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.4"

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

#raw_dataObject

Returns the value of attribute raw_data.



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

def raw_data
  @raw_data
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



60
61
62
# File 'lib/threetaps_client.rb', line 60

def default_params
  { :auth_token => api_key }
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



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

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

#raw_data?Boolean

Returns:

  • (Boolean)


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

def raw_data?
  !!raw_data
end

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



64
65
66
67
68
# File 'lib/threetaps_client.rb', line 64

def request(url, params={})
  params   = default_params.merge params.flatten
  response = RestClient.get url, :params => params, :accept => :json, :accept_charset => 'utf-8'
  JSON.parse(response)
end

#search(criteria = {}) ⇒ Object



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

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