Class: Access::Favorite

Inherits:
Object
  • Object
show all
Defined in:
lib/access/favorite.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ Favorite

Returns a new instance of Favorite.



8
9
10
11
12
13
14
15
16
17
# File 'lib/access/favorite.rb', line 8

def initialize(values)
  self.class.class_eval {attr_reader *values.keys }
  values.each do |attribute_name, attribute_value|
    self.instance_variable_set("@#{attribute_name}", attribute_value)
  end
  @offer = Access::Offer.new(@offer) if @offer
  @location = Access::Location.new(@location) if @location
  @store = Access::Store.new(@store) if @store

end

Class Method Details

.create(offer_key, options = {}) ⇒ Object



55
56
57
# File 'lib/access/favorite.rb', line 55

def self.create(offer_key, options = {})
  Access::Api.new.favorites_create offer_key, options
end

.create_location(location_key, options = {}) ⇒ Object



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

def self.create_location(location_key, options = {})
  Access::Api.new.favorites_create location_key, options.merge(favorite_type: 'locations')
end

.create_offer(offer_key, options = {}) ⇒ Object



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

def self.create_offer(offer_key, options = {})
  Access::Api.new.favorites_create offer_key, options.merge(favorite_type: 'offers')
end

.create_store(store_key, options = {}) ⇒ Object



67
68
69
# File 'lib/access/favorite.rb', line 67

def self.create_store(store_key, options = {})
  Access::Api.new.favorites_create store_key, options.merge(favorite_type: 'stores')
end

.delete(offer_key, options = {}) ⇒ Object



71
72
73
# File 'lib/access/favorite.rb', line 71

def self.delete(offer_key, options = {})
  Access::Api.new.favorites_delete offer_key, options
end

.delete_location(location_key, options = {}) ⇒ Object



79
80
81
# File 'lib/access/favorite.rb', line 79

def self.delete_location(location_key, options = {})
  Access::Api.new.favorites_delete location_key, options.merge(favorite_type: 'locations')
end

.delete_offer(offer_key, options = {}) ⇒ Object



75
76
77
# File 'lib/access/favorite.rb', line 75

def self.delete_offer(offer_key, options = {})
  Access::Api.new.favorites_delete offer_key, options.merge(favorite_type: 'offers')
end

.delete_store(store_key, options = {}) ⇒ Object



83
84
85
# File 'lib/access/favorite.rb', line 83

def self.delete_store(store_key, options = {})
  Access::Api.new.favorites_delete store_key, options.merge(favorite_type: 'stores')
end

.find(offer_key, options = {}) ⇒ Object



39
40
41
# File 'lib/access/favorite.rb', line 39

def self.find(offer_key, options = {})
  Access::Api.new.favorites_find offer_key, options
end

.find_location(location_key, options = {}) ⇒ Object



47
48
49
# File 'lib/access/favorite.rb', line 47

def self.find_location(location_key, options = {})
  Access::Api.new.favorites_find location_key, options.merge(favorite_type: 'locations')
end

.find_offer(offer_key, options = {}) ⇒ Object



43
44
45
# File 'lib/access/favorite.rb', line 43

def self.find_offer(offer_key, options = {})
  Access::Api.new.favorites_find offer_key, options.merge(favorite_type: 'offers')
end

.find_store(store_key, options = {}) ⇒ Object



51
52
53
# File 'lib/access/favorite.rb', line 51

def self.find_store(store_key, options = {})
  Access::Api.new.favorites_find store_key, options.merge(favorite_type: 'stores')
end

.process_batch(chunk) ⇒ Object



4
5
6
# File 'lib/access/favorite.rb', line 4

def self.process_batch(chunk)
  chunk.map { |favorite| new(favorite) }
end

.search(options = {}) ⇒ Object



23
24
25
# File 'lib/access/favorite.rb', line 23

def self.search(options = {})
  Access::Api.new.favorites_search options
end

.search_locations(options = {}) ⇒ Object



31
32
33
# File 'lib/access/favorite.rb', line 31

def self.search_locations(options = {})
  Access::Api.new.favorites_search options.merge(favorite_type: 'locations')
end

.search_offers(options = {}) ⇒ Object



27
28
29
# File 'lib/access/favorite.rb', line 27

def self.search_offers(options = {})
  Access::Api.new.favorites_search options.merge(favorite_type: 'offers')
end

.search_stores(options = {}) ⇒ Object



35
36
37
# File 'lib/access/favorite.rb', line 35

def self.search_stores(options = {})
  Access::Api.new.favorites_search options.merge(favorite_type: 'stores')
end

Instance Method Details

#resourceObject



19
20
21
# File 'lib/access/favorite.rb', line 19

def resource
  self.send(self.favorite_type)
end