Class: Vng::Contact
- Inherits:
-
Object
- Object
- Vng::Contact
- Defined in:
- lib/vng/contact.rb
Overview
Provides methods to interact with Vonigo contacts.
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#first_name ⇒ Object
readonly
Returns the value of attribute first_name.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_name ⇒ Object
readonly
Returns the value of attribute last_name.
-
#phone ⇒ Object
readonly
Returns the value of attribute phone.
Class Method Summary collapse
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(id:, first_name:, last_name:, email:, phone:) ⇒ Contact
constructor
A new instance of Contact.
Constructor Details
#initialize(id:, first_name:, last_name:, email:, phone:) ⇒ Contact
Returns a new instance of Contact.
6 7 8 9 10 11 12 |
# File 'lib/vng/contact.rb', line 6 def initialize(id:, first_name:, last_name:, email:, phone:) @id = id @first_name = first_name @last_name = last_name @email = email @phone = phone end |
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
4 5 6 |
# File 'lib/vng/contact.rb', line 4 def email @email end |
#first_name ⇒ Object (readonly)
Returns the value of attribute first_name.
4 5 6 |
# File 'lib/vng/contact.rb', line 4 def first_name @first_name end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/vng/contact.rb', line 4 def id @id end |
#last_name ⇒ Object (readonly)
Returns the value of attribute last_name.
4 5 6 |
# File 'lib/vng/contact.rb', line 4 def last_name @last_name end |
#phone ⇒ Object (readonly)
Returns the value of attribute phone.
4 5 6 |
# File 'lib/vng/contact.rb', line 4 def phone @phone end |
Class Method Details
.create(first_name:, last_name:, email:, phone:, client_id:) ⇒ Object
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 42 43 44 45 46 |
# File 'lib/vng/contact.rb', line 14 def self.create(first_name:, last_name:, email:, phone:, client_id:) body = { securityToken: Vng.configuration.security_token, method: '3', clientID: client_id, Fields: [ {fieldID: 127, fieldValue: first_name}, {fieldID: 128, fieldValue: last_name}, {fieldID: 97, fieldValue: email}, {fieldID: 96, fieldValue: phone}, ] } uri = URI::HTTPS.build host: 'aussiepetmobileusatraining2.vonigo.com', path: '/api/v1/data/Contacts/' 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 body = JSON response.body id = body['Contact']['objectID'] first_name = body['Fields'].find{|field| field['fieldID'] == 127}['fieldValue'] last_name = body['Fields'].find{|field| field['fieldID'] == 128}['fieldValue'] email = body['Fields'].find{|field| field['fieldID'] == 97}['fieldValue'] phone = body['Fields'].find{|field| field['fieldID'] == 96}['fieldValue'] new id: id, first_name: first_name, last_name: last_name, email: email, phone: phone end |
Instance Method Details
#destroy ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/vng/contact.rb', line 48 def destroy body = { securityToken: Vng.configuration.security_token, method: '4', objectID: id, } uri = URI::HTTPS.build host: 'aussiepetmobileusatraining2.vonigo.com', path: '/api/v1/data/Contacts/' 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 |