Class: ThinkNear::Offer

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find(id_or_params, app_id = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/think_near/offer.rb', line 3

def self.find(id_or_params, app_id = nil)
  if id_or_params.is_a? String
    begin
      if params = Client.get_offer(id_or_params, app_id)['offer']
        new(params)
      else
        raise OfferNotFound, "Couldn't find Offer with ID=#{id_or_params}"
      end
    rescue NotFound
      raise OfferNotFound, "Couldn't find Offer with ID=#{id_or_params}"
    end
  elsif id_or_params.is_a? Hash
    Client.get_offers(id_or_params, app_id).map do |item|
      new item['offer']
    end
  end
end

Instance Method Details

#attributesObject



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

def attributes
  @table
end

#claim!(latitude = nil, longitude = nil, app_id = nil) ⇒ Object



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

def claim!(latitude = nil, longitude = nil, app_id = nil)
  self.class.new Client.claim_offer(id, latitude, longitude, app_id)['offer']
end

#save(email, app_id = nil) ⇒ Object



29
30
31
32
# File 'lib/think_near/offer.rb', line 29

def save(email, app_id = nil)
  Client.save_offer(id, email, app_id)
  true
end