Class: Vng::Availability
- Inherits:
-
Object
- Object
- Vng::Availability
- Defined in:
- lib/vng/availability.rb
Overview
Provides methods to interact with Vonigo availabilities.
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#minutes ⇒ Object
readonly
Returns the value of attribute minutes.
-
#route_id ⇒ Object
readonly
Returns the value of attribute route_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(route_id:, date:, minutes:) ⇒ Availability
constructor
A new instance of Availability.
Constructor Details
#initialize(route_id:, date:, minutes:) ⇒ Availability
Returns a new instance of Availability.
6 7 8 9 10 |
# File 'lib/vng/availability.rb', line 6 def initialize(route_id:, date:, minutes:) @route_id = route_id @date = date @minutes = minutes end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
4 5 6 |
# File 'lib/vng/availability.rb', line 4 def date @date end |
#minutes ⇒ Object (readonly)
Returns the value of attribute minutes.
4 5 6 |
# File 'lib/vng/availability.rb', line 4 def minutes @minutes end |
#route_id ⇒ Object (readonly)
Returns the value of attribute route_id.
4 5 6 |
# File 'lib/vng/availability.rb', line 4 def route_id @route_id end |
Class Method Details
.where(location_id:, duration:, from_time:, to_time:) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/vng/availability.rb', line 12 def self.where(location_id:, duration:, from_time:, to_time:) body = { securityToken: Vng.configuration.security_token, method: '0', serviceTypeID: '14', # only return items of serviceType 'Pet Grooming' locationID: location_id, duration: duration.to_i, dateStart: from_time.to_i, dateEnd: to_time.to_i, } 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 JSON(response.body)['Availability'].map do |body| route_id = body['routeID'] date = Date.strptime body['dayID'], '%Y%m%d' minutes = body['startTime'].to_i new route_id: route_id, date: date, minutes: minutes end end |