trakio-ruby 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.coveralls.yml +1 -0
- data/.gitignore +1 -0
- data/.travis.yml +5 -2
- data/README.md +7 -0
- data/lib/trakio/version.rb +1 -1
- data/lib/trakio.rb +25 -11
- data/spec/spec_helper.rb +2 -0
- data/spec/trakio/page_view_spec.rb +73 -0
- data/trakio-ruby.gemspec +2 -1
- metadata +20 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NGQ5ODIxMGM4MjVlMDg2ZGE0MDc1NTZkZmU3ZDlmOWFmNjM5M2IwOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NWZjODc1MzJhNzFlZWM4ZGQyY2E2YmU3ZTYxOWZlZGIxZjBlMjQ4YQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YWI3YzYyMTExZjJjZmNiMTkwMjhkNDU3NDViZDQxNmMyOWI5Nzc3OTlmZjhh
|
10
|
+
MTJjNDBlZjQxZGQ4MDY5ZDc3MmRhMzZiODA3NmRkM2UzNGRmM2MxNDdhNjM5
|
11
|
+
OTY5YzdmMjllMDMwNTZhNzEwYTNjODVjODNhM2YyOWVlNmVkODQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzJhNjliNzFhMjNiNTE2MDI1Mjc2MmVjZmY4ODgxMTcyNDRmZmY3ZDQ5M2E3
|
14
|
+
OTg4YjM2MjY3YzU5ZmZlYjdlMTJmMTk0ODM1YjY3ZWVkYmMxMGIzY2EyNTY4
|
15
|
+
OTc1NDBiODNmNGRiMzNkMDJhMDJjMDE2Mzc3OWM4YzA0M2Q5OTc=
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Official trak.io Ruby Library
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/trakio-ruby.png)](http://badge.fury.io/rb/trakio-ruby)
|
4
|
+
[![Dependency Status](https://gemnasium.com/trakio/trakio-ruby.png)](https://gemnasium.com/trakio/trakio-ruby)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/trakio/trakio-ruby.png)](https://codeclimate.com/github/trakio/trakio-ruby)
|
6
|
+
[![Build Status](https://travis-ci.org/trakio/trakio-ruby.png?branch=master)](https://travis-ci.org/trakio/trakio-ruby)
|
7
|
+
[![Coverage Status](https://coveralls.io/repos/trakio/trakio-ruby/badge.png?branch=master)](https://coveralls.io/r/trakio/trakio-ruby?branch=master)
|
8
|
+
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/trakio/trakio-ruby/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
9
|
+
|
3
10
|
## Installation
|
4
11
|
|
5
12
|
Add this line to your application's Gemfile:
|
data/lib/trakio/version.rb
CHANGED
data/lib/trakio.rb
CHANGED
@@ -25,18 +25,13 @@ class Trakio
|
|
25
25
|
def init(*args)
|
26
26
|
api_token, params = args
|
27
27
|
raise Trakio::Exceptions::InvalidToken.new('Missing API Token') unless api_token
|
28
|
-
if params and params.has_key?(:distinct_id)
|
29
|
-
raise Trakio::Exceptions::NoDistinctIdForDefaultInstance
|
30
|
-
end
|
28
|
+
raise Trakio::Exceptions::NoDistinctIdForDefaultInstance if params and params.has_key?(:distinct_id)
|
31
29
|
@default_instance = Trakio.new(*args)
|
32
30
|
end
|
33
31
|
|
34
32
|
def default_instance
|
35
|
-
|
36
|
-
|
37
|
-
else
|
38
|
-
raise Trakio::Exceptions::Uninitiated
|
39
|
-
end
|
33
|
+
raise Trakio::Exceptions::Uninitiated unless @default_instance
|
34
|
+
@default_instance
|
40
35
|
end
|
41
36
|
|
42
37
|
def default_instance=(instance)
|
@@ -76,9 +71,7 @@ class Trakio
|
|
76
71
|
@host = 'api.trak.io/v1'
|
77
72
|
|
78
73
|
%w{https host channel distinct_id}.each do |name|
|
79
|
-
if params && params.has_key?(name.to_sym)
|
80
|
-
instance_variable_set("@#{name}", params[name.to_sym])
|
81
|
-
end
|
74
|
+
instance_variable_set("@#{name}", params[name.to_sym]) if params && params.has_key?(name.to_sym)
|
82
75
|
end
|
83
76
|
end
|
84
77
|
|
@@ -161,6 +154,27 @@ class Trakio
|
|
161
154
|
send_request('annotate', params)
|
162
155
|
end
|
163
156
|
|
157
|
+
def page_view(parameters)
|
158
|
+
parameters.default = nil
|
159
|
+
args = {
|
160
|
+
event: 'Page view'
|
161
|
+
}
|
162
|
+
|
163
|
+
distinct_id = parameters[:distinct_id]
|
164
|
+
args[:distinct_id] = distinct_id if distinct_id
|
165
|
+
|
166
|
+
raise "Must specify URL" unless parameters.has_key?(:url)
|
167
|
+
raise "Must specify Title" unless parameters.has_key?(:title)
|
168
|
+
|
169
|
+
properties = {
|
170
|
+
url: parameters[:url],
|
171
|
+
title: parameters[:title],
|
172
|
+
}
|
173
|
+
args[:properties] = properties
|
174
|
+
|
175
|
+
track args # right now page_view is an alias of track
|
176
|
+
end
|
177
|
+
|
164
178
|
def send_request(endpoint, params)
|
165
179
|
protocol = @https ? "https" : "http"
|
166
180
|
url = "#{protocol}://#{@host}/#{endpoint}"
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Trakio do
|
4
|
+
|
5
|
+
subject { Trakio }
|
6
|
+
|
7
|
+
after {
|
8
|
+
Trakio.default_instance = nil
|
9
|
+
}
|
10
|
+
|
11
|
+
describe '.page_view' do
|
12
|
+
|
13
|
+
context 'when a url is specified' do
|
14
|
+
context 'when a title is specified' do
|
15
|
+
it 'tracks a page_view' do
|
16
|
+
stub = stub_request(:post, "https://api.trak.io/v1/track").
|
17
|
+
with(:body => {
|
18
|
+
token: 'my_api_token',
|
19
|
+
data: {
|
20
|
+
distinct_id: 'user@example.com',
|
21
|
+
event: 'Page view',
|
22
|
+
properties: {
|
23
|
+
title: 'Test Title',
|
24
|
+
url: 'http://test.test/test',
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}).to_return(:body => {
|
28
|
+
status: 'success',
|
29
|
+
trak_id: '1234567890'
|
30
|
+
}.to_json)
|
31
|
+
|
32
|
+
trakio = Trakio.new 'my_api_token'
|
33
|
+
resp = trakio.page_view distinct_id: 'user@example.com', title: 'Test Title', url: 'http://test.test/test'
|
34
|
+
|
35
|
+
expect(resp[:status]).to eql 'success'
|
36
|
+
expect(resp[:trak_id]).to eql '1234567890'
|
37
|
+
|
38
|
+
stub.should have_been_requested
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when a title is not specified' do
|
43
|
+
it 'should raise an error' do
|
44
|
+
trakio = Trakio.new 'my_api_token'
|
45
|
+
expect {
|
46
|
+
trakio.page_view distinct_id: 'user@example.com',
|
47
|
+
url: 'http://test.test/test'
|
48
|
+
}.to raise_error RuntimeError
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when a url is not specified' do
|
54
|
+
it 'should raise an error' do
|
55
|
+
trakio = Trakio.new 'my_api_token'
|
56
|
+
expect {
|
57
|
+
trakio.page_view distinct_id: 'user@example.com'
|
58
|
+
}.to raise_error RuntimeError
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'when a title is specified' do
|
62
|
+
it 'should raise an error' do
|
63
|
+
trakio = Trakio.new 'my_api_token'
|
64
|
+
expect {
|
65
|
+
trakio.page_view distinct_id: 'user@example.com', title: 'Test Title'
|
66
|
+
}.to raise_error RuntimeError
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end # end .page_view
|
72
|
+
|
73
|
+
end
|
data/trakio-ruby.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["matt@trak.io", "tobie.warburton@gmail.com"]
|
11
11
|
spec.description = "Official trak.io ruby library for Ruby"
|
12
12
|
spec.summary = "Official trak.io ruby library for Ruby"
|
13
|
-
spec.homepage = "https://
|
13
|
+
spec.homepage = "https://trak.io"
|
14
14
|
spec.license = "Apache 2.0"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency 'rspec'
|
24
24
|
spec.add_development_dependency 'webmock'
|
25
25
|
spec.add_development_dependency 'fuubar'
|
26
|
+
spec.add_development_dependency 'coveralls'
|
26
27
|
|
27
28
|
spec.add_dependency 'rest_client'
|
28
29
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trakio-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Spence
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-02-
|
12
|
+
date: 2014-02-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -81,6 +81,20 @@ dependencies:
|
|
81
81
|
- - ! '>='
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: coveralls
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
84
98
|
- !ruby/object:Gem::Dependency
|
85
99
|
name: rest_client
|
86
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,6 +117,7 @@ executables: []
|
|
103
117
|
extensions: []
|
104
118
|
extra_rdoc_files: []
|
105
119
|
files:
|
120
|
+
- .coveralls.yml
|
106
121
|
- .gitignore
|
107
122
|
- .travis.yml
|
108
123
|
- Gemfile
|
@@ -119,9 +134,10 @@ files:
|
|
119
134
|
- spec/trakio/indentify_spec.rb
|
120
135
|
- spec/trakio/initialize_spec.rb
|
121
136
|
- spec/trakio/instance_methods_spec.rb
|
137
|
+
- spec/trakio/page_view_spec.rb
|
122
138
|
- spec/trakio/track_spec.rb
|
123
139
|
- trakio-ruby.gemspec
|
124
|
-
homepage: https://
|
140
|
+
homepage: https://trak.io
|
125
141
|
licenses:
|
126
142
|
- Apache 2.0
|
127
143
|
metadata: {}
|
@@ -154,4 +170,5 @@ test_files:
|
|
154
170
|
- spec/trakio/indentify_spec.rb
|
155
171
|
- spec/trakio/initialize_spec.rb
|
156
172
|
- spec/trakio/instance_methods_spec.rb
|
173
|
+
- spec/trakio/page_view_spec.rb
|
157
174
|
- spec/trakio/track_spec.rb
|