Class: PQSDK::Store
- Inherits:
-
Object
- Object
- PQSDK::Store
- Defined in:
- lib/pqsdk/store.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#city ⇒ Object
Returns the value of attribute city.
-
#city_id ⇒ Object
Returns the value of attribute city_id.
-
#id ⇒ Object
Returns the value of attribute id.
-
#latitude ⇒ Object
Returns the value of attribute latitude.
-
#leaflet_ids ⇒ Object
Returns the value of attribute leaflet_ids.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
-
#name ⇒ Object
Returns the value of attribute name.
-
#opening_hours ⇒ Object
Returns the value of attribute opening_hours.
-
#opening_hours_text ⇒ Object
Returns the value of attribute opening_hours_text.
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#phone ⇒ Object
Returns the value of attribute phone.
-
#zipcode ⇒ Object
Returns the value of attribute zipcode.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Store
constructor
A new instance of Store.
- #save ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Store
Returns a new instance of Store.
5 6 7 8 9 10 11 12 |
# File 'lib/pqsdk/store.rb', line 5 def initialize(params = {}) params.each do |key, val| send("#{key}=", val) end self.leaflet_ids ||= [] self.opening_hours ||= [] end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
3 4 5 |
# File 'lib/pqsdk/store.rb', line 3 def address @address end |
#city ⇒ Object
Returns the value of attribute city.
3 4 5 |
# File 'lib/pqsdk/store.rb', line 3 def city @city end |
#city_id ⇒ Object
Returns the value of attribute city_id.
3 4 5 |
# File 'lib/pqsdk/store.rb', line 3 def city_id @city_id end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/pqsdk/store.rb', line 3 def id @id end |
#latitude ⇒ Object
Returns the value of attribute latitude.
3 4 5 |
# File 'lib/pqsdk/store.rb', line 3 def latitude @latitude end |
#leaflet_ids ⇒ Object
Returns the value of attribute leaflet_ids.
3 4 5 |
# File 'lib/pqsdk/store.rb', line 3 def leaflet_ids @leaflet_ids end |
#longitude ⇒ Object
Returns the value of attribute longitude.
3 4 5 |
# File 'lib/pqsdk/store.rb', line 3 def longitude @longitude end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/pqsdk/store.rb', line 3 def name @name end |
#opening_hours ⇒ Object
Returns the value of attribute opening_hours.
3 4 5 |
# File 'lib/pqsdk/store.rb', line 3 def opening_hours @opening_hours end |
#opening_hours_text ⇒ Object
Returns the value of attribute opening_hours_text.
3 4 5 |
# File 'lib/pqsdk/store.rb', line 3 def opening_hours_text @opening_hours_text end |
#origin ⇒ Object
Returns the value of attribute origin.
3 4 5 |
# File 'lib/pqsdk/store.rb', line 3 def origin @origin end |
#phone ⇒ Object
Returns the value of attribute phone.
3 4 5 |
# File 'lib/pqsdk/store.rb', line 3 def phone @phone end |
#zipcode ⇒ Object
Returns the value of attribute zipcode.
3 4 5 |
# File 'lib/pqsdk/store.rb', line 3 def zipcode @zipcode end |
Class Method Details
.find(address, zipcode, retailer = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pqsdk/store.rb', line 14 def self.find(address, zipcode, retailer = nil) res = RestLayer.get('v1/stores', { address: address, zipcode: zipcode, retailer: retailer }, { 'Authorization' => "Bearer #{Token.access_token}" }) if res[0] == 200 Store.from_json res[1] elsif res[0] == 404 nil else raise Exception.new("Unexpected HTTP status code #{res[0]}, #{res[1]}") end end |
.get(id) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/pqsdk/store.rb', line 25 def self.get(id) res = RestLayer.get("v1/stores/#{id}", { }, { 'Authorization' => "Bearer #{Token.access_token}" }) if res[0] == 200 Store.from_json res[1] elsif res[0] == 404 nil else raise Exception.new("Unexpected HTTP status code #{res[0]}, #{res[1]}") end end |
Instance Method Details
#save ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/pqsdk/store.rb', line 36 def save if self.id != nil method = :put url = "v1/stores/#{self.id}" expected_status = 200 else method = :post url = "v1/stores" expected_status = 201 end if city.nil? and city_id.nil? raise "city or city_id must be set" end fields = {} if method != :put [ :name, :address, :zipcode, :latitude, :longitude, :origin ].each do |field| raise "Missing required #{field} field" if send(field).to_s == '' fields[field.to_s] = send(field) end fields['city'] = city if city fields['city_id'] = city_id if city_id fields['phone'] = phone if phone end fields['opening_hours'] = opening_hours if opening_hours.try(:any?) fields['opening_hours_text'] = opening_hours_text if opening_hours_text.present? res = RestLayer.send(method, url, fields, { 'Authorization' => "Bearer #{Token.access_token}", 'Content-Type' => 'application/json' }) 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 |