Class: Vng::Zip
Overview
Provides methods to interact with Vonigo ZIP codes.
Constant Summary collapse
- PATH =
'/api/v1/resources/zips/'
Instance Attribute Summary collapse
-
#city ⇒ Object
readonly
Returns the value of attribute city.
-
#service_types ⇒ Object
readonly
Returns the value of attribute service_types.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#zip ⇒ Object
readonly
Returns the value of attribute zip.
-
#zone_name ⇒ Object
readonly
Returns the value of attribute zone_name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(zip:, state:, zone_name:, city: nil, service_types: []) ⇒ Zip
constructor
A new instance of Zip.
Constructor Details
#initialize(zip:, state:, zone_name:, city: nil, service_types: []) ⇒ Zip
Returns a new instance of Zip.
11 12 13 14 15 16 17 |
# File 'lib/vng/zip.rb', line 11 def initialize(zip:, state:, zone_name:, city: nil, service_types: []) @zip = zip @state = state @zone_name = zone_name @city = city @service_types = service_types end |
Instance Attribute Details
#city ⇒ Object (readonly)
Returns the value of attribute city.
9 10 11 |
# File 'lib/vng/zip.rb', line 9 def city @city end |
#service_types ⇒ Object (readonly)
Returns the value of attribute service_types.
9 10 11 |
# File 'lib/vng/zip.rb', line 9 def service_types @service_types end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
9 10 11 |
# File 'lib/vng/zip.rb', line 9 def state @state end |
#zip ⇒ Object (readonly)
Returns the value of attribute zip.
9 10 11 |
# File 'lib/vng/zip.rb', line 9 def zip @zip end |
#zone_name ⇒ Object (readonly)
Returns the value of attribute zone_name.
9 10 11 |
# File 'lib/vng/zip.rb', line 9 def zone_name @zone_name end |
Class Method Details
.all ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/vng/zip.rb', line 19 def self.all data = request path: PATH data.fetch('Zips', []).reject do |franchise| ['Owned – Deactivated', 'Owned - Not In Service'].include? franchise['zipStatus'] end.map do |body| zip = body['zip'] state = body['state'] zone_name = body['zoneName'] new zip: zip, state: state, zone_name: zone_name end end |
.find_by(zip:) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/vng/zip.rb', line 33 def self.find_by(zip:) body = { method: '1', zip: zip, } data = request path: PATH, body: body zip_data = data['Zip'] # TODO: Remove ServiceType class, store duration and price_list_id # inside Zip itself unless zip_data['zipCodeID'] == '0' service_types = data['ServiceTypes'].map do |body| id = body['serviceTypeID'] type = body['serviceType'] duration = body['duration'] price_list_id = body['priceID'] ServiceType.new id: id, type: type, duration: duration, price_list_id: price_list_id end new zip: zip_data['zipCode'], state: zip_data['provinceAbbr'], zone_name: zip_data['zoneName'], city: zip_data['defaultCity'], service_types: service_types end end |