From 261b7d76edc75ba361bbf3f290a7ca413c17afa5 Mon Sep 17 00:00:00 2001 From: Vera Date: Mon, 23 Mar 2020 18:11:48 -0700 Subject: [PATCH 1/4] Describing GET request on high-level. --- individual-reflection.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/individual-reflection.md b/individual-reflection.md index 603cdeb..90660ea 100644 --- a/individual-reflection.md +++ b/individual-reflection.md @@ -9,7 +9,7 @@ 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 - - Answer: + - Answer: File: recipient.rb, line: 18. The GET request info from the SLACK API, Not modify it in any way. It returns an slackError if the info is not found. If the request is successful (200 and parsed_response: "ok") it returns the response in a variable called `resp` as a JSON. 1. What is the verb of this request? - Answer: 1. What is the path (or the URL, or endpoint) of this request? From 968e0d474cc59ca43c82d0bb377365bac3e0eca3 Mon Sep 17 00:00:00 2001 From: Vera Date: Mon, 23 Mar 2020 18:26:23 -0700 Subject: [PATCH 2/4] Answer to GET requests --- individual-reflection.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/individual-reflection.md b/individual-reflection.md index 90660ea..07c9145 100644 --- a/individual-reflection.md +++ b/individual-reflection.md @@ -11,22 +11,25 @@ Answer the following comprehension questions **within this file.** Write your an 1. Describe a GET request that your project makes, and the high-level description of what it does - Answer: File: recipient.rb, line: 18. The GET request info from the SLACK API, Not modify it in any way. It returns an slackError if the info is not found. If the request is successful (200 and parsed_response: "ok") it returns the response in a variable called `resp` as a JSON. 1. What is the verb of this request? - - Answer: + - Answer: GET 1. What is the path (or the URL, or endpoint) of this request? - - Answer: + - Answer: URL: `"https://slack.com/api/users.list` , `"https://slack.com/api/channels.list` 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) - Answer: ```ruby # Copy and paste your answer below this comment - + base_url = "https://slack.com/api/" + post_url = "#{base_url}channels.list" + params = { token: ENV["SLACK_API_TOKEN"] } + response: HTTParty.get(pots_url, query: params) # 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: + - Answer: It saves the response within a variable called `resp`. 1. What does the program do if the response does not come back with a status code of 200? - - Answer: + - Answer: It has a class called `SlackAPIError` to handle the exception with the error and comment: "We encountered a problem". ### `POST` Request Review From 80062ba955cdb4157ec5a58bfabdf1067a9fbf99 Mon Sep 17 00:00:00 2001 From: Vera Date: Mon, 23 Mar 2020 22:01:16 -0700 Subject: [PATCH 3/4] Answering custions of POST request and optional refactoring --- individual-reflection.md | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/individual-reflection.md b/individual-reflection.md index 07c9145..80654d9 100644 --- a/individual-reflection.md +++ b/individual-reflection.md @@ -36,24 +36,35 @@ Answer the following comprehension questions **within this file.** Write your an 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: + - Answer:File: recipient.rb, line: 30. The POST request post to the SLACK API, It sends a message to a specific channel. it returns the response in a variable called `resp` as a JSON when the response is code: 200 and parsed_response: "ok". 1. What is the verb of this request? - - Answer: + - Answer: POST 1. What is the path (or the URL, or endpoint) of this request? - - Answer: + - Answer: URL: `"https://slack.com/api/chat.postMessage"` 1. What are the query params (the additional data sent with the request, besides the verb and the path)? - - Answer: + - Answer: Headers(Content-Type, charset), and body(token, channel and 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 - + base_url = "https://slack.com/api/" + post_url = "#{base_url}/chat.postMessage" + + resp = HTTParty.post(post_url,{ + headers: { 'Content-Type'=> 'application/x-www-form-urlencoded', + 'charset' => 'utf-8' }, + body:{ + token: ENV["SLACK_API_TOKEN"], + channel: channel, + text: message + } + }) # 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: + - Answer: It returns the response. 1. What does the program do if the response does not come back with a status code of 200? - - Answer: + - Answer: It does not handle the error/exception. ## Request & Response Cycle @@ -65,11 +76,11 @@ There are two actors: Based on the project requirements, when Grace enters "list channels," 1. What is the request being made in the program? - - Answer: + - Answer: Use GET, endpoint `"https://slack.com/api/channels.list"` 1. Who is the client? - - Answer: + - Answer: Grace computer running `slack.rb` 1. Who is the server? - - Answer: + - Answer: The endpoint `channels.list` it defines request–response message system, expressed in JSON. ## Part 2: Optional Refactoring @@ -83,4 +94,4 @@ If your reflection inspired you to make minimal changes to your Slack CLI implem ### Describe your optional Slack CLI changes here -Answer: +Answer: For the POST request, I did not take into account when the message could not be sent. I wrote an If statement to handle the error, File: `recipiente.rb` line: 39 to 42. Including `SlackAPIError, "We encountered a problem:` Also I wrote the test for these lines. File: `recipient_test.rb` lines: 52 to 59. \ No newline at end of file From adbdd1db4676ce4a0372c93047b965adc9eb3ad4 Mon Sep 17 00:00:00 2001 From: codesrobertson <47929832+codesrobertson@users.noreply.github.com> Date: Tue, 24 Mar 2020 16:15:40 -0700 Subject: [PATCH 4/4] Submitting feedback for Vera's project. Most everything looks excellent, cleanly written, and I expect that it's fully functional. That said, tI was unable to verify the functional requirements due to the following error when I tried to run Slack.rb from the CLI: Traceback (most recent call last): 2: from slack.rb:3:in `
' 1: from /Users/Ruya/.rvm/rubies/ruby-2.6.5/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' /Users/Ruya/.rvm/rubies/ruby-2.6.5/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- tty-prompt (LoadError). --- feedback.md | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/feedback.md b/feedback.md index f90b999..97d940b 100644 --- a/feedback.md +++ b/feedback.md @@ -17,7 +17,7 @@ 1. Practices best practices working with APIs. (The .env is not checked into git, and no API token was directly used in the Ruby code without ENV.) - yes/no + yes @@ -26,7 +26,7 @@ 2. Practices error handling with APIs. (For all pieces of code that make an API call, it handles API requests that come back with errors/error status codes appropriately.) - yes/no + yes @@ -35,7 +35,7 @@ 3. Implements inheritance and inheritance idioms. There is a Recipient class. User and Channel inherit from Recipient. In Recipient, there are appropriate methods defined that are used in both User and Channel. Some may be implemented. Some may be template methods. - yes/no + yes @@ -51,7 +51,7 @@ - yes/no + yes @@ -60,7 +60,7 @@ 5. Practices instance methods vs. class methods appropriately. (The methods to list all Channels or Users is a class method within those respective classes.) - yes/no + yes @@ -70,7 +70,7 @@ 6. Practices best practices for testing. (The project has and uses VCR mocking when running tests, and can run offline.) - yes/no + yes @@ -80,7 +80,7 @@ 7. Practices writing tests. (The User, Channel, and Workspace classes have unit tests.) - yes/no + yes @@ -90,7 +90,7 @@ 8. There are also tests for sending messages (the location of these tests may differ, but is likely in Recipient) - yes/no + yes @@ -100,7 +100,7 @@ 9. Practices git with at least 15 small commits and meaningful commit messages - yes/no + yes @@ -118,7 +118,10 @@ 1. As a user of the CLI program, I can list users and channels with the commands list users and list channels - yes/no + It looks like functionality for this is available (and I assume working), but when I try to run the program from terminal, I get a "cannot load such file" error: Traceback (most recent call last): + 2: from slack.rb:3:in `
' + 1: from /Users/Ruya/.rvm/rubies/ruby-2.6.5/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' +/Users/Ruya/.rvm/rubies/ruby-2.6.5/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- tty-prompt (LoadError) @@ -126,7 +129,7 @@ 2. As a user of the CLI program, I can select users and channels with the commands select user and select channel - yes/no + ^ @@ -134,7 +137,7 @@ 3. As a user of the CLI program, I can show the details of a selected user or channel with the command details - yes/no + ^ @@ -142,7 +145,7 @@ 4. As a user of the CLI program, when I input something inappropriately, the program runs without crashing. Example commands to try are do_something, or select user followed by Mr. Fakename - yes/no + ^