Class: Vng::Breed

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

Overview

Provides methods to interact with Vonigo breeds.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name:, species:, option_id:, low_weight:, high_weight:) ⇒ Breed

Returns a new instance of Breed.



6
7
8
9
10
11
12
13
# File 'lib/vng/breed.rb', line 6

def initialize(id:, name:, species:, option_id:, low_weight:, high_weight:)
  @id = id
  @name = name
  @species = species
  @option_id = option_id
  @low_weight = low_weight
  @high_weight = high_weight
end

Instance Attribute Details

#high_weightObject (readonly)

Returns the value of attribute high_weight.



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

def high_weight
  @high_weight
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#low_weightObject (readonly)

Returns the value of attribute low_weight.



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

def low_weight
  @low_weight
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#option_idObject (readonly)

Returns the value of attribute option_id.



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

def option_id
  @option_id
end

#speciesObject (readonly)

Returns the value of attribute species.



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

def species
  @species
end

Class Method Details

.allObject

TODO: Needs pagination



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
41
# File 'lib/vng/breed.rb', line 16

def self.all
  body = {
    securityToken: Vng.configuration.security_token,
  }

  uri = URI::HTTPS.build host: 'aussiepetmobileusatraining2.vonigo.com', path: '/api/v1/resources/breeds/'

  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)['Breeds'].map do |body|
    id = body['breedID']
    name = body['breed']
    species = body['species']
    option_id = body['optionID']
    low_weight = body['breedLowWeight']
    high_weight = body['breedHighWeight']

    new id: id, name: name, species: species, option_id: option_id, low_weight: low_weight, high_weight: high_weight
  end
end