Class: Dailymile::Client

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token = nil) ⇒ Client

Returns a new instance of Client.



22
23
24
25
26
# File 'lib/dailymile/client.rb', line 22

def initialize(token = nil)
  @@client ||= OAuth2::Client.new('', '', :site => BASE_URI) # HACK: dummy client
  
  @access_token = Token.new(@@client, token)
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



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

def access_token
  @access_token
end

Class Method Details

.set_client_credentials(client_id, client_secret) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/dailymile/client.rb', line 14

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

Instance Method Details

#entries(*args) ⇒ Object

EXAMPLES:

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


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

def 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