class Totango::Client
Attributes
account[RW]
Public Class Methods
create(args)
click to toggle source
# File lib/totango-api/client.rb, line 62 def self.create(args) event = Client.new(args) event.save return event end
new(hash={})
click to toggle source
# File lib/totango-api/client.rb, line 19 def initialize(hash={}) @sid = hash[:sid] || hash["sid"] || nil load_sid_from_file if @sid == nil raise Totango::Error::NoSID, "No SID provided" unless @sid @user_attributes = hash[:user] || hash["user"] || {} @account_attributes = hash[:account] || hash["account"] || {} @attributes = {} @attributes["sdr_s"] = @sid @attributes["sdr_a"] = hash[:action] || hash["action"] @attributes["sdr_m"] = hash[:module] || hash["module"] @account = Totango::Account.new(@account_attributes) @user = Totango::User.new(@user_attributes) @api = Faraday.new(url: "https://sdr.totango.com/") do |faraday| faraday.response :logger # log requests to STDOUT faraday.adapter Faraday.default_adapter # make requests with Net::HTTP end end
Public Instance Methods
attributes()
click to toggle source
# File lib/totango-api/client.rb, line 38 def attributes @attributes.merge(@user.attributes).merge(@account.attributes) end
save()
click to toggle source
# File lib/totango-api/client.rb, line 42 def save if valid? then begin Timeout.timeout(Totango.timeout) { @api.get '/pixel.gif/', self.attributes } rescue Timeout::Error Totango.error_proc.call("Timed out getting data from Totango.") unless Totango.error_proc == nil rescue Exception => e Totango.error_proc.call("Totango API error #{e.message}") unless Totango.error_proc == nil end else raise Totango::Error::InvalidEvent end end
valid?()
click to toggle source
# File lib/totango-api/client.rb, line 56 def valid? return false if @account.id == nil return false if @user.attributes.keys.grep(/sdr_u\./).count > 0 and @user.attributes["sdr_u"] == nil return true end
Private Instance Methods
load_sid_from_file()
click to toggle source
# File lib/totango-api/client.rb, line 70 def load_sid_from_file if File.exist?("./config/totango.yml") @sid = YAML.load_file("./config/totango.yml")["sid"] end return nil end