natero 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/natero.rb +8 -11
- data/lib/natero/account.rb +7 -3
- data/lib/natero/event.rb +106 -0
- data/lib/natero/serializable.rb +4 -0
- data/lib/natero/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 396f35850e555410d1c47b49834076e468cb59e1
|
4
|
+
data.tar.gz: 5a8b869c6b8201089924184cacabd40ca16ea10b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e05aeab33aa8d0f9c03ba3b19e762b6c8929358a5263ac01831072c346e0cd05146f4298d4dc2d04ce260deeff2a2922dcf5352d39f9bdf0fd087d6410311c5f
|
7
|
+
data.tar.gz: b41c24bb70354f386277f1b76df2e209e5dc1c3e9fc9297e08b2e2ff48faceeeb1651f6c342a54569e6cdaccec26bcbd5d3a9b104437b38482132d86b2b38d01
|
data/Gemfile.lock
CHANGED
data/lib/natero.rb
CHANGED
@@ -3,15 +3,10 @@ require 'json'
|
|
3
3
|
require 'pry'
|
4
4
|
|
5
5
|
module Natero
|
6
|
-
PRODUCTION_URI = 'https://api.natero.com'
|
7
|
-
|
8
|
-
API_VERSION_URI = '/api/v2'
|
9
|
-
|
10
6
|
class Configuration
|
11
7
|
attr_accessor :base_uri, :account_api_key, :event_api_key, :event_auth_key
|
12
8
|
|
13
9
|
def initialize
|
14
|
-
self.base_uri = PRODUCTION_URI
|
15
10
|
self.account_api_key = nil
|
16
11
|
self.event_api_key = nil
|
17
12
|
self.event_auth_key = nil
|
@@ -26,16 +21,17 @@ module Natero
|
|
26
21
|
yield(configuration) if block_given?
|
27
22
|
end
|
28
23
|
|
29
|
-
def self.full_endpoint_uri(
|
30
|
-
base = self.uri
|
24
|
+
def self.full_endpoint_uri(base_uri, version_uri, *params)
|
25
|
+
base = self.uri(base_uri, version_uri)
|
31
26
|
|
32
|
-
params.
|
27
|
+
params.flatten!
|
28
|
+
params.each { |param| base << '/' + param } unless params.empty?
|
33
29
|
|
34
|
-
base
|
30
|
+
base
|
35
31
|
end
|
36
32
|
|
37
|
-
def self.uri
|
38
|
-
|
33
|
+
def self.uri(base_uri, version_uri)
|
34
|
+
base_uri + version_uri
|
39
35
|
end
|
40
36
|
|
41
37
|
def self.api_key_uri
|
@@ -49,4 +45,5 @@ end
|
|
49
45
|
|
50
46
|
require_relative 'natero/serializable'
|
51
47
|
require_relative 'natero/account'
|
48
|
+
require_relative 'natero/event'
|
52
49
|
require_relative 'natero/response'
|
data/lib/natero/account.rb
CHANGED
@@ -2,6 +2,9 @@ class Natero::Account
|
|
2
2
|
include HTTParty
|
3
3
|
include Serializable
|
4
4
|
|
5
|
+
BASE_URI = 'https://api.natero.com'
|
6
|
+
VERSION_URI = '/api/v2'
|
7
|
+
|
5
8
|
attr_reader :account_id, :name, :join_date, :renewal_date,
|
6
9
|
:billing_account_id, :support_account_id, :crm_account_id,
|
7
10
|
:billing_street, :billing_city, :billing_postal_code,
|
@@ -24,13 +27,13 @@ class Natero::Account
|
|
24
27
|
# http://apidocs.natero.com/apidoc.html#Accounts_Bulk%20insert%2Fmodify%20accounts
|
25
28
|
def self.bulk_insert_modify(accounts)
|
26
29
|
body = Natero.to_records_json(accounts)
|
27
|
-
Natero::Response.new(post(endpoint, { :body => body }))
|
30
|
+
Natero::Response.new(post(endpoint, { :body => body, :headers => { 'Content-Type' => 'application/json' } }))
|
28
31
|
end
|
29
32
|
|
30
33
|
# http://apidocs.natero.com/apidoc.html#Accounts_Modify%20an%20account
|
31
34
|
def self.modify(id, account)
|
32
35
|
body = account.to_json
|
33
|
-
Natero::Response.new(put(endpoint(id), { :body => body }))
|
36
|
+
Natero::Response.new(put(endpoint(id), { :body => body, :headers => { 'Content-Type' => 'application/json'} }))
|
34
37
|
end
|
35
38
|
|
36
39
|
# http://apidocs.natero.com/apidoc.html#Accounts_Retrieve%20custom%20metrics
|
@@ -94,7 +97,8 @@ class Natero::Account
|
|
94
97
|
end
|
95
98
|
|
96
99
|
def self.endpoint(*params)
|
97
|
-
|
100
|
+
params = ['accounts'] + params + [Natero.api_key_uri]
|
101
|
+
Natero.full_endpoint_uri(BASE_URI, VERSION_URI, params)
|
98
102
|
end
|
99
103
|
|
100
104
|
def initialize(params, raw_response = nil)
|
data/lib/natero/event.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
class Natero::Event
|
2
|
+
include HTTParty
|
3
|
+
include Serializable
|
4
|
+
|
5
|
+
BASE_URI = 'https://events.natero.com'
|
6
|
+
VERSION_URI = '/v1'
|
7
|
+
|
8
|
+
attr_reader :account_id, :user_id, :created_at, :session_id, :raw_response
|
9
|
+
|
10
|
+
##############################################
|
11
|
+
### Documentation for all endpoints ###
|
12
|
+
### http://apidocs.natero.com/restapi.html ###
|
13
|
+
##############################################
|
14
|
+
|
15
|
+
REQUIRED_PARAMS = %w{
|
16
|
+
account_id
|
17
|
+
user_id
|
18
|
+
created_at
|
19
|
+
session_id
|
20
|
+
}
|
21
|
+
|
22
|
+
private_class_method def self.post_event(body)
|
23
|
+
Natero::Response.new(post(endpoint, { :body => body.to_json, :headers => { 'Content-Type' => 'application/json' } }))
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.identify_user(event, details)
|
27
|
+
action = 'identifyUser'
|
28
|
+
|
29
|
+
body = event.to_h
|
30
|
+
body.merge!({ 'action' => action })
|
31
|
+
body.merge!({ 'details' => details })
|
32
|
+
|
33
|
+
post_event(body)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.identify_account(event, details)
|
37
|
+
action = 'identifyAccount'
|
38
|
+
|
39
|
+
body = event.to_h
|
40
|
+
body.merge!({ 'action' => action })
|
41
|
+
body.merge!({ 'details' => details })
|
42
|
+
|
43
|
+
post_event(body)
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.session_sync(event, active_duration)
|
47
|
+
action = 'sessionSync'
|
48
|
+
|
49
|
+
body = event.to_h
|
50
|
+
body.merge!({ 'action' => action })
|
51
|
+
body.merge!({ 'active_duration' => active_duration })
|
52
|
+
|
53
|
+
post_event(body)
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.module_end(event, module_name, time_spent)
|
57
|
+
action = 'moduleEnd'
|
58
|
+
|
59
|
+
body = event.to_h
|
60
|
+
body.merge!({ 'action' => action })
|
61
|
+
body.merge!({ 'module' => module_name })
|
62
|
+
body.merge!({ 'time_spent' => time_spent })
|
63
|
+
|
64
|
+
post_event(body)
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.feature(event, feature, module_name, total)
|
68
|
+
action = 'feature'
|
69
|
+
|
70
|
+
body = event.to_h
|
71
|
+
body.merge!({ 'action' => action })
|
72
|
+
body.merge!({ 'feature' => feature })
|
73
|
+
body.merge!({ 'module' => module_name })
|
74
|
+
body.merge!({ 'total' => total })
|
75
|
+
|
76
|
+
post_event(body)
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.endpoint
|
80
|
+
Natero.full_endpoint_uri(
|
81
|
+
BASE_URI,
|
82
|
+
VERSION_URI,
|
83
|
+
Natero.configuration.event_auth_key,
|
84
|
+
Natero.configuration.event_api_key
|
85
|
+
)
|
86
|
+
end
|
87
|
+
|
88
|
+
def initialize(params, raw_response = nil)
|
89
|
+
missing = REQUIRED_PARAMS - params.keys
|
90
|
+
|
91
|
+
unless missing.empty?
|
92
|
+
raise ArgumentError.new("Missing required params #{missing.join(', ')}")
|
93
|
+
end
|
94
|
+
|
95
|
+
# Base properties - required
|
96
|
+
@account_id = params['account_id']
|
97
|
+
@user_id = params['user_id']
|
98
|
+
@created_at = params['created_at']
|
99
|
+
@session_id = params['session_id']
|
100
|
+
@raw_response = raw_response
|
101
|
+
end
|
102
|
+
|
103
|
+
def to_json
|
104
|
+
serialize
|
105
|
+
end
|
106
|
+
end
|
data/lib/natero/serializable.rb
CHANGED
data/lib/natero/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: natero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Brown
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- bin/setup
|
85
85
|
- lib/natero.rb
|
86
86
|
- lib/natero/account.rb
|
87
|
+
- lib/natero/event.rb
|
87
88
|
- lib/natero/response.rb
|
88
89
|
- lib/natero/serializable.rb
|
89
90
|
- lib/natero/version.rb
|