This forum is now read-only. Please use our new forums! Go to forums
Exercise 5 - Creating Tokens For An Application
Hi there,
I seem to be a bit stuck on exercise 5, my current code is:
require 'httparty'
require 'json'
class GitHub
API_CLIENT_ID = '34a57b3c1f20e85a56ab'
API_CLIENT_SECRET = '89060fce512d1042d168c3e71504ae35208cef1b'
include HTTParty
basic_auth "api-padawan", "GitHubPassw0rd"
def create_token
endpoint = "https://api.github.com/authorizations"
postbody = {
:clientid => API_CLIENT_ID,
:clientsecret => API_CLIENT_SECRET
}
self.class.post endpoint, :body => post_body.to_json
end
end
client = GitHub.new
response = client.create_token
puts response.parsed_response
Please could someone explain what I have done wrong?
Thanks.
Answer 51293b0d8712b5952300565d
I’ve got it!
require 'httparty'
require 'json'
class GitHub
API_CLIENT_ID = '34a57b3c1f20e85a56ab'
API_CLIENT_SECRET = '89060fce512d1042d168c3e71504ae35208cef1b'
include HTTParty
basic_auth "api-padawan", "GitHubPassw0rd"
def create_token
endpoint = "https://api.github.com/authorizations"
post_body = {:client_id => API_CLIENT_ID, :client_secret => API_CLIENT_SECRET};
self.class.post endpoint, :body => post_body.to_json
end
end
client = GitHub.new
response = client.create_token
puts response.parsed_response
The code had to go along one line… Plus, I added some underscores. Hope this helps anyone else that gets stuck. :-)
Answer 51293858cf8f1cb47c00532a
I don’t think you’ve done wrong much, but the exercise doesn’t give credit where it’s due. :)
5 comments
I’ve got it! - Just added the code as an answer.
Thanks for your help!
No worries :-)
thanks,i was pulling my hair out. It was my missing underscores :(
XD
Answer 51295bc7b287b420b30006f4
your original code was missing underscores in the terms “client_id” and “client_secret”
I think that’s all that was causing the problem. Cheers.
Answer 53f028327c82ca7cea00094f
The correct answer is
require ‘httparty’ require ‘json’
class GitHub API_CLIENT_ID = ‘34a57b3c1f20e85a56ab’ API_CLIENT_SECRET = ‘89060fce512d1042d168c3e71504ae35208cef1b’
include HTTParty.get basic_auth “api-padawan”, “GitHubPassw0rd”
def create_token endpoint = “https://api.github.com/authorizations“ post_body = {:client_id => API_CLIENT_ID, :client_secret => API_CLIENT_SECRET}; self.class.post endpoint, :body => post_body.to_json end end
client = GitHub.new response = client.create_token
puts response.parsed_response
This is the only way it will work. The directions and the api for the exercise are broken.
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
4 comments
How did you get around this error?
(ruby):4: warning: already initialized constant API_CLIENT_ID (ruby):5: warning: already initialized constant API_CLIENT_SECRET
Have you tried using a different browser?
Oddly, You apparently can’t use Ruby 1.9 hash syntax.
{complete}