This forum is now read-only. Please use our new forums at discuss.codecademy.com.

OAuth2 Forum

View Course » View Exercise

1732 points
E76ea7f99af82cdab6af744ac2197f4b?s=140&d=retro
Submitted by
Scott Hollinshead
over 4 years ago

Why will this exercise not pass?

I have changed the last line to response.inspect but it is failing, below is the code I have.

require 'httparty'
require 'json'

class GitHub
  include HTTParty
  basic_auth "api-padawan", "GitHubPassw0rd"

  def create_token
    endpoint = "https://api.github.com/authorizations"
    self.class.post endpoint, :body => {}.to_json
  end
end

client = GitHub.new
response = client.create_token

puts response.inspect

2 votes

permalink

add .get to "require 'httparty' on line 1

It should look like this..

require 'httparty.get'
require 'json'

class GitHub
include HTTParty
basic_auth "api-padawan", "GitHubPassw0rd"

def createtoken
endpoint = "https://api.github.com/authorizations"
self.class.post endpoint, :body => {}.to
json
end
end

client = GitHub.new
response = client.create_token

puts response.inspect

467 points
52626d59548c35f49d008373_718039614
Submitted by
Frederik De Roover
over 4 years ago


0 votes

permalink

Hi,

Due to an error {"message":"Missing or invalid User Agent string. See http://developer.github.com/v3/#user-agent-required"}, you need to add a User-Agent into a post request header of create token method. Updated method should look like this:

def create_token
endpoint = "https://api.github.com/authorizations"
self.class.post endpoint, :headers => {
"User-Agent" => "codecademy"
}, :body => {}.to_json
end

805 points
Picture
Submitted by
Emir Tabakovic
over 4 years ago


0 votes

permalink

This passes but still throws an error:

require 'httparty'
require 'json'

class GitHub
include HTTParty
headers "User-Agent" => "codecademy"
basic_auth "api-padawan", "GitHubPassw0rd"

def createtoken
endpoint = "https://api.github.com/authorizations"
self.class.post endpoint, :headers => {
"User-Agent" => "codecademy"
}, :body => {}.to
json
end

client = GitHub.new
response = client.create_token

print response.parsed_response

ERROR: (ruby):18: syntax error, unexpected $end, expecting keyword_end

1049 points
96757fad09ce6a5c510a3ed90655d205?s=140&d=retro
Submitted by
larrymclean
about 3 years ago