diff --git a/feedback.md b/feedback.md index f90b999..e06e6b7 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,7 @@ 1. As a user of the CLI program, I can list users and channels with the commands list users and list channels - yes/no + Was not able to run program with ENV token. diff --git a/individual-reflection.md b/individual-reflection.md index 603cdeb..f12e151 100644 --- a/individual-reflection.md +++ b/individual-reflection.md @@ -9,48 +9,58 @@ 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: The list_all method in my user class makes a GET request to get information from slack about the users that are in the work space. The GET request sends a request to the slack server, and the slack server sends a reponse based on the request. If the request is successful, I get a response that is a JSON that contains all the user inforamtion for the workspace. If the request was unsuccessful, I get a response that is a JSON that tells me the error(s). 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: The path is url = "https://slack.com/api/users.list". 1. What are the query params (the additional data sent with the request, besides the verb and the path)? - - Answer: + - Answer: The only param that I pass to HTTParty is the token, which i have hidden in an `.env` file that I place in a `.gitignore` file. 1. What is the syntax used to make this request? (Copy and paste a code snippet here) - - Answer: + - Answer: The actual execution of the GET request using HTTParty happens in my recipient class. I call the method in my user class and pass in the url I need. ```ruby - # Copy and paste your answer below this comment - - # Copy and paste your answer above this comment + url = "https://slack.com/api/users.list" + slack_token = ENV["SLACK_TOKEN"] + params = {token: slack_token} + response = HTTParty.get(url, query: params) ``` 1. What does the program do if the response comes back with a status code of 200? - - Answer: + - Answer: If it comes back with a status code of 200, the list all method goes through the response and collects the users' usernames, real names, Slack IDs, status emojis, and status text and uses that information to initialize a User object, and stores each User object it initalizes into an array. 1. What does the program do if the response does not come back with a status code of 200? - - Answer: + - Answer: If the program does not respond with a status code of 200 (ok: false) it raises an exception. ### `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: + - Answer: My workspace class has a send message method that utilizes a POST request. My program makes a request to the slack api to post a message to a channel. The server receives my request, and if the request is valid, it will allow me to post that message and send back a response that is a JSON tha tlls me that the message was posted and where it was posted along with some other information. If the request is not valid, it will send me a response that is also a JSON that tells me what the error(s) are. 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: You also need a header that specifies that content type and the charset, and a body that specifies the token, channel, and the text that is being posted. 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 + slack_token = ENV["SLACK_TOKEN"] + header = { + 'Content-Type' => 'application/x-www-form-urlencoded', + 'charset' => 'utf-8' + } + body = { + token: slack_token, + channel: send_to, + text: message + } + response = HTTParty.post(url, body: body, headers: header) - # 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: If the response comes back with a status code of 200, the program posts the message to the specified channel in slack and returns a message to the CLI that the message was successfully sent. 1. What does the program do if the response does not come back with a status code of 200? - - Answer: + - Answer: If the response does not come back with a status code 200, it raises and exception. ## Request & Response Cycle @@ -62,11 +72,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: When she runs list channels, the program runs a Get request to slack to get all the channels in that workspace, and then returns that information and slack.rb table prints the reponse. 1. Who is the client? - - Answer: + - Answer: The client is my program. 1. Who is the server? - - Answer: + - Answer: The server is slack api. ## Part 2: Optional Refactoring @@ -80,4 +90,4 @@ If your reflection inspired you to make minimal changes to your Slack CLI implem ### Describe your optional Slack CLI changes here -Answer: +Answer: N/A