trakio-ruby 0.1.2 → 0.1.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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NGQ5ODIxMGM4MjVlMDg2ZGE0MDc1NTZkZmU3ZDlmOWFmNjM5M2IwOQ==
4
+ Y2E5MmRiYzhhYTQ1N2NhNmU0YmQ2NDA4MzkwNzQyZWFlZjYxOTFmNA==
5
5
  data.tar.gz: !binary |-
6
- NWZjODc1MzJhNzFlZWM4ZGQyY2E2YmU3ZTYxOWZlZGIxZjBlMjQ4YQ==
6
+ YzUzOWYwODc4OTA3MTAwY2Y4YzY3MzMyMzg3NmFhMzAzZTdjMzdlZg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YWI3YzYyMTExZjJjZmNiMTkwMjhkNDU3NDViZDQxNmMyOWI5Nzc3OTlmZjhh
10
- MTJjNDBlZjQxZGQ4MDY5ZDc3MmRhMzZiODA3NmRkM2UzNGRmM2MxNDdhNjM5
11
- OTY5YzdmMjllMDMwNTZhNzEwYTNjODVjODNhM2YyOWVlNmVkODQ=
9
+ N2M3MWUyOTRkMWU4ZjZkMDMwMzJkYjExMWYyYmIyYjI1N2FhZThlNGIzZmM1
10
+ ODZjZmRkZGMwZjE5NzI1YzQ1OTVkZGM1YjgwNDNjN2M3ZGNlYTBiMDViZTY4
11
+ NDlmOTg0MDUzZGY4OWVlZWJiYTFmMWEzOTc5ZmNlZTU3OWVjMDE=
12
12
  data.tar.gz: !binary |-
13
- NzJhNjliNzFhMjNiNTE2MDI1Mjc2MmVjZmY4ODgxMTcyNDRmZmY3ZDQ5M2E3
14
- OTg4YjM2MjY3YzU5ZmZlYjdlMTJmMTk0ODM1YjY3ZWVkYmMxMGIzY2EyNTY4
15
- OTc1NDBiODNmNGRiMzNkMDJhMDJjMDE2Mzc3OWM4YzA0M2Q5OTc=
13
+ MzY0Mzg3MjY4YTllMGE0ZGRjNTAyNjA5MzAzOTJmMmU4N2UxODkxZTQ4MDk0
14
+ MDcxNWM3Y2I3MmZiZGVhNTlhYjJkOTA0M2E4MThhMGZiZDBmMjRlNDEyOTU3
15
+ ZDUyYTFiYzBiNzc4NTNmNDA1OWZlZjY3NWZjNjFlYTljYjI3OGY=
@@ -1,3 +1,3 @@
1
1
  class Trakio
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/trakio.rb CHANGED
@@ -93,6 +93,10 @@ class Trakio
93
93
  distinct_id: distinct_id,
94
94
  event: event,
95
95
  }
96
+ if parameters[:time]
97
+ params[:time] = parameters[:time]
98
+ params[:time] = params[:time].iso8601 unless params[:time].is_a? String
99
+ end
96
100
  params[:channel] = channel if channel
97
101
  params[:properties] = properties if properties
98
102
 
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,8 @@ Coveralls.wear!
3
3
  require 'trakio'
4
4
  require 'webmock/rspec'
5
5
  require 'json'
6
+ require 'active_support/core_ext/numeric/time'
7
+ require 'active_support/core_ext/date/calculations'
6
8
 
7
9
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
8
10
  RSpec.configure do |config|
@@ -122,6 +122,64 @@ describe Trakio do
122
122
 
123
123
  end
124
124
 
125
+ context "when a time is provided as a DateTime" do
126
+
127
+ let (:time) { 3.days.ago }
128
+
129
+ it "sends a track request to api.trak.io" do
130
+ stub = stub_request(:post, "https://api.trak.io/v1/track").
131
+ with(:body => {
132
+ token: 'my_api_token',
133
+ data: {
134
+ distinct_id: 'user@example.com',
135
+ event: 'my-event',
136
+ time: time.iso8601
137
+ }
138
+ }).to_return(:body => {
139
+ status: 'success',
140
+ trak_id: '1234567890'
141
+ }.to_json)
142
+
143
+ trakio = Trakio.new 'my_api_token'
144
+ resp = trakio.track distinct_id: 'user@example.com', event: 'my-event', time: time
145
+
146
+ expect(resp[:status]).to eql 'success'
147
+ expect(resp[:trak_id]).to eql '1234567890'
148
+
149
+ stub.should have_been_requested
150
+ end
151
+
152
+ end
153
+
154
+ context "when a time is provided as a string" do
155
+
156
+ let (:time) { 3.days.ago }
157
+
158
+ it "sends a track request to api.trak.io" do
159
+ stub = stub_request(:post, "https://api.trak.io/v1/track").
160
+ with(:body => {
161
+ token: 'my_api_token',
162
+ data: {
163
+ distinct_id: 'user@example.com',
164
+ event: 'my-event',
165
+ time: time.iso8601
166
+ }
167
+ }).to_return(:body => {
168
+ status: 'success',
169
+ trak_id: '1234567890'
170
+ }.to_json)
171
+
172
+ trakio = Trakio.new 'my_api_token'
173
+ resp = trakio.track distinct_id: 'user@example.com', event: 'my-event', time: time.iso8601
174
+
175
+ expect(resp[:status]).to eql 'success'
176
+ expect(resp[:trak_id]).to eql '1234567890'
177
+
178
+ stub.should have_been_requested
179
+ end
180
+
181
+ end
182
+
125
183
  end
126
184
 
127
185
  context "when an event isn't provided" do
data/trakio-ruby.gemspec CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency 'webmock'
25
25
  spec.add_development_dependency 'fuubar'
26
26
  spec.add_development_dependency 'coveralls'
27
+ spec.add_development_dependency 'activesupport'
27
28
 
28
29
  spec.add_dependency 'rest_client'
29
30
  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.2
4
+ version: 0.1.3
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-19 00:00:00.000000000 Z
12
+ date: 2014-04-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -95,6 +95,20 @@ dependencies:
95
95
  - - ! '>='
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: activesupport
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
98
112
  - !ruby/object:Gem::Dependency
99
113
  name: rest_client
100
114
  requirement: !ruby/object:Gem::Requirement