ga-wdi-boston / capstone-project

Other
3 stars 29 forks source link

Need help connecting to 3rd Party API #846

Closed Fcarrion001 closed 6 years ago

Fcarrion001 commented 6 years ago

Headers required from api https://www.dropbox.com/s/umx6stpslkxy71y/Screenshot%202017-08-30%2013.15.42.png?dl=0 syntax for gem im using to make the request https://www.dropbox.com/s/mz4h1l3ho20mo82/Screenshot%202017-08-30%2013.17.00.png?dl=0

help please!

Fcarrion001 commented 6 years ago

Issue Resolved

I defined a custom route in the routes file

get '/game-api' => 'games#gameapi'

I defined the method in the games controller

def gameapi
    # user_key given by 3rd party api
    user_key = ENV['USER_KEY']
    p user_key
    p "route is being hit"
    # headers and get request required by the api in the format that the gem requires
    response = HTTP.headers({ :accept => "application/json", 'user-key' => user_key })
                .get("https://api-2445582011268.apicast.io/games/").to_s
      render json: response
  end