Class: Vng::ServiceType

Inherits:
Object
  • Object
show all
Defined in:
lib/vng/service_type.rb

Overview

Provides methods to interact with Vonigo service types.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#durationObject (readonly)

Returns the value of attribute duration.



4
5
6
# File 'lib/vng/service_type.rb', line 4

def duration
  @duration
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/vng/service_type.rb', line 4

def id
  @id
end

#typeObject (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

.allObject

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