Module: ThreetapsClient

Extended by:
ThreetapsClient
Included in:
ThreetapsClient
Defined in:
lib/threetaps_client.rb,
lib/threetaps_client/version.rb

Constant Summary collapse

DOMAIN =
'3taps.com'
SEARCH_END_POINT =
"http://search.#{DOMAIN}"
POLLING_END_POINT =
"http://polling.#{DOMAIN}"
REFERENCE_END_POINT =
"http://reference.#{DOMAIN}"
ANCHOR_URL =
"#{POLLING_END_POINT}/anchor"
POLL_URL =
"#{POLLING_END_POINT}/poll"
DATA_SOURCES_URL =
"#{REFERENCE_END_POINT}/sources"
CATEGORY_GROUPS_URL =
"#{REFERENCE_END_POINT}/category_groups"
CATEGORIES_URL =
"#{REFERENCE_END_POINT}/categories"
LOCATIONS_URL =
"#{REFERENCE_END_POINT}/locations"
LOCATION_LOOKUP_URL =
"#{REFERENCE_END_POINT}/locations/lookup"
VERSION =
"0.0.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



23
24
25
# File 'lib/threetaps_client.rb', line 23

def api_key
  @api_key
end

Instance Method Details

#anchor(timestamp = Time.now.to_i) ⇒ Object



29
30
31
# File 'lib/threetaps_client.rb', line 29

def anchor(timestamp=Time.now.to_i)
  request ANCHOR_URL, :timestamp => timestamp
end

#categoriesObject



48
49
50
# File 'lib/threetaps_client.rb', line 48

def categories
  request CATEGORIES_URL
end

#category_groupsObject



44
45
46
# File 'lib/threetaps_client.rb', line 44

def category_groups
  request CATEGORY_GROUPS_URL
end

#data_sourcesObject



40
41
42
# File 'lib/threetaps_client.rb', line 40

def data_sources
  request DATA_SOURCES_URL
end

#default_paramsObject



69
70
71
# File 'lib/threetaps_client.rb', line 69

def default_params
  { :auth_token => api_key, :retvals => retvals }
end

#locations(level = 'country') ⇒ Object



52
53
54
# File 'lib/threetaps_client.rb', line 52

def locations(level='country')
  request LOCATIONS_URL, :level => level
end

#log=(io) ⇒ Object



79
80
81
# File 'lib/threetaps_client.rb', line 79

def log=(io)
  RestClient.log = io
end

#lookup_location(code) ⇒ Object



56
57
58
# File 'lib/threetaps_client.rb', line 56

def lookup_location(code)
  request LOCATION_LOOKUP_URL, :code => code
end

#poll(*args) ⇒ Object



33
34
35
36
37
38
# File 'lib/threetaps_client.rb', line 33

def poll(*args)
  criteria = args.extract_options!
  anchor   = args.first || criteria[:anchor]
  anchor   = self.anchor['anchor'] if anchor.nil?
  request POLL_URL, criteria.merge(:anchor => anchor)
end

#request(url, params = {}) ⇒ Object



73
74
75
76
77
# File 'lib/threetaps_client.rb', line 73

def request(url, params={})
  params   = default_params.merge params.flatten
  response = RestClient.get url, :params => params, :accept => :json
  response.decode_json
end

#retvalsObject



60
61
62
63
64
65
66
67
# File 'lib/threetaps_client.rb', line 60

def retvals
  %w[
    id account_id source category category_group
    location external_id external_url heading body
    timestamp expires language price currency
    images annotations status immortal deleted
  ].join(',')
end

#search(criteria = {}) ⇒ Object



25
26
27
# File 'lib/threetaps_client.rb', line 25

def search(criteria={})
  request SEARCH_END_POINT, criteria
end