Class: ThinkNear::Endpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/think_near/endpoint.rb

Class Method Summary collapse

Class Method Details

.app_id_hash(app_id) ⇒ Object



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

def app_id_hash(app_id) 
  app_id ? {:app_id => app_id} : {} 
end

.authenticatedObject



13
14
15
# File 'lib/think_near/endpoint.rb', line 13

def authenticated
  endpoint_url 'authenticated'
end

.categoriesObject



17
18
19
# File 'lib/think_near/endpoint.rb', line 17

def categories
  endpoint_url 'categories'
end

.claim_offer(offer_id, latitude, longitude, app_id) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/think_near/endpoint.rb', line 43

def claim_offer(offer_id, latitude, longitude, app_id)
  if latitude && longitude
    endpoint_url "offers/#{offer_id}/claim/#{latitude},#{longitude}", app_id_hash(app_id)
  else
    endpoint_url "offers/#{offer_id}/claim", app_id_hash(app_id)
  end 
end

.draws(category) ⇒ Object



21
22
23
# File 'lib/think_near/endpoint.rb', line 21

def draws(category)
  endpoint_url "draws/#{category}"
end

.endpoint_url(path, params = {}, format = 'json', version = API_VERSION) ⇒ Object



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

def endpoint_url(path, params = {}, format = 'json', version = API_VERSION)
  ["http://#{Client.api_host}", version, [path, format].join('.')].join('/') + "?#{params.to_param}"
end

.feed(city) ⇒ Object



55
56
57
# File 'lib/think_near/endpoint.rb', line 55

def feed(city)
  endpoint_url('feeds', {:city => CGI.escape(city)}.merge(app_id_hash(app_id)), 'rss')
end

.healthObject



9
10
11
# File 'lib/think_near/endpoint.rb', line 9

def health
  endpoint_url 'health'
end

.offer(id, app_id) ⇒ Object



39
40
41
# File 'lib/think_near/endpoint.rb', line 39

def offer(id, app_id)
  endpoint_url "offers/#{id}", app_id_hash(app_id)
end

.offers(params, app_id) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/think_near/endpoint.rb', line 25

def offers(params, app_id)
  latitude = params.delete(:latitude)
  longitude = params.delete(:longitude)
  zipcode = params.delete(:zipcode)
  params = params.select { |k, v| !v.blank? }
  params.merge(app_id_hash(app_id))

  if !latitude.blank? && !longitude.blank?
    endpoint_url("offers/#{latitude},#{longitude}", params)
  elsif !zipcode.blank?
    endpoint_url("offers/#{zipcode}", params)
  end 
end

.pingObject



5
6
7
# File 'lib/think_near/endpoint.rb', line 5

def ping
  endpoint_url 'ping'
end

.save_offer(offer_id, email, app_id) ⇒ Object



51
52
53
# File 'lib/think_near/endpoint.rb', line 51

def save_offer(offer_id, email, app_id)
  endpoint_url("offers/#{offer_id}/save", {:email => CGI.escape(email)}.merge(app_id_hash(app_id)))
end