Class: Access::Favorite

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MuchMeta

#set_up_methods, #set_values

Constructor Details

#initialize(values) ⇒ Favorite

Returns a new instance of Favorite.



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

def initialize(values)
  @used_fields = []
  set_up_methods(values)
  set_values(values)
  @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(resource_key, options = {}) ⇒ Object

create



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

def self.create(resource_key, options = {})
  # must pass in a favorite_type
  Access::Api.new.favorites_create resource_key, options
end

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



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

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



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

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



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

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

delete



81
82
83
# File 'lib/access/favorite.rb', line 81

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

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



89
90
91
# File 'lib/access/favorite.rb', line 89

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



85
86
87
# File 'lib/access/favorite.rb', line 85

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



93
94
95
# File 'lib/access/favorite.rb', line 93

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

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

find / show



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

def self.find(resource_id, options = {})
  # must pass in a favorite_type
  Access::Api.new.favorites_find resource_id, options
end

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



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

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



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

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



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

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

.process_batch(chunk) ⇒ Object



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

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

.search(options = {}) ⇒ Object

search / index



25
26
27
# File 'lib/access/favorite.rb', line 25

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

.search_locations(options = {}) ⇒ Object



33
34
35
# File 'lib/access/favorite.rb', line 33

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

.search_offers(options = {}) ⇒ Object



29
30
31
# File 'lib/access/favorite.rb', line 29

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

.search_stores(options = {}) ⇒ Object



37
38
39
# File 'lib/access/favorite.rb', line 37

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