Class: Vng::Asset
- Inherits:
-
Object
- Object
- Vng::Asset
- Defined in:
- lib/vng/asset.rb
Overview
Provides methods to interact with Vonigo assets.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(id:) ⇒ Asset
constructor
A new instance of Asset.
Constructor Details
#initialize(id:) ⇒ Asset
Returns a new instance of Asset.
6 7 8 |
# File 'lib/vng/asset.rb', line 6 def initialize(id:) @id = id end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/vng/asset.rb', line 4 def id @id end |
Class Method Details
.create(name:, weight:, breed_option_id:, client_id:) ⇒ Object
10 11 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 41 |
# File 'lib/vng/asset.rb', line 10 def self.create(name:, weight:, breed_option_id:, client_id:) body = { securityToken: Vng.configuration.security_token, method: '3', clientID: client_id, Fields: [ {fieldID: 1013, fieldValue: name}, {fieldID: 1017, fieldValue: weight}, {fieldID: 1014, optionID: breed_option_id}, ] } uri = URI::HTTPS.build host: 'aussiepetmobileusatraining2.vonigo.com', path: '/api/v1/data/Assets/' 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 # curl = 'curl'.tap do |curl| # curl << ' -X POST' # request.each_header{|k, v| curl << %Q{ -H "#{k}: #{v}"}} # curl << %Q{ -d '#{request.body}'} if request.body # curl << %Q{ "#{uri.to_s}"} # end # puts curl new id: JSON(response.body)['Asset']['objectID'] end |
Instance Method Details
#destroy ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/vng/asset.rb', line 43 def destroy body = { securityToken: Vng.configuration.security_token, method: '4', objectID: id, } uri = URI::HTTPS.build host: 'aussiepetmobileusatraining2.vonigo.com', path: '/api/v1/data/Assets/' 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 end |