Class: PQSDK::OfferBatch
- Inherits:
-
Object
- Object
- PQSDK::OfferBatch
- Defined in:
- lib/pqsdk/offer_batch.rb
Instance Attribute Summary collapse
-
#offers ⇒ Object
Returns the value of attribute offers.
Instance Method Summary collapse
- #<<(offer) ⇒ Object
-
#initialize ⇒ OfferBatch
constructor
A new instance of OfferBatch.
- #save ⇒ Object
Constructor Details
#initialize ⇒ OfferBatch
Returns a new instance of OfferBatch.
5 6 7 |
# File 'lib/pqsdk/offer_batch.rb', line 5 def initialize @offers = [] end |
Instance Attribute Details
#offers ⇒ Object
Returns the value of attribute offers.
3 4 5 |
# File 'lib/pqsdk/offer_batch.rb', line 3 def offers @offers end |
Instance Method Details
#<<(offer) ⇒ Object
9 10 11 |
# File 'lib/pqsdk/offer_batch.rb', line 9 def <<(offer) @offers << offer end |
#save ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/pqsdk/offer_batch.rb', line 13 def save request = [] method = :post endpoint = "v1/offers" @offers.each do |offer| request << offer.to_hash end res = RestLayer.send(method, endpoint, request, {'Authorization' => "Bearer #{Token.access_token}", 'Content-Type' => 'application/json'}) if res[0] == 200 # 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]}") end end |