gosquared 0.1.5 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/Gemfile +4 -10
- data/LICENSE +21 -0
- data/README.md +138 -48
- data/lib/gosquared.rb +34 -47
- data/lib/gosquared/account.rb +79 -0
- data/lib/gosquared/client.rb +68 -0
- data/lib/gosquared/now.rb +50 -0
- data/lib/gosquared/people.rb +54 -0
- data/lib/gosquared/tracking.rb +29 -0
- data/lib/gosquared/trends.rb +44 -0
- data/spec/account_spec.rb +67 -0
- data/spec/client_spec.rb +71 -0
- data/spec/now_spec.rb +32 -0
- data/spec/people_spec.rb +51 -0
- data/spec/spec_helper.rb +105 -0
- data/spec/tracking_spec.rb +21 -0
- data/spec/trends_spec.rb +37 -0
- metadata +45 -67
- data/Rakefile +0 -14
- data/gosquared.gemspec +0 -28
- data/lib/client.rb +0 -58
- data/test/api.rb +0 -17
- data/test/event.rb +0 -19
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 51c2a6717a8db7d61b602c4f51dda78e7328ce59
|
4
|
+
data.tar.gz: c723eb2426af2869ee78dfb14d680cba1210bb8e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 704d1fac4d900e0c188fb816cbdeb34bce2075864fcf3c52deaedf103dd9b0d248ba90eac2cff5ca131bae7cb424dc0de9577a37f0627d1d49d68cde8e3f14c0
|
7
|
+
data.tar.gz: f380d51a645dc84095895e9594fdd58e9fcd116faa60e12c904867524590c94f786d7da6f5a9eea2965fe965319f3224b8183bcd0a69234ae44a074685178fd4
|
data/.rspec
ADDED
data/Gemfile
CHANGED
@@ -1,14 +1,8 @@
|
|
1
|
-
ruby '1.9.3'
|
2
1
|
source 'https://rubygems.org'
|
3
2
|
|
4
|
-
|
5
|
-
gem 'json', '~> 1.7'
|
3
|
+
ruby '2.2.2'
|
6
4
|
|
7
|
-
group :development do
|
8
|
-
gem '
|
5
|
+
group :development, :test do
|
6
|
+
gem 'rspec'
|
7
|
+
gem 'webmock'
|
9
8
|
end
|
10
|
-
|
11
|
-
group :test do
|
12
|
-
gem 'guard-minitest', '~> 0.5'
|
13
|
-
gem 'minitest', '~> 3.4'
|
14
|
-
end
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015-2016 Go Squared Ltd.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,75 +1,165 @@
|
|
1
|
-
## GoSquared Ruby
|
1
|
+
## GoSquared Ruby Gem
|
2
2
|
|
3
|
-
|
3
|
+
[](https://travis-ci.org/gosquared/ruby-gem)
|
4
|
+
|
5
|
+
**This is an early beta, please open an issue if you find anything not working, or to leave feedback for improvement. You can also get in touch directly: russell@gosquared.com**
|
6
|
+
|
7
|
+
This gems works with the [GoSquared API](https://www.gosquared.com/docs/api/), making it simple to integrate GoSquared with your Rails app. You can use it for both fetching metrics from your GoSquared account and also posting new events and contacts.
|
8
|
+
|
9
|
+
All functions listed in the API documentation are methods you can call on the GoSquared class.
|
10
|
+
|
11
|
+
#Installation
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem install gosquared
|
15
|
+
```
|
16
|
+
|
17
|
+
#Tracking API
|
18
|
+
This is for sending data to GoSquared. It allows you to track:
|
19
|
+
* Events
|
20
|
+
* Transactions
|
21
|
+
* People profiles
|
22
|
+
|
23
|
+
##Track Events
|
24
|
+
```ruby
|
25
|
+
|
26
|
+
gs = GoSquared.new("your_API_key","your_project_token")
|
27
|
+
|
28
|
+
gs.tracking.event({event: {name: 'event'}})
|
29
|
+
|
30
|
+
#builds the url to the 'GoSquared Tracking' endpoint with the "events" dimension and an event to add to the events list
|
31
|
+
|
32
|
+
gs.tracking.post
|
33
|
+
|
34
|
+
#posts the data to the 'GoSquared Tracking' endpoint
|
35
|
+
|
36
|
+
Reponse Message: OK
|
37
|
+
=> #<Net::HTTPOK 200 OK readbody=true>
|
4
38
|
|
5
|
-
## Installation
|
6
|
-
```bash
|
7
|
-
gem install gosquared
|
8
39
|
```
|
9
40
|
|
10
|
-
##
|
41
|
+
##Track Transactions
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
gs = GoSquared.new("your_API_key","your_project_token")
|
45
|
+
|
46
|
+
gs.tracking.transaction({ transaction: {id: "1", revenue: 50, quantity: 1, previous_transaction_timestamp: Time.new } })
|
11
47
|
|
48
|
+
gs.tracking.post
|
49
|
+
|
50
|
+
Reponse Message: OK
|
51
|
+
=> #<Net::HTTPOK 200 OK readbody=true>
|
52
|
+
```
|
53
|
+
|
54
|
+
##Track People
|
12
55
|
```ruby
|
13
|
-
|
14
|
-
|
56
|
+
gs = GoSquared.new("your_API_key","your_project_token")
|
57
|
+
|
58
|
+
gs.tracking.identify({person_id:"email:example_email@example.com", properties: {first_name: 'Example', last_name: "User", created_at: Time.new, custom: {any: "properties", you: "would_like" } })
|
15
59
|
|
16
|
-
|
17
|
-
gosquared_event = GoSquared::Event.new(opts)
|
60
|
+
gs.tracking.post
|
18
61
|
|
62
|
+
Reponse Message: OK
|
63
|
+
=> #<Net::HTTPOK 200 OK readbody=true>
|
19
64
|
```
|
20
65
|
|
21
|
-
##### Options
|
22
66
|
|
23
|
-
|
24
|
-
|
25
|
-
*
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
67
|
+
#Reporting API
|
68
|
+
This is for pulling data from your GoSquared account. It is split into 3 sections;
|
69
|
+
* Now - realtime data
|
70
|
+
* Trends – historical data (includes ecommerce)
|
71
|
+
* People - user data
|
72
|
+
* Account - administration
|
73
|
+
|
74
|
+
##Now
|
75
|
+
The Now API provides real-time concurrent information about your sites and apps, such as the number of concurrent visitors online, the most popular pages right now, the most influential traffic sources, and much more.
|
76
|
+
|
77
|
+
_Now Example:_
|
31
78
|
|
32
|
-
### API
|
33
79
|
```ruby
|
34
|
-
|
80
|
+
gs = GoSquared.new("your_API_key","your_project_token")
|
81
|
+
|
82
|
+
#instantiates new GoSquared object
|
83
|
+
|
84
|
+
gs.now.concurrents
|
35
85
|
|
36
|
-
|
37
|
-
:api_key => 'demo',
|
38
|
-
:site_token => 'GSN-181546-E'
|
39
|
-
})
|
86
|
+
#builds the url to the 'GoSquared Now' endpoint with the "Concurrents dimension"
|
40
87
|
|
41
|
-
|
88
|
+
gs.now.fetch
|
89
|
+
|
90
|
+
#fetches the data from the 'GoSquared Now' endpoint
|
91
|
+
|
92
|
+
=> {"visitors"=>3, "returning"=>1, "pages"=>0, "active"=>0, "tagged"=>0}
|
42
93
|
```
|
43
94
|
|
44
|
-
|
95
|
+
##Trends
|
96
|
+
The Trends API provides historical analytics information for any given period in a project's history. The data for the current period updates in real-time, so the figures are always fresh and up-to-date.
|
97
|
+
|
98
|
+
_Trends Example:_
|
45
99
|
|
100
|
+
```ruby
|
101
|
+
gs = GoSquared.new("your_API_key","your_project_token")
|
102
|
+
|
103
|
+
gs.trends.browser.from('2016-06-30').to('2016-07-07')
|
104
|
+
|
105
|
+
#builds the url to the 'GoSquared Trends' endpoint with the "Trends dimension" and date filters
|
106
|
+
|
107
|
+
gs.trends.fetch
|
108
|
+
|
109
|
+
#fetches the filtered data from the 'GoSquared Trends' endpoint
|
110
|
+
|
111
|
+
=> {"list"=>[{"id"=>"chrome", "browser"=>"chrome", "name"=>"Chrome", "metrics"=>{"visits"=>3}}], "cardinality"=>1, "dimension"=>"browser", "range"=>{"from"=>"2016-06-30T00:00:00+01:00", "to"=>"2016-07-07T23:59:59+01:00"}, "interval"=>"day"}
|
112
|
+
|
113
|
+
```
|
46
114
|
|
47
|
-
|
115
|
+
##People
|
48
116
|
|
49
|
-
##### Events
|
50
|
-
Send events to GoSquared:
|
51
117
|
|
52
118
|
```ruby
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
})
|
119
|
+
|
120
|
+
gs = GoSquared.new("your_API_key","your_project_token")
|
121
|
+
|
122
|
+
gs.people.smartgroups
|
123
|
+
|
124
|
+
#builds the url to the 'GoSquared People' endpoint with the "people" dimension.
|
125
|
+
|
126
|
+
gs.people.fetch
|
127
|
+
|
128
|
+
#fetches all smartgroups associated with the account.
|
129
|
+
|
65
130
|
```
|
66
131
|
|
67
|
-
##
|
68
|
-
|
132
|
+
##Account
|
133
|
+
The Account API allows you to perform administrative actions against GoSquared accounts. This includes actions like changing settings, configuration, and listing resources under the account.
|
134
|
+
|
135
|
+
_Account Example:_
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
|
139
|
+
gs = GoSquared.new("your_API_key","your_project_token")
|
140
|
+
|
141
|
+
gs.account.blocked.ips.ip('5.10.148.50')
|
142
|
+
|
143
|
+
#builds the url to the 'GoSquared Account' endpoint with the "Blocked dimension" and ip address to add to the blocked list
|
144
|
+
|
145
|
+
gs.account.post
|
146
|
+
|
147
|
+
#posts the data to the 'GoSquared Account' endpoint
|
148
|
+
|
149
|
+
Reponse Message: OK
|
150
|
+
=> #<Net::HTTPOK 200 OK readbody=true>
|
151
|
+
|
152
|
+
gs.sites.token("you_site_token")
|
153
|
+
|
154
|
+
#builds the url to the 'GoSquared Account' endpoint with the "Sites" dimension and token you want to retrieve the site by.
|
155
|
+
|
156
|
+
gs.sites.fetch
|
69
157
|
|
70
|
-
```bash
|
71
|
-
rake
|
72
158
|
```
|
73
159
|
|
74
|
-
|
75
|
-
|
160
|
+
|
161
|
+
#Tests
|
162
|
+
|
163
|
+
```ruby
|
164
|
+
rspec
|
165
|
+
```
|
data/lib/gosquared.rb
CHANGED
@@ -1,47 +1,34 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
def store_event(name, params={})
|
37
|
-
debug 4, GoSquared::DEBUG_LEVELS[:WARNING] if name.nil?
|
38
|
-
|
39
|
-
params = JSON.generate(params)
|
40
|
-
query_params = {
|
41
|
-
:_name => name
|
42
|
-
}
|
43
|
-
post('/event', query_params, params)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
1
|
+
require './lib/gosquared/trends'
|
2
|
+
require './lib/gosquared/tracking'
|
3
|
+
require './lib/gosquared/people'
|
4
|
+
require './lib/gosquared/now'
|
5
|
+
require './lib/gosquared/account'
|
6
|
+
|
7
|
+
class GoSquared
|
8
|
+
|
9
|
+
def initialize api_key, site_id
|
10
|
+
@api_key = api_key
|
11
|
+
@site_id = site_id
|
12
|
+
end
|
13
|
+
|
14
|
+
def trends
|
15
|
+
@trends ||= Trends.new(@api_key, @site_id)
|
16
|
+
end
|
17
|
+
|
18
|
+
def tracking
|
19
|
+
@tracking ||= Tracking.new(@api_key, @site_id)
|
20
|
+
end
|
21
|
+
|
22
|
+
def people
|
23
|
+
@people ||= People.new(@api_key, @site_id)
|
24
|
+
end
|
25
|
+
|
26
|
+
def now
|
27
|
+
@now ||= Now.new(@api_key, @site_id)
|
28
|
+
end
|
29
|
+
|
30
|
+
def account
|
31
|
+
@account ||= Account.new(@api_key, @site_id)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require './lib/gosquared/client'
|
2
|
+
|
3
|
+
class Account
|
4
|
+
|
5
|
+
BASEURL = "https://api.gosquared.com/account/v1/"
|
6
|
+
DIMENSIONS = %w(blocked feeds reportPreferences sharedUsers sites taggedVisitors triggerTypes webhooks)
|
7
|
+
DIMENSION_FILTER = %w(token webhookID visitorID triggerType)
|
8
|
+
@@filters = {presenter: @presenter, ip: @ip, url: @url, email: @email}
|
9
|
+
|
10
|
+
def initialize(api_key, site_token, client = Client.new)
|
11
|
+
@site_token = site_token
|
12
|
+
@api_key = api_key
|
13
|
+
@client = client
|
14
|
+
@bots= ""
|
15
|
+
@ips = ""
|
16
|
+
@visitor = ""
|
17
|
+
@dimension_filter = ""
|
18
|
+
end
|
19
|
+
|
20
|
+
DIMENSION_FILTER.each do |filter|
|
21
|
+
define_method filter do |parameter = ""|
|
22
|
+
@dimension_filter = "/" + parameter
|
23
|
+
self
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
DIMENSIONS.each do |dimension|
|
28
|
+
define_method dimension do |options = ""|
|
29
|
+
@dimension = dimension
|
30
|
+
@data = options
|
31
|
+
self
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
@@filters.each do |key, value|
|
36
|
+
define_method key do |argument|
|
37
|
+
@@filters[key] = argument
|
38
|
+
self
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def fetch
|
43
|
+
data = @client.get(url)
|
44
|
+
@@filters.each{|key, value| @@filters[key]=nil} if data
|
45
|
+
data
|
46
|
+
end
|
47
|
+
|
48
|
+
def post
|
49
|
+
@client.post(url, @data)
|
50
|
+
end
|
51
|
+
|
52
|
+
def delete
|
53
|
+
@client.delete(url, @data)
|
54
|
+
end
|
55
|
+
|
56
|
+
def bots
|
57
|
+
@bots = "/bots"
|
58
|
+
end
|
59
|
+
|
60
|
+
def ips
|
61
|
+
@ips = "/ips"
|
62
|
+
self
|
63
|
+
end
|
64
|
+
|
65
|
+
def visitors(id="")
|
66
|
+
@visitor = "/visitors/#{id}"
|
67
|
+
self
|
68
|
+
end
|
69
|
+
|
70
|
+
def url(ips = @ips)
|
71
|
+
array = [""]
|
72
|
+
@url = BASEURL + @dimension + @dimension_filter + @visitor + @bots + ips +
|
73
|
+
"?api_key=#{@api_key}" + "&site_token=#{@site_token}"
|
74
|
+
@@filters.each {|key, value| array << "#{key}=#{value}" if value }
|
75
|
+
parameters=array.join('&')
|
76
|
+
@url = @url.concat(parameters)
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
class Client
|
6
|
+
|
7
|
+
def get(url)
|
8
|
+
uri = URI(url)
|
9
|
+
begin
|
10
|
+
response = Net::HTTP.get(uri)
|
11
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
|
12
|
+
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
|
13
|
+
puts "[error] HTTP error: #{e}"
|
14
|
+
begin
|
15
|
+
JSON.parse(response)
|
16
|
+
rescue StandardError => e
|
17
|
+
puts "[error] StandardError: Could not parse JSON"
|
18
|
+
response = false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
@data = JSON.parse(response) if response
|
22
|
+
end
|
23
|
+
|
24
|
+
def post(url,data)
|
25
|
+
uri = URI.parse(url)
|
26
|
+
begin
|
27
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
28
|
+
https.use_ssl = true
|
29
|
+
request = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' =>'application/json'})
|
30
|
+
request.body = "[ #{data.to_json} ]"
|
31
|
+
response = https.request(request)
|
32
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
|
33
|
+
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
|
34
|
+
puts "[error] HTTP error: #{e}"
|
35
|
+
begin
|
36
|
+
response.message
|
37
|
+
rescue StandardError => e
|
38
|
+
puts "[error] StandardError: Could not print response message"
|
39
|
+
response = false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
puts "Reponse Message: #{response.message}" if response
|
43
|
+
response
|
44
|
+
end
|
45
|
+
|
46
|
+
def delete(url,data)
|
47
|
+
uri = URI.parse(url)
|
48
|
+
begin
|
49
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
50
|
+
https.use_ssl = true
|
51
|
+
request = Net::HTTP::Delete.new(uri.request_uri, initheader = {'Content-Type' =>'application/json'})
|
52
|
+
request.body = "[ #{data.to_json} ]"
|
53
|
+
response = https.request(request)
|
54
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
|
55
|
+
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
|
56
|
+
puts "[error] HTTP error: #{e}"
|
57
|
+
begin
|
58
|
+
response.message
|
59
|
+
rescue StandardError => e
|
60
|
+
puts "[error] StandardError: Could not print response message"
|
61
|
+
response = false
|
62
|
+
end
|
63
|
+
end
|
64
|
+
puts "Reponse Message: #{response.message}" if response
|
65
|
+
response
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|