Class: PQSDK::Offer
- Inherits:
-
Object
- Object
- PQSDK::Offer
- Defined in:
- lib/pqsdk/offer.rb
Instance Attribute Summary collapse
-
#brand ⇒ Object
Returns the value of attribute brand.
-
#btn_online_offers_visible ⇒ Object
Returns the value of attribute btn_online_offers_visible.
-
#btn_other_offers_visible ⇒ Object
Returns the value of attribute btn_other_offers_visible.
-
#btn_partner_link_text ⇒ Object
Returns the value of attribute btn_partner_link_text.
-
#btn_partner_link_visible ⇒ Object
Returns the value of attribute btn_partner_link_visible.
-
#btn_print_visible ⇒ Object
Returns the value of attribute btn_print_visible.
-
#btn_stores_visible ⇒ Object
Returns the value of attribute btn_stores_visible.
-
#description ⇒ Object
Returns the value of attribute description.
-
#discount ⇒ Object
Returns the value of attribute discount.
-
#end_date ⇒ Object
Returns the value of attribute end_date.
-
#image ⇒ Object
Returns the value of attribute image.
-
#national ⇒ Object
Returns the value of attribute national.
-
#original_price ⇒ Object
Returns the value of attribute original_price.
-
#partner_link ⇒ Object
Returns the value of attribute partner_link.
-
#price ⇒ Object
Returns the value of attribute price.
-
#start_date ⇒ Object
Returns the value of attribute start_date.
-
#store_ids ⇒ Object
Returns the value of attribute store_ids.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Offer
constructor
A new instance of Offer.
- #save ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Offer
Returns a new instance of Offer.
6 7 8 9 10 11 12 |
# File 'lib/pqsdk/offer.rb', line 6 def initialize(params = {}) params.each do |key, val| send("#{key}=", val) end store_ids ||= [] end |
Instance Attribute Details
#brand ⇒ Object
Returns the value of attribute brand.
3 4 5 |
# File 'lib/pqsdk/offer.rb', line 3 def brand @brand end |
#btn_online_offers_visible ⇒ Object
Returns the value of attribute btn_online_offers_visible.
3 4 5 |
# File 'lib/pqsdk/offer.rb', line 3 def btn_online_offers_visible @btn_online_offers_visible end |
#btn_other_offers_visible ⇒ Object
Returns the value of attribute btn_other_offers_visible.
3 4 5 |
# File 'lib/pqsdk/offer.rb', line 3 def btn_other_offers_visible @btn_other_offers_visible end |
#btn_partner_link_text ⇒ Object
Returns the value of attribute btn_partner_link_text.
3 4 5 |
# File 'lib/pqsdk/offer.rb', line 3 def btn_partner_link_text @btn_partner_link_text end |
#btn_partner_link_visible ⇒ Object
Returns the value of attribute btn_partner_link_visible.
3 4 5 |
# File 'lib/pqsdk/offer.rb', line 3 def btn_partner_link_visible @btn_partner_link_visible end |
#btn_print_visible ⇒ Object
Returns the value of attribute btn_print_visible.
3 4 5 |
# File 'lib/pqsdk/offer.rb', line 3 def btn_print_visible @btn_print_visible end |
#btn_stores_visible ⇒ Object
Returns the value of attribute btn_stores_visible.
3 4 5 |
# File 'lib/pqsdk/offer.rb', line 3 def btn_stores_visible @btn_stores_visible end |
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/pqsdk/offer.rb', line 3 def description @description end |
#discount ⇒ Object
Returns the value of attribute discount.
3 4 5 |
# File 'lib/pqsdk/offer.rb', line 3 def discount @discount end |
#end_date ⇒ Object
Returns the value of attribute end_date.
3 4 5 |
# File 'lib/pqsdk/offer.rb', line 3 def end_date @end_date end |
#image ⇒ Object
Returns the value of attribute image.
3 4 5 |
# File 'lib/pqsdk/offer.rb', line 3 def image @image end |
#national ⇒ Object
Returns the value of attribute national.
3 4 5 |
# File 'lib/pqsdk/offer.rb', line 3 def national @national end |
#original_price ⇒ Object
Returns the value of attribute original_price.
3 4 5 |
# File 'lib/pqsdk/offer.rb', line 3 def original_price @original_price end |
#partner_link ⇒ Object
Returns the value of attribute partner_link.
3 4 5 |
# File 'lib/pqsdk/offer.rb', line 3 def partner_link @partner_link end |
#price ⇒ Object
Returns the value of attribute price.
3 4 5 |
# File 'lib/pqsdk/offer.rb', line 3 def price @price end |
#start_date ⇒ Object
Returns the value of attribute start_date.
3 4 5 |
# File 'lib/pqsdk/offer.rb', line 3 def start_date @start_date end |
#store_ids ⇒ Object
Returns the value of attribute store_ids.
3 4 5 |
# File 'lib/pqsdk/offer.rb', line 3 def store_ids @store_ids end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/pqsdk/offer.rb', line 3 def title @title end |
Instance Method Details
#save ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/pqsdk/offer.rb', line 14 def save method = :post endpoint = "v1/offers" fields = {:offer => {}} [ :title, :description, :price, :original_price, :discount, :start_date, :end_date, :brand, :image, :national, :partner_link, :btn_other_offers_visible, :btn_partner_link_text, :btn_partner_link_visible, :btn_print_visible, :btn_stores_visible, :btn_online_offers_visible ].each do |key| fields[:offer][key.to_s] = send(key) unless send(key).nil? end fields[:offer]['store_ids'] = store_ids.presence || [] res = RestLayer.send(method, endpoint, fields, {'Authorization' => "Bearer #{Token.access_token}", 'Content-Type' => 'application/json'}) if [200, 201].include? res[0] # All right! elsif res[0] == 400 raise Exception.new("Bad request! Error: #{res[1]['errors']}") else raise Exception.new("Unexpected HTTP status code #{res[0]}, #{res[1]}") end end |
#to_hash ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/pqsdk/offer.rb', line 37 def to_hash { title: title, description: description, price: price, original_price: original_price, discount: discount, start_date: start_date, end_date: end_date, brand: brand, image: image, store_ids: store_ids } end |