Skip to content

Commit

Permalink
Add Fitness Activities
Browse files Browse the repository at this point in the history
  • Loading branch information
joelind committed Sep 11, 2011
1 parent ba037cb commit 31e9ba9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ end

gem 'oauth2', '~> 0.5.0'
gem 'faraday-stack'
gem 'json'
32 changes: 22 additions & 10 deletions lib/baby_tooth.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'oauth2'
require 'faraday_stack'
require 'json'

module BabyTooth
class << self
Expand Down Expand Up @@ -28,16 +29,18 @@ def oauth_client

class Client
attr_accessor :access_token, :path
attr_reader :body

def [](key)
body[key]
end

def body
@body ||= retrieve_body
end

def initialize(access_token, path)
self.access_token = access_token
self.path = path
retrieve!
end

def resource_class_name
Expand All @@ -54,13 +57,13 @@ def self.exposes_keys(*keys)

protected

def retrieve!
def retrieve_body
response = connection.get(path) do |request|
request.headers['Authorization'] = "Bearer #{access_token}"
request.headers['Accept'] = "application/vnd.com.runkeeper.#{resource_class_name}+json"
end

@body = JSON.parse(response.body)
JSON.parse(response.body)
end

def connection
Expand All @@ -69,10 +72,16 @@ def connection
end

class User < Client
exposes_keys 'fitness_activities'

def initialize(access_token)
super access_token, '/user'
end

def fitness_activity_feed
@fitness_activity_feed ||= FitnessActivityFeed.new(access_token, fitness_activities)
end

def street_team
@street_team ||= TeamFeed.new(access_token).members
end
Expand All @@ -94,16 +103,19 @@ class Profile < Client
"profile"
end

class TeamFeed < Client
def initialize(access_token)
super access_token, '/team'
end
class FitnessActivityFeed < Client
exposes_keys "items"

def members
body['items']
def fitness_activities
items.map do |item|
FitnessActivity.new access_token, item['uri']
end
end
end

class FitnessActivity < Client
end

private

class Configuration
Expand Down

0 comments on commit 31e9ba9

Please sign in to comment.