Class: Libring::API
- Inherits:
-
Object
- Object
- Libring::API
- Defined in:
- lib/libring/api.rb
Instance Attribute Summary collapse
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #event_track(contact) ⇒ Object
- #get_all_messages ⇒ Object
- #get_clv(contact_code) ⇒ Object
- #get_contact(contact_code) ⇒ Object
- #get_message(contact_code) ⇒ Object
-
#initialize(token) ⇒ API
constructor
A new instance of API.
- #update_attribute(contact_code, name, value, type) ⇒ Object
Constructor Details
#initialize(token) ⇒ API
Returns a new instance of API.
5 6 7 8 9 |
# File 'lib/libring/api.rb', line 5 def initialize(token) @token = token true end |
Instance Attribute Details
#token ⇒ Object (readonly)
Returns the value of attribute token.
3 4 5 |
# File 'lib/libring/api.rb', line 3 def token @token end |
Instance Method Details
#event_track(contact) ⇒ Object
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 42 43 44 45 46 47 48 49 |
# File 'lib/libring/api.rb', line 11 def event_track(contact) require "net/https" require "uri" require "json" x = 0 begin x += 1 uri = URI.parse("http://api-clv.libring.com/v2/event_tracker") https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = false https.verify_mode = OpenSSL::SSL::VERIFY_NONE req = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' =>'application/json', 'Authorization' => "Token #{@token}"}) req.set_form_data({ libring: { "#{contact.contact_code}" => { attributes: contact.attributes, location: contact.location, events: contact.events } }.to_json }) response = https.request(req) if response.body == "" { success: true } else { error: response.body, success: false } end rescue if x <= 5 retry end end end |
#get_all_messages ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/libring/api.rb', line 114 def require "net/https" require "uri" require "json" uri = URI.parse("http://api-clv.libring.com/v2/messages/get_all") https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = false req = Net::HTTP::Get.new(uri.request_uri, initheader = {'Content-Type' =>'application/json', 'Authorization' => "Token #{@token}"}) resp = https.request(req) resp.body end |
#get_clv(contact_code) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/libring/api.rb', line 133 def get_clv(contact_code) require "net/https" require "uri" require "json" uri = URI.parse("http://api-clv.libring.com/v2/clv/get/" + contact_code.to_s) https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = false req = Net::HTTP::Get.new(uri.request_uri, initheader = {'Content-Type' =>'application/json', 'Authorization' => "Token #{@token}"}) resp = https.request(req) resp.body end |
#get_contact(contact_code) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/libring/api.rb', line 51 def get_contact(contact_code) require "net/https" require "uri" require "json" uri = URI.parse("http://api-clv.libring.com/v2/contact/get/" + contact_code.to_s) https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = false req = Net::HTTP::Get.new(uri.request_uri, initheader = {'Content-Type' =>'application/json', 'Authorization' => "Token #{@token}"}) resp = https.request(req) resp.body end |
#get_message(contact_code) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/libring/api.rb', line 95 def (contact_code) require "net/https" require "uri" require "json" uri = URI.parse("http://api-clv.libring.com/v2/messages/get/" + contact_code.to_s) https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = false req = Net::HTTP::Get.new(uri.request_uri, initheader = {'Content-Type' =>'application/json', 'Authorization' => "Token #{@token}"}) resp = https.request(req) resp.body end |
#update_attribute(contact_code, name, value, type) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/libring/api.rb', line 70 def update_attribute(contact_code, name, value, type) require "net/https" require "uri" require "json" uri = URI.parse("http://api-clv.libring.com/v2/contact/put") https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = false req = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' =>'application/json', 'Authorization' => "Token #{@token}"}) req.set_form_data({libring: { "#{contact_code}"=> { "#{name}" => { value: "#{value}", type: "#{type}" } }}.to_json }) resp = https.request(req) if resp.body == "OK" { success: true } else { error: resp.body, success: false } end end |