-
Notifications
You must be signed in to change notification settings - Fork 47
Space- Shonda #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Space- Shonda #30
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,65 +8,86 @@ Answer the following comprehension questions **within this file.** Write your an | |
|
|
||
| ### `GET` Request Review | ||
|
|
||
| 1. Describe a GET request that your project makes, and the high-level description of what it does | ||
| 1. Describe a GET request that your project makes, and the high-level description of what it does | ||
| - Answer: A Get request for my project is requesting that my browser perform an action for example. I created a method that requests a url and sub url to the user list or channel list. | ||
| 1. What is the verb of this request? | ||
| - Answer: GET | ||
| 1. What is the path (or the URL, or endpoint) of this request? | ||
| - Answer: "https://slack.com/api/#{sub_url}?token=#{SLACK_TOKEN}&pretty=1" | ||
| 1. What are the query params (the additional data sent with the request, besides the verb and the path)? | ||
| - Answer: | ||
| 1. What is the verb of this request? | ||
| - Answer: | ||
| 1. What is the path (or the URL, or endpoint) of this request? | ||
| - Answer: | ||
| 1. What are the query params (the additional data sent with the request, besides the verb and the path)? | ||
| - Answer: | ||
| 1. What is the syntax used to make this request? (Copy and paste a code snippet here) | ||
| 1. What is the syntax used to make this request? (Copy and paste a code snippet here) | ||
|
|
||
| - Answer: | ||
| ```ruby | ||
| # Copy and paste your answer below this comment | ||
| ```ruby # Copy and paste your answer below this comment | ||
| def self.get(sub_url) # self calls only know about its self to call in another method # must call the (Class name).something # Recipent.get(querty) is called on the respective class that | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a perfect explanation of self/the class method syntax! Nice! |
||
| url = "https://slack.com/api/#{sub_url}?token=#{SLACK_TOKEN}&pretty=1" | ||
| response = HTTParty.get(url) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a perfectly good way to make this HTTP call! You construct the In case the string interpolation is confusing to read, it's good to know that the API key is being passed in as a query parameter. (One way to tell this by reading it is seeing any URL that has a If you wanted to try an alternative syntax, you may use this syntax with HTTParty: HTTParty.get("https://slack.com/api/#{sub_url}", query: {token: ENV['SLACK_TOKEN']})This line is saying "Make a GET request to this url. Also, pass along these query parameters: Again, both syntaxes are correct; just wanted to make sure you knew the other option! |
||
| return response | ||
| end | ||
|
|
||
| # Copy and paste your answer above this comment | ||
| ``` | ||
| 1. What does the program do if the response comes back with a status code of 200? | ||
| - Answer: | ||
| 1. What does the program do if the response does not come back with a status code of 200? | ||
| - Answer: | ||
| # Copy and paste your answer above this comment | ||
|
|
||
| 1. What does the program do if the response comes back with a status code of 200? | ||
| - Answer: The request will be valid and will return the response | ||
| 1. What does the program do if the response does not come back with a status code of 200? | ||
| - Answer: if the response does not comeback with true or 200 there Slack Error will raise an error | ||
|
|
||
| ### `POST` Request Review | ||
|
|
||
| If your project does not make a POST request, read through Wave 3 on the original Slack CLI, and research and answer questions 1, 2, 3, 4, 6, and 7. | ||
|
|
||
| 1. Describe a POST request that your project makes, and the high-level description of what it does | ||
| - Answer: | ||
| 1. What is the verb of this request? | ||
| - Answer: | ||
| 1. What is the path (or the URL, or endpoint) of this request? | ||
| - Answer: | ||
| 1. What are the query params (the additional data sent with the request, besides the verb and the path)? | ||
| - Answer: | ||
| 1. What is the syntax used to make this request? (Copy and paste a code snippet here) | ||
| 1. Describe a POST request that your project makes, and the high-level description of what it does | ||
| - Answer: The post will update the data as it is posting to a channel or a user. | ||
| 1. What is the verb of this request? | ||
| - Answer: POST | ||
| 1. What is the path (or the URL, or endpoint) of this request? | ||
| - Answer: url = "https://slack.com/api/chat.postMessage?token=#{SLACK_TOKEN}&channel=#{@slack_id}&text=#{message}" | ||
| 1. What are the query params (the additional data sent with the request, besides the verb and the path)? | ||
| - Answer: token, user/channel or text | ||
| 1. What is the syntax used to make this request? (Copy and paste a code snippet here) | ||
|
|
||
| - Answer: | ||
| ```ruby | ||
| # Copy and paste your answer below this comment | ||
|
|
||
| # Copy and paste your answer above this comment | ||
| def send_message(message) | ||
| url = "https://slack.com/api/chat.postMessage?token=#{SLACK_TOKEN}&channel=#{@slack_id}&text=#{message}" | ||
| ``` | ||
| 1. What does the program do if the response comes back with a status code of 200? | ||
| - Answer: | ||
| 1. What does the program do if the response does not come back with a status code of 200? | ||
| - Answer: | ||
|
|
||
| response = HTTParty.post(url) | ||
|
|
||
| if response["ok"] != true || response.code != 200 | ||
| raise SlackError(("There was an error posting this message: #{response["error"]}")) | ||
| else puts "Your message has been sent successfully!" end | ||
|
|
||
| return response | ||
| end | ||
|
|
||
| # Copy and paste your answer above this comment | ||
| ``` | ||
|
|
||
| 1. What does the program do if the response comes back with a status code of 200? | ||
| - Answer: if the response is not true or equal to 200 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, this answer doesn't quite make sense considering the question. The program makes a request to send a message... and a response eventually comes back from the server, back to the program. A response always has a status code. In the case that the response has a status code of 200, what does the program do? This question is asking what happens when the response comes back with a status code of 200. Your answer should be talking about the program's logic of what happens after that! What does a status code of 200 mean? |
||
| 1. What does the program do if the response does not come back with a status code of 200? | ||
| - Answer: Raise a built in response era | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to my other comment, I'd love to hear more details about this. What does your program do if the response has a status code that isn't 200? What does "Raise a built in response era" mean in this case? |
||
|
|
||
| ## Request & Response Cycle | ||
|
|
||
| Imagine this situation: A human user, Grace, opens up Terminal and runs in the command line `$ ruby lib/slack.rb`. When the program runs, she types "list channels." | ||
|
|
||
| There are two actors: | ||
| - the human user, Grace, and their computer that runs `slack.rb` | ||
| - Slack API | ||
|
|
||
| - the human user, Grace, and their computer that runs `slack.rb` | ||
| - Slack API | ||
|
|
||
| Based on the project requirements, when Grace enters "list channels," | ||
|
|
||
| 1. What is the request being made in the program? | ||
| - Answer: | ||
| - Answer: we are request a response of a list of channels and assocaited Data | ||
| 1. Who is the client? | ||
| - Answer: | ||
| - Answer: Grace is using the her web browser which is the client | ||
| 1. Who is the server? | ||
| - Answer: | ||
| - Answer: Slack's API | ||
|
|
||
| ## Part 2: Optional Refactoring | ||
|
|
||
|
|
@@ -80,4 +101,4 @@ If your reflection inspired you to make minimal changes to your Slack CLI implem | |
|
|
||
| ### Describe your optional Slack CLI changes here | ||
|
|
||
| Answer: | ||
| Answer: | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have an answer here? In this case, it's the token, which holds the value of the Slack API Key/Slack Token!