Class: Vng::ServiceType
- Inherits:
-
Object
- Object
- Vng::ServiceType
- Defined in:
- lib/vng/service_type.rb
Overview
Provides methods to interact with Vonigo service types.
Instance Attribute Summary collapse
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.all ⇒ Object
TODO: Needs pagination.
- .where(zip:) ⇒ Object
Instance Method Summary collapse
-
#initialize(id:, type:, duration:) ⇒ ServiceType
constructor
A new instance of ServiceType.
Constructor Details
#initialize(id:, type:, duration:) ⇒ ServiceType
Returns a new instance of ServiceType.
6 7 8 9 10 |
# File 'lib/vng/service_type.rb', line 6 def initialize(id:, type:, duration:) @id = id @type = type @duration = duration end |
Instance Attribute Details
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
4 5 6 |
# File 'lib/vng/service_type.rb', line 4 def duration @duration end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/vng/service_type.rb', line 4 def id @id end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/vng/service_type.rb', line 4 def type @type 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/service_type.rb', line 13 def self.all body = { securityToken: Vng.configuration.security_token, } uri = URI::HTTPS.build host: 'aussiepetmobileusatraining2.vonigo.com', path: '/api/v1/resources/serviceTypes/' 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)['ServiceTypes'].map do |body| id = body['serviceTypeID'] type = body['serviceType'] duration = body['duration'] new id: id, type: type, duration: duration end end |
.where(zip:) ⇒ Object
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 |
# File 'lib/vng/service_type.rb', line 37 def self.where(zip:) body = { securityToken: Vng.configuration.security_token, zip: zip, } uri = URI::HTTPS.build host: 'aussiepetmobileusatraining2.vonigo.com', path: '/api/v1/resources/serviceTypes/' 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)['ServiceTypes'].filter do |body| body['isActive'] end.map do |body| id = body['serviceTypeID'] type = body['serviceType'] duration = body['duration'] new id: id, type: type, duration: duration end end |