Class: PQSDK::Store

Inherits:
RemoteObject show all
Defined in:
lib/pqsdk/store.rb

Overview

The Store class provides an interface for crawlers to the v1/stores api endpoint.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RemoteObject

all, #create, #create!, get, #persisted?, #save, #save!, #update, #update!

Instance Attribute Details

#addressObject

Returns the value of attribute address.



9
10
11
# File 'lib/pqsdk/store.rb', line 9

def address
  @address
end

#cityObject

Returns the value of attribute city.



9
10
11
# File 'lib/pqsdk/store.rb', line 9

def city
  @city
end

#city_idObject

Returns the value of attribute city_id.



9
10
11
# File 'lib/pqsdk/store.rb', line 9

def city_id
  @city_id
end

#idObject

Returns the value of attribute id.



9
10
11
# File 'lib/pqsdk/store.rb', line 9

def id
  @id
end

#latitudeObject

Returns the value of attribute latitude.



9
10
11
# File 'lib/pqsdk/store.rb', line 9

def latitude
  @latitude
end

#longitudeObject

Returns the value of attribute longitude.



9
10
11
# File 'lib/pqsdk/store.rb', line 9

def longitude
  @longitude
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/pqsdk/store.rb', line 9

def name
  @name
end

#opening_hoursObject

Returns the value of attribute opening_hours.



9
10
11
# File 'lib/pqsdk/store.rb', line 9

def opening_hours
  @opening_hours
end

#opening_hours_textObject

Returns the value of attribute opening_hours_text.



9
10
11
# File 'lib/pqsdk/store.rb', line 9

def opening_hours_text
  @opening_hours_text
end

#originObject

Returns the value of attribute origin.



9
10
11
# File 'lib/pqsdk/store.rb', line 9

def origin
  @origin
end

#phoneObject

Returns the value of attribute phone.



9
10
11
# File 'lib/pqsdk/store.rb', line 9

def phone
  @phone
end

#regionObject

Returns the value of attribute region.



9
10
11
# File 'lib/pqsdk/store.rb', line 9

def region
  @region
end

#zipcodeObject

Returns the value of attribute zipcode.



9
10
11
# File 'lib/pqsdk/store.rb', line 9

def zipcode
  @zipcode
end

Class Method Details

.find(address, zipcode, retailer = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/pqsdk/store.rb', line 27

def self.find(address, zipcode, retailer = nil)
  res = RestLayer.get(@endpoint, { address: address, zipcode: zipcode, retailer: retailer }, 'Authorization' => "Bearer #{Token.access_token}")
  if res[0] == 200
    from_hash res[1]
  elsif res[0] == 404
    nil
  else
    raise "Unexpected HTTP status code #{res[0]}, #{res[1]}"
  end
end

.from_hash(json) ⇒ Object



38
39
40
# File 'lib/pqsdk/store.rb', line 38

def self.from_hash(json)
  super(json.stringify_keys.except('city'))
end

Instance Method Details

#attributesObject



15
16
17
18
19
20
21
# File 'lib/pqsdk/store.rb', line 15

def attributes
  {
    'origin' => nil, 'name' => nil, 'address' => nil, 'latitude' => nil,
    'longitude' => nil, 'city' => nil, 'city_id' => nil, 'zipcode' => nil,
    'phone' => nil, 'opening_hours' => nil, 'opening_hours_text' => nil, 'region' => nil
  }
end