Class: PQSDK::Leaflet
- Inherits:
-
Object
- Object
- PQSDK::Leaflet
- Defined in:
- lib/pqsdk/leaflet.rb
Instance Attribute Summary collapse
-
#end_date ⇒ Object
Returns the value of attribute end_date.
-
#id ⇒ Object
Returns the value of attribute id.
-
#image_urls ⇒ Object
Returns the value of attribute image_urls.
-
#name ⇒ Object
Returns the value of attribute name.
-
#pdf_data ⇒ Object
Returns the value of attribute pdf_data.
-
#start_date ⇒ Object
Returns the value of attribute start_date.
-
#store_ids ⇒ Object
Returns the value of attribute store_ids.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Leaflet
constructor
A new instance of Leaflet.
- #save ⇒ Object
- #show ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Leaflet
Returns a new instance of Leaflet.
5 6 7 8 9 10 11 12 |
# File 'lib/pqsdk/leaflet.rb', line 5 def initialize(params = {}) params.each do |key, val| send("#{key}=", val) end self.image_urls ||= [] self.store_ids ||= [] end |
Instance Attribute Details
#end_date ⇒ Object
Returns the value of attribute end_date.
3 4 5 |
# File 'lib/pqsdk/leaflet.rb', line 3 def end_date @end_date end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/pqsdk/leaflet.rb', line 3 def id @id end |
#image_urls ⇒ Object
Returns the value of attribute image_urls.
3 4 5 |
# File 'lib/pqsdk/leaflet.rb', line 3 def image_urls @image_urls end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/pqsdk/leaflet.rb', line 3 def name @name end |
#pdf_data ⇒ Object
Returns the value of attribute pdf_data.
3 4 5 |
# File 'lib/pqsdk/leaflet.rb', line 3 def pdf_data @pdf_data end |
#start_date ⇒ Object
Returns the value of attribute start_date.
3 4 5 |
# File 'lib/pqsdk/leaflet.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/leaflet.rb', line 3 def store_ids @store_ids end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/pqsdk/leaflet.rb', line 3 def url @url end |
Class Method Details
.find(url) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pqsdk/leaflet.rb', line 14 def self.find(url) res = RestLayer.get('v1/leaflets', { url: url }, { 'Authorization' => "Bearer #{Token.access_token}" }) if res[0] == 200 Leaflet.from_json res[1] elsif res[0] == 404 nil else raise Exception.new("Unexpected HTTP status code #{res[0]}") end end |
Instance Method Details
#save ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/pqsdk/leaflet.rb', line 39 def save method = :post endpoint = "v1/leaflets" expected_status = 201 fields = {} fields['name'] = name unless name.nil? fields['url'] = url unless url.nil? fields['start_date'] = start_date unless start_date.nil? fields['end_date'] = end_date unless end_date.nil? fields['pdf_data'] = pdf_data unless pdf_data.nil? fields['image_urls'] = image_urls.try(:to_json) || [] fields['store_ids'] = store_ids.try(:to_json) || [] res = RestLayer.send(method, endpoint, fields, {'Authorization' => "Bearer #{Token.access_token}"}) if res[0] != expected_status raise Exception.new("Unexpected HTTP status code #{res[0]}, #{res[1]}") else if method == :post self.id = res[1]['id'] end end end |
#show ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/pqsdk/leaflet.rb', line 25 def show method = :get endpoint = "v1/leaflet" expected_status = 201 fields = {} fields['id'] = id unless id.is_a? Integer and !id.nil? res = RestLayer.send(method, endpoint, fields, {'Authorization' => "Bearer #{Token.access_token}"}) if res[0] != expected_status raise Exception.new("Unexpected HTTP status code #{res[0]}, #{res[1]}") end end |