Class: Vng::Zip
- Inherits:
-
Object
- Object
- Vng::Zip
- Defined in:
- lib/vng/zip.rb
Overview
Provides methods to interact with Vonigo ZIP codes.
Instance Attribute Summary collapse
-
#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
-
.all ⇒ Object
TODO: Needs pagination.
Instance Method Summary collapse
-
#initialize(zip:, state:, zone_name:) ⇒ Zip
constructor
A new instance of Zip.
Constructor Details
#initialize(zip:, state:, zone_name:) ⇒ Zip
Returns a new instance of Zip.
6 7 8 9 10 |
# File 'lib/vng/zip.rb', line 6 def initialize(zip:, state:, zone_name:) @zip = zip @state = state @zone_name = zone_name end |
Instance Attribute Details
#state ⇒ Object (readonly)
Returns the value of attribute state.
4 5 6 |
# File 'lib/vng/zip.rb', line 4 def state @state end |
#zip ⇒ Object (readonly)
Returns the value of attribute zip.
4 5 6 |
# File 'lib/vng/zip.rb', line 4 def zip @zip end |
#zone_name ⇒ Object (readonly)
Returns the value of attribute zone_name.
4 5 6 |
# File 'lib/vng/zip.rb', line 4 def zone_name @zone_name end |
Class Method Details
.all ⇒ Object
TODO: Needs pagination
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/vng/zip.rb', line 13 def self.all body = { securityToken: Vng.configuration.security_token, } uri = URI::HTTPS.build host: 'aussiepetmobileusatraining2.vonigo.com', path: '/api/v1/resources/zips/' request = Net::HTTP::Post.new(uri.request_uri) request.initialize_http_header 'Content-Type' => 'application/json' request.body = body.to_json response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http| http.request request end JSON(response.body)['Zips'].map do |body| zip = body['zip'] state = body['state'] zone_name = body['zoneName'] new zip: zip, state: state, zone_name: zone_name end end |