Class: Nike::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/nike/client.rb

Constant Summary collapse

LOGIN_URL =

debug_output $stdout

'https://secure-nikeplus.nike.com/nsl/services/user/login'
BASE_URL =
'http://nikeplus.nike.com/plus'
APP_KEY =
'b31990e7-8583-4251-808f-9dc67b40f5d2'
FORMAT =
:json
RUN_ACTIVITIES_URL =

service urls

'/activity/running/[user_id]/lifetime/activities'
HR_ACTIVITIES_URL =
'/activity/running/[user_id]/heartrate/lifetime/activities'
ACTIVITY_URL =
'/running/ajax'
ACTIVITIES_URLS =
{
  run:   RUN_ACTIVITIES_URL,
  hr:    HR_ACTIVITIES_URL
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email, password, opts = {}) ⇒ Client

Returns a new instance of Client.



34
35
36
37
# File 'lib/nike/client.rb', line 34

def initialize(email, password, opts = {})
  @email, @password, @user_id = email, password, nil
  @caching, @cache = opts[:caching] || true, {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



59
60
61
62
63
64
# File 'lib/nike/client.rb', line 59

def method_missing(method_name, *args, &block)
  if /(.*)!$/ === method_name && self.respond_to?(method_name.to_s.chop)
    no_cache { self.send($1, *args, &block) }
  else super
  end
end

Instance Attribute Details

#cachingObject

Returns the value of attribute caching.



32
33
34
# File 'lib/nike/client.rb', line 32

def caching
  @caching
end

Instance Method Details

#activities(opts = {}) ⇒ Object



43
44
45
# File 'lib/nike/client.rb', line 43

def activities(opts = {})
  fetch_user_data(opts).activities.map { |a| a.activity }
end

#activity(id) ⇒ Object



39
40
41
# File 'lib/nike/client.rb', line 39

def activity(id)
  fetch_activity_data(id.to_s).activity
end

#detailed_activities(opts = {}) ⇒ Object



47
48
49
# File 'lib/nike/client.rb', line 47

def detailed_activities(opts = {})
  activities(opts).map { |a| activity(a.activity_id) }
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/nike/client.rb', line 66

def respond_to_missing?(method_name, include_private = false)
  method_name.to_s.end_with?('!') && self.respond_to?(method_name.to_s.chop)
end