Class: ThinkNear::Endpoint
- Inherits:
-
Object
- Object
- ThinkNear::Endpoint
- Defined in:
- lib/think_near/endpoint.rb
Class Method Summary collapse
- .app_id_hash(app_id) ⇒ Object
- .authenticated ⇒ Object
- .categories ⇒ Object
- .claim_offer(offer_id, latitude, longitude, app_id) ⇒ Object
- .draws(category) ⇒ Object
- .endpoint_url(path, params = {}, format = 'json', version = API_VERSION) ⇒ Object
- .feed(city) ⇒ Object
- .health ⇒ Object
- .offer(id, app_id) ⇒ Object
- .offers(params, app_id) ⇒ Object
- .ping ⇒ Object
- .save_offer(offer_id, email, app_id) ⇒ Object
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 |
.authenticated ⇒ Object
13 14 15 |
# File 'lib/think_near/endpoint.rb', line 13 def authenticated endpoint_url 'authenticated' end |
.categories ⇒ Object
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 => city}.merge(app_id_hash(app_id)), 'rss') end |
.health ⇒ Object
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 |
.ping ⇒ Object
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 => email}.merge(app_id_hash(app_id))) end |