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

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



63
64
65
# File 'lib/threetaps_client.rb', line 63

def default_params
  { :auth_token => api_key }
end

#locations(*args) ⇒ Object



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

def locations(*args)
  options = args.extract_options!
  level   = args.first || options[:level] || args.first || 'country'
  options.merge! :level => level
  request LOCATIONS_URL, options
end

#log=(io) ⇒ Object



77
78
79
# File 'lib/threetaps_client.rb', line 77

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

#lookup_location(code) ⇒ Object



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

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)


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

def raw_data?
  !!raw_data
end

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



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

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