Created
January 19, 2013 18:49
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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