Class: Totango::Client
- Inherits:
-
Object
- Object
- Totango::Client
- Defined in:
- lib/totango-api/client.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Returns the value of attribute account.
-
#sid ⇒ Object
readonly
Returns the value of attribute sid.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
-
#initialize(hash = {}) ⇒ Client
constructor
A new instance of Client.
- #save ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(hash = {}) ⇒ Client
Returns a new instance of Client.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# 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 |
Instance Attribute Details
#account ⇒ Object (readonly)
Returns the value of attribute account.
18 19 20 |
# File 'lib/totango-api/client.rb', line 18 def account @account end |
#sid ⇒ Object (readonly)
Returns the value of attribute sid.
18 19 20 |
# File 'lib/totango-api/client.rb', line 18 def sid @sid end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
18 19 20 |
# File 'lib/totango-api/client.rb', line 18 def user @user end |
Class Method Details
Instance Method Details
#attributes ⇒ Object
38 39 40 |
# File 'lib/totango-api/client.rb', line 38 def attributes @attributes.merge(@user.attributes).merge(@account.attributes) end |
#save ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# 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.}") unless Totango.error_proc == nil end else raise Totango::Error::InvalidEvent end end |
#valid? ⇒ Boolean
56 57 58 59 60 |
# 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 |