Class: Vng::Franchise
- Inherits:
-
Object
- Object
- Vng::Franchise
- Defined in:
- lib/vng/franchise.rb
Overview
Provides methods to interact with Vonigo franchises.
Instance Attribute Summary collapse
-
#gmt_offset ⇒ Object
readonly
Returns the value of attribute gmt_offset.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id:, name: nil, gmt_offset: nil) ⇒ Franchise
constructor
A new instance of Franchise.
Constructor Details
#initialize(id:, name: nil, gmt_offset: nil) ⇒ Franchise
Returns a new instance of Franchise.
6 7 8 9 10 |
# File 'lib/vng/franchise.rb', line 6 def initialize(id:, name: nil, gmt_offset: nil) @id = id @name = name @gmt_offset = gmt_offset end |
Instance Attribute Details
#gmt_offset ⇒ Object (readonly)
Returns the value of attribute gmt_offset.
4 5 6 |
# File 'lib/vng/franchise.rb', line 4 def gmt_offset @gmt_offset end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/vng/franchise.rb', line 4 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/vng/franchise.rb', line 4 def name @name end |
Class Method Details
.all ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/vng/franchise.rb', line 34 def self.all body = { securityToken: Vng.configuration.security_token, } uri = URI::HTTPS.build host: 'aussiepetmobileusatraining2.vonigo.com', path: '/api/v1/resources/franchises/' 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)['Franchises'].filter do |body| body['isActive'] end.map do |body| id = body['franchiseID'] name = body['franchiseName'] gmt_offset = body['gmtOffsetFranchise'] new id: id, name: name, gmt_offset: gmt_offset end end |
.find_by(zip:) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/vng/franchise.rb', line 13 def self.find_by(zip:) body = { securityToken: Vng.configuration.security_token, method: '1', zip: zip, } uri = URI::HTTPS.build host: 'aussiepetmobileusatraining2.vonigo.com', path: '/api/v1/resources/availability/' 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 franchise_id = JSON(response.body)['Ids']['franchiseID'] new(id: franchise_id) unless franchise_id == '0' end |