Skip to content

Instantly share code, notes, and snippets.

@kevinthompson
Created January 19, 2013 18:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kevinthompson/4574273 to your computer and use it in GitHub Desktop.
Save kevinthompson/4574273 to your computer and use it in GitHub Desktop.
A quick example of how you might work with the Nike+ API. You'll need to get your own access key at https://developer.nike.com/console to test this code.
require 'httparty'
APP_ID = 'nike'
BASE_URL = 'https://api.nike.com'
class Person
def initialize(access_token)
self.access_token = access_token
end
def data
@data ||= begin
api_request('/me/sport').parsed_response
end
end
private
def access_token
@access_token
end
def access_token=(value)
@access_token = value
end
def api_request(endpoint)
options = { headers: { 'Accept' => 'application/json', 'appid' => APP_ID } }
HTTParty.get("#{BASE_URL}#{endpoint}?access_token=#{access_token}", options)
end
end
p = Person.new('<YOUR ACCESS TOKEN>')
p.data # => {"experienceTypes"=>["FUELBAND"], "summaries"=>[{"experienceType"=>"ALL", "records"=>{"lifetimeFuel"=>142358}} ... ]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment