Class: RunKeeper::Request
- Inherits:
-
Object
- Object
- RunKeeper::Request
- Defined in:
- lib/run_keeper/request.rb
Constant Summary collapse
- HEADERS =
{ 'fitness_activities' => 'application/vnd.com.runkeeper.FitnessActivityFeed+json', 'profile' => 'application/vnd.com.runkeeper.Profile+json', 'user' => 'application/vnd.com.runkeeper.User+json' }
Instance Method Summary collapse
- #authorize_url(redirect_uri) ⇒ Object
- #fitness_activities(options = {}) ⇒ Object
- #get_token(code, redirect_uri) ⇒ Object
-
#initialize(client_id, client_secret, token) ⇒ Request
constructor
A new instance of Request.
- #profile ⇒ Object
- #request(endpoint, params = {}) ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(client_id, client_secret, token) ⇒ Request
Returns a new instance of Request.
9 10 11 |
# File 'lib/run_keeper/request.rb', line 9 def initialize client_id, client_secret, token @client_id, @client_secret, @token = client_id, client_secret, token end |
Instance Method Details
#authorize_url(redirect_uri) ⇒ Object
13 14 15 |
# File 'lib/run_keeper/request.rb', line 13 def redirect_uri client('https://runkeeper.com').auth_code. :redirect_uri => redirect_uri end |
#fitness_activities(options = {}) ⇒ Object
17 18 19 |
# File 'lib/run_keeper/request.rb', line 17 def fitness_activities = {} ActivityRequest.new(self, ).get_activities end |
#get_token(code, redirect_uri) ⇒ Object
21 22 23 24 25 |
# File 'lib/run_keeper/request.rb', line 21 def get_token code, redirect_uri client('https://runkeeper.com').auth_code.get_token(code, :redirect_uri => redirect_uri).token rescue OAuth2::Error => e raise Error.new(e.response) end |
#profile ⇒ Object
27 28 29 |
# File 'lib/run_keeper/request.rb', line 27 def profile Profile.new request('profile').parsed.merge(:userid => @user.userid) end |
#request(endpoint, params = {}) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/run_keeper/request.rb', line 31 def request endpoint, params = {} response = access_token.get(user.send(endpoint), :headers => {'Accept' => HEADERS[endpoint]}, :parse => :json) do |request| request.params = params end parse_response response end |