Class: NikePlus::Client
- Inherits:
-
Object
- Object
- NikePlus::Client
- Defined in:
- lib/nike_plus/client.rb
Instance Attribute Summary collapse
-
#authorization_response ⇒ Object
readonly
Returns the value of attribute authorization_response.
-
#screenname ⇒ Object
readonly
Returns the value of attribute screenname.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#activities ⇒ Object
Return an array of NikePlus::ActivitySummary objects.
-
#activity(id) ⇒ Object
Return full details on a specific activity.
-
#activity_ids ⇒ Object
Return an array of activity ids.
-
#initialize(options = {}) ⇒ Client
constructor
Initializes a new NikePlus::Client object.
Constructor Details
#initialize(options = {}) ⇒ Client
Initializes a new NikePlus::Client object.
Configuration options are:
-
email
- Nike+ account email address. -
password
- Nike+ account password. -
debug
- Debug flag, set to true for debugging output.
Example:
nike = NikePlus::Client.new( :email => '[email protected]', :password => 'mypassword' )
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/nike_plus/client.rb', line 19 def initialize( ={} ) @email = [:email] @password = [:password] @debug = [:debug] @agent = Mechanize.new url = 'https://secure-nikeplus.nike.com/nsl/services/user/login?app=b31990e7-8583-4251-808f-9dc67b40f5d2&format=json&contentType=plaintext' @authorization_response = post(url, { :email => @email, :password => @password }) if @authorization_response.serviceResponse.header.success == 'true' @user = @authorization_response.serviceResponse.body.User @screenname = @user.screenName else raise @authorization_response.serviceResponse.header.errorCodes.first. end end |
Instance Attribute Details
#authorization_response ⇒ Object (readonly)
Returns the value of attribute authorization_response.
8 9 10 |
# File 'lib/nike_plus/client.rb', line 8 def @authorization_response end |
#screenname ⇒ Object (readonly)
Returns the value of attribute screenname.
8 9 10 |
# File 'lib/nike_plus/client.rb', line 8 def screenname @screenname end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
8 9 10 |
# File 'lib/nike_plus/client.rb', line 8 def user @user end |
Instance Method Details
#activities ⇒ Object
Return an array of NikePlus::ActivitySummary objects. To retrieve full details on the activity use the #activity method.
Example:
activities = nike.activities # => [NikePlus::ActivitySummary, NikePlus::ActivitySummary]
activity = nike.activity( activities[0].activityId ) # => NikePlus::Activity
42 43 44 45 46 |
# File 'lib/nike_plus/client.rb', line 42 def activities url = "http://nikeplus.nike.com/plus/activity/running/#{ @screenname }/lifetime/activities?indexStart=0&indexEnd=9999" data = get(url) activity_list = data.activities.any? ? data.activities.collect { |a| NikePlus::ActivitySummary.new( a.activity ) } : [] end |
#activity(id) ⇒ Object
Return full details on a specific activity.
Params:
-
id
- Nike+ Activity ID
Example:
nike.activity( 123456 ) # => NikePlus::Activity
55 56 57 58 59 |
# File 'lib/nike_plus/client.rb', line 55 def activity( id ) url = "http://nikeplus.nike.com/plus/running/ajax/#{ id }" data = get(url) activity = NikePlus::Activity.new( data.activity ) if data.activity end |
#activity_ids ⇒ Object
Return an array of activity ids.
Example:
nike.activity_ids # => [100, 101, 102, 103]
65 66 67 |
# File 'lib/nike_plus/client.rb', line 65 def activity_ids self.activities.collect(&:activityId) end |