Class: Autopilothq
- Inherits:
-
Object
- Object
- Autopilothq
- Defined in:
- lib/autopilothq.rb
Class Method Summary collapse
- .api_key=(key) ⇒ Object
- .get_key_name(name, value) ⇒ Object
- .headers ⇒ Object
- .update_contact(email, custom_attrs) ⇒ Object
Class Method Details
.api_key=(key) ⇒ Object
6 7 8 |
# File 'lib/autopilothq.rb', line 6 def self.api_key=(key) @@api_key = key end |
.get_key_name(name, value) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/autopilothq.rb', line 36 def self.get_key_name(name, value) type = {"Float" => "float", "Fixnum" => "integer", "String" => "string", "TrueClass" => "boolean", "FalseClass" => "boolean", "Date" => "date"} return "#{type[value.class.to_s]}--#{name.gsub(/\s+/, "--")}" end |
.headers ⇒ Object
30 31 32 33 34 |
# File 'lib/autopilothq.rb', line 30 def self.headers return { :autopilotapikey => @@api_key, } end |
.update_contact(email, custom_attrs) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/autopilothq.rb', line 10 def self.update_contact(email, custom_attrs) if @@api_key.present? attributes = { "contact" => { "Email" => email, "custom" => {} } } custom_attrs.each_pair{ |key, value| attributes['contact']['custom'][get_key_name(key, value)] = value } response = RestClient.post 'https://api2.autopilothq.com/v1/contact', attributes.to_json, headers end return true rescue RestClient::RequestFailed => e return false end |