gosquared 3.0.1 → 3.0.3
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 +4 -4
- data/README.md +4 -1
- data/lib/gosquared.rb +5 -5
- data/lib/gosquared/account.rb +70 -70
- data/lib/gosquared/client.rb +62 -60
- data/lib/gosquared/now.rb +50 -47
- data/lib/gosquared/people.rb +56 -53
- data/lib/gosquared/tracking.rb +41 -38
- data/lib/gosquared/trends.rb +13 -5
- data/spec/account_spec.rb +14 -14
- data/spec/client_spec.rb +12 -12
- data/spec/now_spec.rb +7 -7
- data/spec/people_spec.rb +5 -5
- data/spec/tracking_spec.rb +3 -3
- data/spec/trends_spec.rb +6 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78358a00b7bf496eef23fa1b7dacbb2f1e1096e1
|
4
|
+
data.tar.gz: dd61d41cf61c67bf9ec5c505335448e792af6c67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38f86d39c694124b9f2e517cb7e12e74dc20c32b91010852da37951957cbd79b04e766029a04fb8319c17b9581b030807d744e1747447e7e6ff7aaa84aa9c4f0
|
7
|
+
data.tar.gz: 868a7cb63f24a03d094c19f87245caa2e749455dfd638c9f8e3caf86284a609c363f1d105b841aa7fe33846290f2cdd745fa965095f1fb667616a57a5be46fb9
|
data/README.md
CHANGED
@@ -4,7 +4,10 @@
|
|
4
4
|
|
5
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
6
|
|
7
|
-
This gems works with the [GoSquared API](https://www.gosquared.com/docs/api/),
|
7
|
+
This gems works with the [GoSquared API](https://www.gosquared.com/docs/api/), You can use it for both fetching metrics from your GoSquared account and also posting new events and contacts.
|
8
|
+
|
9
|
+
Note, if you are looking to set up GoSquared for the first time and install Analytics, People and Live Chat within a Rails app, you can do so by using our [GoSquared-Rails gem]
|
10
|
+
(https://github.com/gosquared/gosquared-rails)
|
8
11
|
|
9
12
|
All functions listed in the API documentation are methods you can call on the GoSquared class.
|
10
13
|
|
data/lib/gosquared.rb
CHANGED
@@ -16,23 +16,23 @@ module Gosquared
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def trends
|
19
|
-
@trends ||= Trends.new(@api_key, @site_id)
|
19
|
+
@trends ||= Gosquared::Trends.new(@api_key, @site_id)
|
20
20
|
end
|
21
21
|
|
22
22
|
def tracking
|
23
|
-
@tracking ||= Tracking.new(@api_key, @site_id)
|
23
|
+
@tracking ||= Gosquared::Tracking.new(@api_key, @site_id)
|
24
24
|
end
|
25
25
|
|
26
26
|
def people
|
27
|
-
@people ||=
|
27
|
+
@people ||= Gosquared::People.new(@api_key, @site_id)
|
28
28
|
end
|
29
29
|
|
30
30
|
def now
|
31
|
-
@now ||= Now.new(@api_key, @site_id)
|
31
|
+
@now ||= Gosquared::Now.new(@api_key, @site_id)
|
32
32
|
end
|
33
33
|
|
34
34
|
def account
|
35
|
-
@account ||= Account.new(@api_key, @site_id)
|
35
|
+
@account ||= Gosquared::Account.new(@api_key, @site_id)
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
data/lib/gosquared/account.rb
CHANGED
@@ -1,83 +1,83 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative 'client'
|
2
2
|
|
3
|
-
|
3
|
+
module Gosquared
|
4
|
+
class Account
|
5
|
+
BASEURL = 'https://api.gosquared.com/account/v1/'.freeze
|
6
|
+
DIMENSIONS = %w(blocked feeds reportPreferences sharedUsers sites taggedVisitors triggerTypes webhooks).freeze
|
7
|
+
DIMENSION_FILTER = %w(token webhookID visitorID triggerType).freeze
|
8
|
+
@@filters = { presenter: @presenter, ip: @ip, url: @url, email: @email }
|
4
9
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
10
|
+
def initialize(api_key, site_token, client = Gosquared::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
|
9
19
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@visitor = ""
|
17
|
-
@dimension_filter = ""
|
18
|
-
end
|
20
|
+
DIMENSION_FILTER.each do |filter|
|
21
|
+
define_method filter do |parameter = ''|
|
22
|
+
@dimension_filter = '/' + parameter
|
23
|
+
self
|
24
|
+
end
|
25
|
+
end
|
19
26
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
27
|
+
DIMENSIONS.each do |dimension|
|
28
|
+
define_method dimension do |options = ''|
|
29
|
+
@dimension = dimension
|
30
|
+
@data = options
|
31
|
+
self
|
32
|
+
end
|
33
|
+
end
|
26
34
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
35
|
+
@@filters.each do |key, _value|
|
36
|
+
define_method key do |argument|
|
37
|
+
@@filters[key] = argument
|
38
|
+
self
|
39
|
+
end
|
40
|
+
end
|
34
41
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
42
|
+
def fetch
|
43
|
+
data = @client.get(build_url)
|
44
|
+
@@filters.each { |key, _value| @@filters[key] = nil } if data
|
45
|
+
data
|
46
|
+
end
|
41
47
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
48
|
+
def post
|
49
|
+
response = @client.post(build_url, @data)
|
50
|
+
@@filters.each { |key, _value| @@filters[key] = nil } if response.code === '200'
|
51
|
+
response
|
52
|
+
end
|
47
53
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
54
|
+
def delete
|
55
|
+
response = @client.post(build_url, @data)
|
56
|
+
@@filters.each { |key, _value| @@filters[key] = nil } if response.code === '200'
|
57
|
+
response
|
58
|
+
end
|
53
59
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
response
|
58
|
-
end
|
60
|
+
def bots
|
61
|
+
@bots = '/bots'
|
62
|
+
end
|
59
63
|
|
60
|
-
|
61
|
-
|
62
|
-
|
64
|
+
def ips
|
65
|
+
@ips = '/ips'
|
66
|
+
self
|
67
|
+
end
|
63
68
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
def visitors(id="")
|
70
|
-
@visitor = "/visitors/#{id}"
|
71
|
-
self
|
72
|
-
end
|
73
|
-
|
74
|
-
def build_url(ips = @ips)
|
75
|
-
array = [""]
|
76
|
-
@url = BASEURL + @dimension + @dimension_filter + @visitor + @bots + ips +
|
77
|
-
"?api_key=#{@api_key}" + "&site_token=#{@site_token}"
|
78
|
-
@@filters.each {|key, value| array << "#{key}=#{value}" if value }
|
79
|
-
parameters=array.join('&')
|
80
|
-
@url = @url.concat(parameters)
|
81
|
-
end
|
69
|
+
def visitors(id = '')
|
70
|
+
@visitor = "/visitors/#{id}"
|
71
|
+
self
|
72
|
+
end
|
82
73
|
|
74
|
+
def build_url(ips = @ips)
|
75
|
+
array = ['']
|
76
|
+
@url = BASEURL + @dimension + @dimension_filter + @visitor + @bots + ips +
|
77
|
+
"?api_key=#{@api_key}" + "&site_token=#{@site_token}"
|
78
|
+
@@filters.each { |key, value| array << "#{key}=#{value}" if value }
|
79
|
+
parameters = array.join('&')
|
80
|
+
@url = @url.concat(parameters)
|
81
|
+
end
|
82
|
+
end
|
83
83
|
end
|
data/lib/gosquared/client.rb
CHANGED
@@ -2,67 +2,69 @@ require 'net/https'
|
|
2
2
|
require 'uri'
|
3
3
|
require 'json'
|
4
4
|
|
5
|
-
|
5
|
+
module Gosquared
|
6
|
+
class Client
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
8
|
+
def get(url)
|
9
|
+
uri = URI(url)
|
10
|
+
begin
|
11
|
+
response = Net::HTTP.get(uri)
|
12
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
|
13
|
+
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
|
14
|
+
puts "[error] HTTP error: #{e}"
|
15
|
+
begin
|
16
|
+
JSON.parse(response)
|
17
|
+
rescue StandardError => e
|
18
|
+
puts "[error] StandardError: Could not parse JSON"
|
19
|
+
response = false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
@data = JSON.parse(response) if response
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
25
|
+
def post(url,data)
|
26
|
+
uri = URI.parse(url)
|
27
|
+
begin
|
28
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
29
|
+
https.use_ssl = true
|
30
|
+
request = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' =>'application/json'})
|
31
|
+
request.body = "[ #{data.to_json} ]"
|
32
|
+
response = https.request(request)
|
33
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
|
34
|
+
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
|
35
|
+
puts "[error] HTTP error: #{e}"
|
36
|
+
begin
|
37
|
+
response.message
|
38
|
+
rescue StandardError => e
|
39
|
+
puts "[error] StandardError: Could not print response message"
|
40
|
+
response = false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
puts "Response Message: #{response.message}" if response
|
44
|
+
response
|
45
|
+
end
|
45
46
|
|
46
|
-
def delete(url,data)
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
47
|
+
def delete(url,data)
|
48
|
+
uri = URI.parse(url)
|
49
|
+
begin
|
50
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
51
|
+
https.use_ssl = true
|
52
|
+
request = Net::HTTP::Delete.new(uri.request_uri, initheader = {'Content-Type' =>'application/json'})
|
53
|
+
request.body = "[ #{data.to_json} ]"
|
54
|
+
response = https.request(request)
|
55
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
|
56
|
+
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
|
57
|
+
puts "[error] HTTP error: #{e}"
|
58
|
+
begin
|
59
|
+
response.message
|
60
|
+
rescue StandardError => e
|
61
|
+
puts "[error] StandardError: Could not print response message"
|
62
|
+
response = false
|
63
|
+
end
|
64
|
+
end
|
65
|
+
puts "Response Message: #{response.message}" if response
|
66
|
+
response
|
67
|
+
end
|
67
68
|
|
68
|
-
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/gosquared/now.rb
CHANGED
@@ -1,50 +1,53 @@
|
|
1
1
|
require_relative "client"
|
2
|
-
class Now
|
3
|
-
|
4
|
-
BASEURL = "https://api.gosquared.com/now/v3/"
|
5
|
-
DIMENSIONS = %w(browsers campaigns concurrents engagement geo languages notifications
|
6
|
-
organisations overview pages platforms sources time timeSeries visitors)
|
7
|
-
@@filters = {dateFormat: @date_format, from: @from, to: @to,
|
8
|
-
format: @format, limit: @limit, sort: @sort,
|
9
|
-
presenter: @presenter, visitors_mode: @string, href: @href,
|
10
|
-
drill_limit: @drill_limit, sections: @sections,
|
11
|
-
minimal: @minimal, interval: @interval}
|
12
|
-
|
13
|
-
def initialize(api_key, site_token, client=Client.new)
|
14
|
-
@site_token = site_token
|
15
|
-
@api_key = api_key
|
16
|
-
@client = client
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
DIMENSIONS.each do |dimension|
|
21
|
-
define_method dimension do
|
22
|
-
@dimension = dimension
|
23
|
-
self
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
@@filters.each do |key, value|
|
28
|
-
define_method key do |argument|
|
29
|
-
@@filters[key] = argument
|
30
|
-
self
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def fetch
|
35
|
-
data = @client.get(url)
|
36
|
-
@@filters.each{|key, value| @@filters[key]=nil} if data
|
37
|
-
data
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def url
|
43
|
-
array = [""]
|
44
|
-
@url = BASEURL + @dimension + "?api_key=#{@api_key}" + "&site_token=#{@site_token}"
|
45
|
-
@@filters.each {|key, value| array << "#{key}=#{value}" if value }
|
46
|
-
parameters=array.join('&')
|
47
|
-
@url = @url.concat(parameters)
|
48
|
-
end
|
49
2
|
|
3
|
+
module Gosquared
|
4
|
+
class Now
|
5
|
+
|
6
|
+
BASEURL = "https://api.gosquared.com/now/v3/".freeze
|
7
|
+
DIMENSIONS = %w(browsers campaigns concurrents engagement geo languages notifications
|
8
|
+
organisations overview pages platforms sources time timeSeries visitors).freeze
|
9
|
+
@@filters = {date_format: @date_format, from: @from, to: @to,
|
10
|
+
format: @format, limit: @limit, sort: @sort,
|
11
|
+
presenter: @presenter, visitors_mode: @string, href: @href,
|
12
|
+
drill_limit: @drill_limit, sections: @sections,
|
13
|
+
minimal: @minimal, interval: @interval}
|
14
|
+
|
15
|
+
def initialize(api_key, site_token, client = Gosquared::Client.new)
|
16
|
+
@site_token = site_token
|
17
|
+
@api_key = api_key
|
18
|
+
@client = client
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
DIMENSIONS.each do |dimension|
|
23
|
+
define_method dimension do
|
24
|
+
@dimension = dimension
|
25
|
+
self
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
@@filters.each do |key, value|
|
30
|
+
define_method key do |argument|
|
31
|
+
@@filters[key] = argument
|
32
|
+
self
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def fetch
|
37
|
+
data = @client.get(url)
|
38
|
+
@@filters.each{|key, value| @@filters[key]=nil} if data
|
39
|
+
data
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def url
|
45
|
+
array = [""]
|
46
|
+
@url = BASEURL + @dimension + "?api_key=#{@api_key}" + "&site_token=#{@site_token}"
|
47
|
+
@@filters.each {|key, value| array << "#{key}=#{value}" if value }
|
48
|
+
parameters=array.join('&')
|
49
|
+
@url = @url.concat(parameters)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
50
53
|
end
|
data/lib/gosquared/people.rb
CHANGED
@@ -1,54 +1,57 @@
|
|
1
1
|
require_relative "client"
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
2
|
+
|
3
|
+
module Gosquared
|
4
|
+
class People
|
5
|
+
|
6
|
+
BASEURL = "https://api.gosquared.com/people/v1/".freeze
|
7
|
+
VERSION = %w(v1 v2 v3).freeze
|
8
|
+
DIMENSIONS = %w(devices eventTypes people propertyTypes feed smartgroups).freeze
|
9
|
+
@@filters = {query: @query, filters: @filters, sort: @sort,
|
10
|
+
format: @presenter, limit: @limit, type: @type, from: @from, to: @to}
|
11
|
+
|
12
|
+
def initialize(api_key, site_token, client = Gosquared::Client.new)
|
13
|
+
@site_token = site_token
|
14
|
+
@api_key = api_key
|
15
|
+
@person_id = ""
|
16
|
+
@person_filter = ""
|
17
|
+
@client = client
|
18
|
+
end
|
19
|
+
|
20
|
+
DIMENSIONS.each do |dimension|
|
21
|
+
define_method dimension do |options = ""|
|
22
|
+
@dimension = dimension
|
23
|
+
@data = options
|
24
|
+
self
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
@@filters.each do |key, value|
|
29
|
+
define_method key do |argument|
|
30
|
+
@@filters[key] = argument
|
31
|
+
self
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def person_id(object, filter)
|
36
|
+
@person_id = "/" + object
|
37
|
+
@person_filter = "/" + filter
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
def fetch
|
42
|
+
data = @client.get(url)
|
43
|
+
@@filters.each{|key, value| @@filters[key]=nil} if data
|
44
|
+
data
|
45
|
+
end
|
46
|
+
|
47
|
+
def url
|
48
|
+
array = [""]
|
49
|
+
url = BASEURL + @dimension + @person_id + @person_filter +
|
50
|
+
"?api_key=#{@api_key}" + "&site_token=#{@site_token}"
|
51
|
+
@@filters.each { |key, value| array << "#{key}=#{value}" if value }
|
52
|
+
parameters=array.join('&')
|
53
|
+
url.concat(parameters)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
data/lib/gosquared/tracking.rb
CHANGED
@@ -1,41 +1,44 @@
|
|
1
1
|
require_relative "client"
|
2
|
-
class Tracking
|
3
|
-
|
4
|
-
BASEURL = "https://api.gosquared.com/tracking/v1/"
|
5
|
-
DIMENSIONS = %w(event identify pageview ping properties timeout transaction)
|
6
|
-
|
7
|
-
def initialize(api_key, site_token, client=Client.new)
|
8
|
-
@site_token = site_token
|
9
|
-
@api_key = api_key
|
10
|
-
@client = client
|
11
|
-
end
|
12
|
-
|
13
|
-
DIMENSIONS.each do |dimension|
|
14
|
-
define_method dimension do |options|
|
15
|
-
@dimension = dimension
|
16
|
-
@data = options
|
17
|
-
self
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def post
|
22
|
-
check_for_nil_user
|
23
|
-
response = @client.post(url, @data)
|
24
|
-
@data = nil if response.code === '200'
|
25
|
-
response
|
26
|
-
end
|
27
|
-
|
28
|
-
def url
|
29
|
-
url = BASEURL + @dimension + "?api_key=#{@api_key}" + "&site_token=#{@site_token}"
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def check_for_nil_user
|
35
|
-
if @data.key?(:person_id) && @data[:person_id] == nil
|
36
|
-
@data.tap { |data| @data.delete(:person_id) }
|
37
|
-
warn 'person_id is nil, event will not be track against a user'
|
38
|
-
end
|
39
|
-
end
|
40
2
|
|
3
|
+
module Gosquared
|
4
|
+
class Tracking
|
5
|
+
|
6
|
+
BASEURL = "https://api.gosquared.com/tracking/v1/".freeze
|
7
|
+
DIMENSIONS = %w(event identify pageview ping properties timeout transaction).freeze
|
8
|
+
|
9
|
+
def initialize(api_key, site_token, client = Gosquared::Client.new)
|
10
|
+
@site_token = site_token
|
11
|
+
@api_key = api_key
|
12
|
+
@client = client
|
13
|
+
end
|
14
|
+
|
15
|
+
DIMENSIONS.each do |dimension|
|
16
|
+
define_method dimension do |options|
|
17
|
+
@dimension = dimension
|
18
|
+
@data = options
|
19
|
+
self
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def post
|
24
|
+
check_for_nil_user
|
25
|
+
response = @client.post(url, @data)
|
26
|
+
@data = nil if response.code === '200'
|
27
|
+
response
|
28
|
+
end
|
29
|
+
|
30
|
+
def url
|
31
|
+
url = BASEURL + @dimension + "?api_key=#{@api_key}" + "&site_token=#{@site_token}"
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def check_for_nil_user
|
37
|
+
if @data.key?(:person_id) && @data[:person_id] == nil
|
38
|
+
@data.tap { |data| @data.delete(:person_id) }
|
39
|
+
warn 'person_id is nil, event will not be track against a user'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
41
44
|
end
|
data/lib/gosquared/trends.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
require_relative "client"
|
2
|
+
|
3
|
+
module Gosquared
|
2
4
|
class Trends
|
3
5
|
|
4
|
-
BASEURL = "https://api.gosquared.com/trends/v2/"
|
5
|
-
DIMENSIONS = %w(aggregate browser category country event language organisation os page path1 product screenDimensions sources transactions)
|
6
|
+
BASEURL = "https://api.gosquared.com/trends/v2/".freeze
|
7
|
+
DIMENSIONS = %w(aggregate browser category country event language organisation os page path1 product screenDimensions sources transactions).freeze
|
6
8
|
@@filters = {date_format: @date_format, from: @from, to: @to,
|
7
|
-
format: @format, limit: @limit, sort: @sort, group: @group
|
9
|
+
format: @format, limit: @limit, sort: @sort, group: @group,
|
10
|
+
source_type: @source_type}
|
8
11
|
|
9
|
-
def initialize(api_key, site_token, client=Client.new)
|
12
|
+
def initialize(api_key, site_token, client = Gosquared::Client.new)
|
10
13
|
@site_token = site_token
|
11
14
|
@api_key = api_key
|
12
15
|
@client = client
|
@@ -37,8 +40,13 @@ require_relative "client"
|
|
37
40
|
def url
|
38
41
|
array = [""]
|
39
42
|
url = BASEURL + @dimension + "?api_key=#{@api_key}" + "&site_token=#{@site_token}"
|
40
|
-
@@filters.each {|key, value| array << "#{key}=#{value}" if value }
|
43
|
+
@@filters.each {|key, value| array << "#{camelize(key.to_s)}=#{value}" if value }
|
41
44
|
parameters=array.join('&')
|
42
45
|
url.concat(parameters)
|
43
46
|
end
|
47
|
+
|
48
|
+
def camelize(key)
|
49
|
+
key.split('_').each_with_index.map{|fragment, index| index == 0 ? fragment : fragment.capitalize }.join('')
|
50
|
+
end
|
44
51
|
end
|
52
|
+
end
|
data/spec/account_spec.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
describe Account do
|
1
|
+
describe Gosquared::Account do
|
2
2
|
subject(:gs) { described_class.new("demo", "GSN-2194840-F") }
|
3
3
|
|
4
|
-
Account::DIMENSIONS.each do |dimension|
|
5
|
-
before do
|
4
|
+
Gosquared::Account::DIMENSIONS.each do |dimension|
|
5
|
+
before do
|
6
6
|
data = '{"a": [{"test": "response"}]}'
|
7
7
|
stub_request(:get, "https://api.gosquared.com/account/v1/#{dimension}?api_key=demo&site_token=GSN-2194840-F" ).
|
8
8
|
with(headers: {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
|
@@ -10,26 +10,26 @@ describe Account do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
Account::DIMENSIONS.each do |dimension|
|
14
|
-
it "fetches a request from the GoSquared Account API with #{dimension} dimension" do
|
13
|
+
Gosquared::Account::DIMENSIONS.each do |dimension|
|
14
|
+
it "fetches a request from the GoSquared Account API with #{dimension} dimension" do
|
15
15
|
gs.send("#{dimension}")
|
16
16
|
expect(gs.fetch).to eq("a" => [{"test"=>"response"}])
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
before do
|
20
|
+
before do
|
21
21
|
data = '{"a": [{"test": "response"}]}'
|
22
22
|
stub_request(:get, "https://api.gosquared.com/account/v1/sites/GSN-086224-W?api_key=demo&site_token=GSN-2194840-F").
|
23
23
|
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Host'=>'api.gosquared.com', 'User-Agent'=>'Ruby'}).
|
24
24
|
to_return(:status => 200, :body => data, :headers => {})
|
25
25
|
end
|
26
26
|
|
27
|
-
it "retrieves a site by its site token" do
|
27
|
+
it "retrieves a site by its site token" do
|
28
28
|
gs.sites.token("GSN-086224-W")
|
29
29
|
expect(gs.fetch).to eq("a" => [{"test"=>"response"}])
|
30
30
|
end
|
31
31
|
|
32
|
-
before do
|
32
|
+
before do
|
33
33
|
stub_request(:post, "https://api.gosquared.com/account/v1/blocked/ips?api_key=demo&ip=20.15.33.99&site_token=GSN-2194840-F").
|
34
34
|
with(:body => "[ \"\" ]",
|
35
35
|
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}).
|
@@ -40,28 +40,28 @@ describe Account do
|
|
40
40
|
to_return(:status => 200, :body => "", :headers => {})
|
41
41
|
end
|
42
42
|
|
43
|
-
it "posts a request to the GoSquared Account API with an IP address to block bots" do
|
43
|
+
it "posts a request to the GoSquared Account API with an IP address to block bots" do
|
44
44
|
gs.blocked.ips.ip('20.15.33.99')
|
45
45
|
expect(gs.post.code).to eq('200')
|
46
46
|
end
|
47
47
|
|
48
|
-
it "sends a delete request to the GoSquared Account API with an IP address to block bots" do
|
48
|
+
it "sends a delete request to the GoSquared Account API with an IP address to block bots" do
|
49
49
|
gs.blocked.ips.ip('20.15.33.99')
|
50
50
|
expect(gs.delete.code).to eq('200')
|
51
51
|
end
|
52
52
|
|
53
|
-
before do
|
53
|
+
before do
|
54
54
|
data = '{"a": [{"test": "response"}]}'
|
55
55
|
stub_request(:get, "https://api.gosquared.com/account/v1/blocked/visitors/test.email@gmail.com?api_key=demo&site_token=GSN-2194840-F").
|
56
56
|
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Host'=>'api.gosquared.com', 'User-Agent'=>'Ruby'}).
|
57
57
|
to_return(:status => 200, :body => data, :headers => {})
|
58
58
|
end
|
59
59
|
|
60
|
-
it "retrieves a list of blocked visitors" do
|
60
|
+
it "retrieves a list of blocked visitors" do
|
61
61
|
gs.blocked.visitors("test.email@gmail.com")
|
62
62
|
expect(gs.fetch).to eq("a" => [{"test"=>"response"}])
|
63
63
|
end
|
64
64
|
|
65
|
-
|
66
65
|
|
67
|
-
|
66
|
+
|
67
|
+
end
|
data/spec/client_spec.rb
CHANGED
@@ -2,38 +2,38 @@ require 'net/https'
|
|
2
2
|
require 'uri'
|
3
3
|
require 'json'
|
4
4
|
|
5
|
-
describe Client do
|
5
|
+
describe Gosquared::Client do
|
6
6
|
subject(:client) { described_class.new }
|
7
7
|
|
8
8
|
EXCEPTIONS = [Timeout::Error, EOFError,
|
9
9
|
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError]
|
10
10
|
|
11
|
-
EXCEPTIONS.each do |exception|
|
11
|
+
EXCEPTIONS.each do |exception|
|
12
12
|
it "raises a #{exception} error on a get request" do
|
13
13
|
uri = URI('www.example.com')
|
14
14
|
allow(Net::HTTP).to receive(:get).with(uri).and_raise(exception)
|
15
15
|
expect{client.get('www.example.com')}.to output("[error] HTTP error: #{exception}\n[error] StandardError: Could not parse JSON\n").to_stdout
|
16
|
-
end
|
16
|
+
end
|
17
17
|
end
|
18
18
|
|
19
19
|
it "raises a Errno::EINVAL error on a get request" do
|
20
20
|
uri = URI('www.example.com')
|
21
21
|
allow(Net::HTTP).to receive(:get).with(uri).and_raise(Errno::EINVAL)
|
22
22
|
expect{client.get('www.example.com')}.to output("[error] HTTP error: Invalid argument\n[error] StandardError: Could not parse JSON\n").to_stdout
|
23
|
-
end
|
23
|
+
end
|
24
24
|
|
25
25
|
it "raises a Errno::ECONNRESET error on a get request" do
|
26
26
|
uri = URI('www.example.com')
|
27
27
|
allow(Net::HTTP).to receive(:get).with(uri).and_raise(Errno::ECONNRESET)
|
28
28
|
expect{client.get('www.example.com')}.to output("[error] HTTP error: Connection reset by peer\n[error] StandardError: Could not parse JSON\n").to_stdout
|
29
|
-
end
|
29
|
+
end
|
30
30
|
|
31
|
-
EXCEPTIONS.each do |exception|
|
31
|
+
EXCEPTIONS.each do |exception|
|
32
32
|
it "raises a #{exception} error on a post request" do
|
33
33
|
uri = URI.parse("www.example.com")
|
34
34
|
allow(Net::HTTP).to receive(:new).with(uri.host, uri.port).and_raise(exception)
|
35
35
|
expect{client.post("www.example.com", "body")}.to output("[error] HTTP error: #{exception}\n[error] StandardError: Could not print response message\n").to_stdout
|
36
|
-
end
|
36
|
+
end
|
37
37
|
end
|
38
38
|
|
39
39
|
it "raises a Errno::EINVAL error on a post request" do
|
@@ -46,14 +46,14 @@ it "raises a Errno::ECONNRESET error on a post request" do
|
|
46
46
|
uri = URI.parse("www.example.com")
|
47
47
|
allow(Net::HTTP).to receive(:new).with(uri.host, uri.port).and_raise(Errno::ECONNRESET)
|
48
48
|
expect{client.post("www.example.com", "body")}.to output("[error] HTTP error: Connection reset by peer\n[error] StandardError: Could not print response message\n").to_stdout
|
49
|
-
end
|
49
|
+
end
|
50
50
|
|
51
|
-
EXCEPTIONS.each do |exception|
|
51
|
+
EXCEPTIONS.each do |exception|
|
52
52
|
it "raises a #{exception} error on a delete request" do
|
53
53
|
uri = URI.parse("www.example.com")
|
54
54
|
allow(Net::HTTP).to receive(:new).with(uri.host, uri.port).and_raise(exception)
|
55
55
|
expect{client.delete("www.example.com", "body")}.to output("[error] HTTP error: #{exception}\n[error] StandardError: Could not print response message\n").to_stdout
|
56
|
-
end
|
56
|
+
end
|
57
57
|
end
|
58
58
|
|
59
59
|
it "raises a Errno::EINVAL error on a delete request" do
|
@@ -66,6 +66,6 @@ it "raises a Errno::ECONNRESET error on a delete request" do
|
|
66
66
|
uri = URI.parse("www.example.com")
|
67
67
|
allow(Net::HTTP).to receive(:new).with(uri.host, uri.port).and_raise(Errno::ECONNRESET)
|
68
68
|
expect{client.delete("www.example.com", "body")}.to output("[error] HTTP error: Connection reset by peer\n[error] StandardError: Could not print response message\n").to_stdout
|
69
|
-
end
|
69
|
+
end
|
70
70
|
|
71
|
-
end
|
71
|
+
end
|
data/spec/now_spec.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
describe Now do
|
1
|
+
describe Gosquared::Now do
|
2
2
|
subject(:gs) { described_class.new("demo", "GSN-2194840-F") }
|
3
3
|
|
4
|
-
Now::DIMENSIONS.each do |dimension|
|
5
|
-
before do
|
4
|
+
Gosquared::Now::DIMENSIONS.each do |dimension|
|
5
|
+
before do
|
6
6
|
data = '{"a": [{"test": "response"}]}'
|
7
7
|
stub_request(:get, "https://api.gosquared.com/now/v3/#{dimension}?api_key=demo&site_token=GSN-2194840-F" ).
|
8
8
|
with(headers: {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
|
@@ -10,14 +10,14 @@ describe Now do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
Now::DIMENSIONS.each do |dimension|
|
14
|
-
it "fetches a request from the GoSquared Now API with #{dimension} dimension" do
|
13
|
+
Gosquared::Now::DIMENSIONS.each do |dimension|
|
14
|
+
it "fetches a request from the GoSquared Now API with #{dimension} dimension" do
|
15
15
|
gs.send "#{dimension}"
|
16
16
|
expect(gs.fetch).to eq("a" => [{"test"=>"response"}])
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
before do
|
20
|
+
before do
|
21
21
|
data = '{"a": [{"test": "response"}, {"with": "params"}]}'
|
22
22
|
stub_request(:get, "https://api.gosquared.com/now/v3/browsers?api_key=demo&site_token=GSN-2194840-F&limit=5").
|
23
23
|
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Host'=>'api.gosquared.com', 'User-Agent'=>'Ruby'}).
|
@@ -29,4 +29,4 @@ describe Now do
|
|
29
29
|
expect(gs.fetch).to eq("a" => [{"test"=>"response"}, {"with"=>"params"}])
|
30
30
|
end
|
31
31
|
|
32
|
-
end
|
32
|
+
end
|
data/spec/people_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
describe People do
|
1
|
+
describe Gosquared::People do
|
2
2
|
subject(:gs) { described_class.new("demo", "GSN-106863-S") }
|
3
3
|
|
4
|
-
People::DIMENSIONS.each do |dimension|
|
4
|
+
Gosquared::People::DIMENSIONS.each do |dimension|
|
5
5
|
before do
|
6
6
|
data = '{"a": [{"test": "response"}]}'
|
7
7
|
stub_request(:get, "https://api.gosquared.com/people/v1/#{dimension}?api_key=demo&site_token=GSN-106863-S"
|
@@ -11,7 +11,7 @@ describe People do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
People::DIMENSIONS.each do |dimension|
|
14
|
+
Gosquared::People::DIMENSIONS.each do |dimension|
|
15
15
|
it "fetches a request from the GoSquared People API with #{dimension} dimension" do
|
16
16
|
gs.send "#{dimension}"
|
17
17
|
expect(gs.fetch).to eq("a" => [{"test"=>"response"}])
|
@@ -31,7 +31,7 @@ describe People do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
|
34
|
-
People::DIMENSIONS.each do |dimension|
|
34
|
+
Gosquared::People::DIMENSIONS.each do |dimension|
|
35
35
|
before do
|
36
36
|
data = '{"a": [{"test": "response"}, {"with": "params"}]}'
|
37
37
|
stub_request(:get, "https://api.gosquared.com/people/v1/#{dimension}?api_key=demo&site_token=GSN-106863-S&limit=5").
|
@@ -40,7 +40,7 @@ describe People do
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
People::DIMENSIONS.each do |dimension|
|
43
|
+
Gosquared::People::DIMENSIONS.each do |dimension|
|
44
44
|
it "fetches a request from the GoSquared People API with dimension and paramaters" do
|
45
45
|
gs.send("#{dimension}").limit(5)
|
46
46
|
expect(gs.fetch).to eq("a" => [{"test"=>"response"}, {"with"=>"params"}])
|
data/spec/tracking_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
describe Tracking do
|
1
|
+
describe Gosquared::Tracking do
|
2
2
|
subject(:gs) { described_class.new("demo", "GSN-2194840-F") }
|
3
3
|
|
4
|
-
Tracking::DIMENSIONS.each do |dimension|
|
4
|
+
Gosquared::Tracking::DIMENSIONS.each do |dimension|
|
5
5
|
before do
|
6
6
|
stub_request(:post, "https://api.gosquared.com/tracking/v1/#{dimension}?api_key=demo&site_token=GSN-2194840-F").
|
7
7
|
with(:body => "[ {\"person_id\":\"email:test@example.com\",\"properties\":{\"email\":\"test@example.com\"}} ]",
|
@@ -10,7 +10,7 @@ describe Tracking do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
Tracking::DIMENSIONS.each do |dimension|
|
13
|
+
Gosquared::Tracking::DIMENSIONS.each do |dimension|
|
14
14
|
it "posts a request to the GoSquared Track API with #{dimension} dimension" do
|
15
15
|
gs.send "#{dimension}", ({person_id: "email:test@example.com",
|
16
16
|
properties:{email: "test@example.com"}})
|
data/spec/trends_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
describe Trends do
|
1
|
+
describe Gosquared::Trends do
|
2
2
|
subject(:gs) { described_class.new("demo","GSN-106863-S") }
|
3
3
|
|
4
|
-
Trends::DIMENSIONS.each do |dimension|
|
4
|
+
Gosquared::Trends::DIMENSIONS.each do |dimension|
|
5
5
|
before do
|
6
6
|
data = '{"a": [{"test": "response"}]}'
|
7
7
|
stub_request(:get, "https://api.gosquared.com/trends/v2/#{dimension}?api_key=demo&site_token=GSN-106863-S").
|
@@ -10,23 +10,23 @@ describe Trends do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
Trends::DIMENSIONS.each do |dimension|
|
13
|
+
Gosquared::Trends::DIMENSIONS.each do |dimension|
|
14
14
|
it "fetches a request from the GoSquared Trends API with #{dimension} dimension" do
|
15
15
|
gs.send "#{dimension}"
|
16
16
|
expect(gs.fetch).to eq("a" => [{"test"=>"response"}])
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
Trends::DIMENSIONS.each do |dimension|
|
20
|
+
Gosquared::Trends::DIMENSIONS.each do |dimension|
|
21
21
|
before do
|
22
22
|
data = '{"a": [{"test": "response"}, {"with": "params"}]}'
|
23
|
-
stub_request(:get, "https://api.gosquared.com/trends/v2/#{dimension}?api_key=demo&site_token=GSN-106863-S&
|
23
|
+
stub_request(:get, "https://api.gosquared.com/trends/v2/#{dimension}?api_key=demo&site_token=GSN-106863-S&dateFormat=yyyy-mm-dd&format=json&from=2016-06-20&group=true&limit=5&site_token=GSN-106863-S&sort=visits&to=2016-06-30").
|
24
24
|
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Host'=>'api.gosquared.com', 'User-Agent'=>'Ruby'}).
|
25
25
|
to_return(:status => 200, :body => data, :headers => {})
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
Trends::DIMENSIONS.each do |dimension|
|
29
|
+
Gosquared::Trends::DIMENSIONS.each do |dimension|
|
30
30
|
it "fetches a request from the GoSquared Trends API with #{dimension} dimension and paramaters" do
|
31
31
|
gs.send("#{dimension}").from('2016-06-20').to('2016-06-30')
|
32
32
|
.date_format('yyyy-mm-dd').sort('visits').group(true).format('json').limit(5)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gosquared
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Russell Vaughan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
86
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.
|
87
|
+
rubygems_version: 2.4.8
|
88
88
|
signing_key:
|
89
89
|
specification_version: 4
|
90
90
|
summary: GoSquared Ruby Library
|