totango-api 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/totango-api.rb +12 -0
- data/lib/totango-api/account.rb +108 -0
- data/lib/totango-api/client.rb +79 -0
- data/lib/totango-api/user.rb +35 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 319205dcbe9eaa0bfbde43428407749ad5f0ddde
|
4
|
+
data.tar.gz: 4cd490393e07c57f0b4b7a10b08ebe8ffa51e82b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 02ec7e07b79994109acc525ca4a156f7f4741f98ada1598a3bb7f9de818d3474cf047635744bc301514791a2bd8f67cb4f26db25d6c7588ead596fdb18109edc
|
7
|
+
data.tar.gz: 67baf4dae9d081ae520ed92bcb3889ddc5e8632e64ed5e5506ea38c9babbcc7ca5a488fa3d53539ba50b621595c1115baacd208b6b2834867803a14f35151a8e
|
data/lib/totango-api.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
module Totango
|
2
|
+
class Account
|
3
|
+
|
4
|
+
def initialize(args = {})
|
5
|
+
@attributes = Hash.new(nil)
|
6
|
+
args.each {|k,v| self.send("#{k}=".to_sym,v)}
|
7
|
+
end
|
8
|
+
|
9
|
+
def id
|
10
|
+
@attributes["sdr_o"]
|
11
|
+
end
|
12
|
+
def id=(id)
|
13
|
+
@attributes["sdr_o"] = id
|
14
|
+
end
|
15
|
+
|
16
|
+
def ofid
|
17
|
+
@attributes["sdr_ofid"]
|
18
|
+
end
|
19
|
+
def ofid=(ofid)
|
20
|
+
@attributes["sdr_ofid"]=ofid
|
21
|
+
end
|
22
|
+
|
23
|
+
def account_name
|
24
|
+
@attributes["sdr_odn"]
|
25
|
+
end
|
26
|
+
def account_name=(name)
|
27
|
+
@attributes["sdr_odn"]=name
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_date
|
31
|
+
@attributes["sdr_o_Create Date"]
|
32
|
+
end
|
33
|
+
def create_date=(date)
|
34
|
+
@attributes["sdr_o_Create Date"] = to_xmlschema(date)
|
35
|
+
end
|
36
|
+
|
37
|
+
def contract_renewal
|
38
|
+
@attributes["sdr_o_Contract Renewal Date"]
|
39
|
+
end
|
40
|
+
def contract_renewal=(date)
|
41
|
+
@attributes["sdr_o_Contract Renewal Date"] = to_xmlschema(date)
|
42
|
+
end
|
43
|
+
|
44
|
+
def contract_value
|
45
|
+
@attributes["sdr_o_Contract Value"]
|
46
|
+
end
|
47
|
+
def contract_value=(n)
|
48
|
+
@attributes["sdr_o_Contract value"] = n.to_i
|
49
|
+
end
|
50
|
+
|
51
|
+
def licenses
|
52
|
+
@attributes["sdr_o_Licenses"]
|
53
|
+
end
|
54
|
+
def licenses=(n)
|
55
|
+
@attributes["sdr_o_Licenses"] = n.to_i
|
56
|
+
end
|
57
|
+
|
58
|
+
def sales_manager
|
59
|
+
@attributes["sdr_o_Sales Manager"]
|
60
|
+
end
|
61
|
+
def sales_manager=(s)
|
62
|
+
@attributes["sdr_o_Sales Manager"]=s
|
63
|
+
end
|
64
|
+
|
65
|
+
def success_manager
|
66
|
+
@attributes["sdr_o_Success Manager"]
|
67
|
+
end
|
68
|
+
def success_manager=(s)
|
69
|
+
@attributes["sdr_o_Sucsess Manager"]=s
|
70
|
+
end
|
71
|
+
|
72
|
+
def status
|
73
|
+
@attributes["sdr_o_Status"]
|
74
|
+
end
|
75
|
+
def status=(s)
|
76
|
+
@attributes["sdr_o_Status"]=s
|
77
|
+
end
|
78
|
+
|
79
|
+
def attributes
|
80
|
+
@attributes.delete_if {|k,v| v.nil? }
|
81
|
+
end
|
82
|
+
|
83
|
+
def method_missing(s,*args)
|
84
|
+
m=s.to_s.sub(/=$/,"")
|
85
|
+
attr_name = "sdr_o.#{m}"
|
86
|
+
return @attributes[attr_name] = "#{args.join(" ")}" if args.length > 0
|
87
|
+
raise NoMethodError, "#{s.to_s} for #{self.class}" unless @attributes[attr_name]
|
88
|
+
return @attributes[attr_name]
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def to_xmlschema(date)
|
94
|
+
xml_date = case date.class.to_s
|
95
|
+
when String
|
96
|
+
DateTime.parse(date)
|
97
|
+
when DateTime
|
98
|
+
date
|
99
|
+
when Time
|
100
|
+
date.to_datetime
|
101
|
+
when Date
|
102
|
+
date.to_datetime
|
103
|
+
end
|
104
|
+
|
105
|
+
return xml_date.xmlschema
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Totango
|
2
|
+
@error_proc = nil
|
3
|
+
@timeout = 10
|
4
|
+
|
5
|
+
def self.timeout; return @timeout; end
|
6
|
+
def self.timeout=(n); return @timeout=n; end
|
7
|
+
|
8
|
+
def self.on_error(&x); @error_proc = x; end
|
9
|
+
def self.error_proc; @error_proc; end
|
10
|
+
|
11
|
+
module Error
|
12
|
+
class InvalidEvent < Exception;end
|
13
|
+
class NoSID < Exception;end
|
14
|
+
class TotangoAPIError < Exception;end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Client
|
18
|
+
attr :account, :user, :sid
|
19
|
+
def initialize(hash={})
|
20
|
+
@sid = hash[:sid] || hash["sid"] || nil
|
21
|
+
load_sid_from_file if @sid == nil
|
22
|
+
raise Totango::Error::NoSID, "No SID provided" unless @sid
|
23
|
+
@user_attributes = hash[:user] || hash["user"] || {}
|
24
|
+
@account_attributes = hash[:account] || hash["account"] || {}
|
25
|
+
@attributes = {}
|
26
|
+
@attributes["sdr_s"] = @sid
|
27
|
+
@attributes["sdr_a"] = hash[:action] || hash["action"]
|
28
|
+
@attributes["sdr_m"] = hash[:module] || hash["module"]
|
29
|
+
@account = Totango::Account.new(@account_attributes)
|
30
|
+
@user = Totango::User.new(@user_attributes)
|
31
|
+
|
32
|
+
@api = Faraday.new(url: "https://sdr.totango.com/") do |faraday|
|
33
|
+
faraday.response :logger # log requests to STDOUT
|
34
|
+
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def attributes
|
39
|
+
@attributes.merge(@user.attributes).merge(@account.attributes)
|
40
|
+
end
|
41
|
+
|
42
|
+
def save
|
43
|
+
if valid? then
|
44
|
+
begin
|
45
|
+
Timeout.timeout(Totango.timeout) { @api.get '/pixel.gif/', self.attributes }
|
46
|
+
rescue Timeout::Error
|
47
|
+
Totango.error_proc.call("Timed out getting data from Totango.") unless Totango.error_proc == nil
|
48
|
+
rescue Exception => e
|
49
|
+
Totango.error_proc.call("Totango API error #{e.message}") unless Totango.error_proc == nil
|
50
|
+
end
|
51
|
+
else
|
52
|
+
raise Totango::Error::InvalidEvent
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def valid?
|
57
|
+
return false if @account.id == nil
|
58
|
+
return false if @user.attributes.keys.grep(/sdr_u\./).count > 0 and @user.attributes["sdr_u"] == nil
|
59
|
+
return true
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.create(args)
|
63
|
+
event = Client.new(args)
|
64
|
+
event.save
|
65
|
+
return event
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def load_sid_from_file
|
71
|
+
if File.exist?("./config/totango.yml")
|
72
|
+
@sid = YAML.load_file("./config/totango.yml")["sid"]
|
73
|
+
end
|
74
|
+
|
75
|
+
return nil
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Totango
|
2
|
+
class User
|
3
|
+
def initialize(args = {})
|
4
|
+
@attributes = Hash.new(nil)
|
5
|
+
args.each {|k,v| self.send("#{k}=".to_sym,v)}
|
6
|
+
end
|
7
|
+
|
8
|
+
def id
|
9
|
+
@attributes["sdr_u"]
|
10
|
+
end
|
11
|
+
def id=(id)
|
12
|
+
@attributes["sdr_u"]=id
|
13
|
+
end
|
14
|
+
|
15
|
+
def name
|
16
|
+
@attributes["sdr_u.name"]
|
17
|
+
end
|
18
|
+
def name=(n)
|
19
|
+
@attributes["sdr_u.name"]=n
|
20
|
+
end
|
21
|
+
|
22
|
+
def method_missing(s,*args)
|
23
|
+
m=s.to_s.sub(/=$/,"")
|
24
|
+
attr_name = "sdr_u.#{m}"
|
25
|
+
return @attributes[attr_name] = "#{args.join(" ")}" if args.length > 0
|
26
|
+
raise NoMethodError, "#{s.to_s} for #{self.class}" unless @attributes[attr_name]
|
27
|
+
return @attributes[attr_name]
|
28
|
+
end
|
29
|
+
|
30
|
+
def attributes
|
31
|
+
@attributes.delete_if {|k,v| v.nil? }
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: totango-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Paterni
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: A ruby wrapper for the totango API
|
28
|
+
email: james@ruby-code.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/totango-api.rb
|
34
|
+
- lib/totango-api/account.rb
|
35
|
+
- lib/totango-api/client.rb
|
36
|
+
- lib/totango-api/user.rb
|
37
|
+
homepage:
|
38
|
+
licenses:
|
39
|
+
- GPL-2.0
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 2.4.5.1
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: Totango-API
|
61
|
+
test_files: []
|