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



90
91
92
# File 'lib/think_near/endpoint.rb', line 90

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

.collect(location, unit_details, past_prices) ⇒ Object



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

def collect(location, unit_details, past_prices)
  get_ad_units('ad_units/collect', location, unit_details, past_prices)
end

.creatives(location) ⇒ Object



78
79
80
# File 'lib/think_near/endpoint.rb', line 78

def creatives(location) 
  endpoint_url('ad_units/creatives', location)
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



86
87
88
# File 'lib/think_near/endpoint.rb', line 86

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, app_id) ⇒ Object



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

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

.fetch(location, unit_details, past_prices) ⇒ Object



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

def fetch(location, unit_details, past_prices) 
  get_ad_units('ad_units/fetch', location, unit_details, past_prices)
end

.get_ad_units(method_endpoint, location, unit_details, past_prices) ⇒ Object



67
68
69
70
71
72
73
74
75
76
# File 'lib/think_near/endpoint.rb', line 67

def get_ad_units(method_endpoint, location, unit_details, past_prices) 
  params = location.with_indifferent_access 
  unit_details.each do |k, v| 
    k = "ud_#{k.to_s}".to_sym
  end 
  params.merge!(unit_details)
  p_index = 0
  params.merge!(Hash[past_prices.map {|p| ["p_#{p_index.to_s}", p] }])
  endpoint_url(method_endpoint, params)
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)
  zip_code = params.delete(:zip_code)
  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 !zip_code.blank?
    endpoint_url("offers/#{zip_code}", params)
  end 
end

.pingObject



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

def ping
  endpoint_url 'ping'
end

.report(params) ⇒ Object



82
83
84
# File 'lib/think_near/endpoint.rb', line 82

def report(params)
  endpoint_url('ad_units/report', params)
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