Class: Dailymile::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/dailymile/client.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token = nil) ⇒ Client

Returns a new instance of Client.



12
13
14
# File 'lib/dailymile/client.rb', line 12

def initialize(token = nil)
  @connection = Connection::Token.new(self.class.oauth_client, token)
end

Class Method Details

.entries(*args) ⇒ Object

EXAMPLES:

everyone stream: Dailymile::Client.entries
nearby stream:   Dailymile::Client.entries :nearby, 37.77916, -122.420049, :page => 2
ben's stream:    Dailymile::Client.entries 'ben', :page => 2


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/dailymile/client.rb', line 36

def self.entries(*args)
  params = extract_options_from_args!(args)
  filter = args.shift
  
  entries_path = case filter
  when String, Symbol
    filter = filter.to_s.strip
    
    if STREAM_FILTERS.include?(filter)
      if filter == 'nearby'
        lat, lon = args
        "/entries/nearby/#{lat},#{lon}"
      else
        "/entries/#{filter}"
      end
    else
      "/people/#{filter}/entries"
    end
  else
    '/entries'
  end
  
  data = get entries_path, params
  data["entries"]
end

.get(*args) ⇒ Object



16
# File 'lib/dailymile/client.rb', line 16

def self.get(*args); connection.get(*args) end

.oauth_clientObject



26
27
28
29
30
# File 'lib/dailymile/client.rb', line 26

def self.oauth_client
  raise "Please call set_client_credentials first" if @@oauth_client.nil?
  
  @@oauth_client
end

.set_client_credentials(client_id, client_secret) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/dailymile/client.rb', line 18

def self.set_client_credentials(client_id, client_secret)
  @@oauth_client = OAuth2::Client.new(client_id, client_secret,
    :site => BASE_URI,
    :access_token_path => OAUTH_TOKEN_PATH,
    :authorize_path => OAUTH_AUTHORIZE_PATH
  )
end