leanplum_api 1.4.0 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -11
- data/lib/leanplum_api/api.rb +24 -21
- data/lib/leanplum_api/{content_read_only.rb → connections/content_read_only.rb} +3 -3
- data/lib/leanplum_api/{data_export.rb → connections/data_export.rb} +3 -3
- data/lib/leanplum_api/{development.rb → connections/development.rb} +3 -3
- data/lib/leanplum_api/{http.rb → connections/production.rb} +6 -12
- data/lib/leanplum_api/logger.rb +3 -8
- data/lib/leanplum_api/version.rb +1 -1
- data/lib/leanplum_api.rb +4 -1
- data/spec/api_spec.rb +15 -9
- data/spec/configuration_spec.rb +1 -3
- data/spec/fixtures/vcr/track_offline_events.yml +43 -0
- data/spec/http_spec.rb +3 -3
- data/spec/spec_helper.rb +14 -22
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96a62527d89596e1a01c6260c1b6a78b6a942442
|
4
|
+
data.tar.gz: 0700fe592e63ae062c2f5bebc104f1238763ca44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6248055081fb84ed57b51c5b36b8fd7797e44027f7715812f820922c7e2f5140b510d57e9f20dbe8ec5c5f48f9828d964d8d7615abb8edb9c3d3d1181b62dbc
|
7
|
+
data.tar.gz: 1e4683d7f50be65b44fc7c1b9e7ffa9d26e4729e2488c19c887dfbdac739726d77c243e07ebb563546c0c009e8114cc45f0094c275b595448e7e0cfc0b1f2b78
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ Gem for the Leanplum API.
|
|
6
6
|
|
7
7
|
Leanplum calls it a REST API but it is not very RESTful.
|
8
8
|
|
9
|
-
The gem uses the ```multi``` method with a POST for all
|
9
|
+
The gem uses the ```multi``` method with a POST for all event tracking and user attribute updating requests. Check Leanplum's docs for more information on ```multi```.
|
10
10
|
|
11
11
|
Tested with Leanplum API version 1.0.6.
|
12
12
|
|
@@ -37,7 +37,7 @@ LeanplumApi.configure do |config|
|
|
37
37
|
config.s3_access_id = 'access_id'
|
38
38
|
config.s3_access_key = 'access_key'
|
39
39
|
|
40
|
-
# Set this to true to send events and user attributes to the test environment
|
40
|
+
# Set this to true to send events and user attributes to the test environment.
|
41
41
|
# Defaults to false. See "Debugging" below for more info.
|
42
42
|
config.developer_mode = true
|
43
43
|
end
|
@@ -62,16 +62,19 @@ attribute_hash = {
|
|
62
62
|
}
|
63
63
|
api.set_user_attributes(attribute_hash)
|
64
64
|
|
65
|
-
# You must also provide the :event property for event tracking.
|
66
|
-
# You can optionally provide a :time
|
67
|
-
# All other key/values besides :user_id, :device_id, :event, and :time will be sent as event params
|
65
|
+
# You must also provide the :event property for event tracking. :info is an optional property for an extra string.
|
66
|
+
# You can optionally provide a :time; if it is not set Leanplum will timestamp the event "now".
|
67
|
+
# All other key/values besides :user_id, :device_id, :event, and :time will be sent as event params.
|
68
68
|
event = {
|
69
69
|
user_id: 12345,
|
70
70
|
event: 'purchase',
|
71
|
+
info: 'reallybigpurchase',
|
71
72
|
time: Time.now.utc, # Event timestamps will be converted to epoch seconds by the gem.
|
72
73
|
some_event_property: 'boss_hog_on_candy'
|
73
74
|
}
|
74
75
|
api.track_events(event)
|
76
|
+
# Events tracked like this will be made part of a session; for independent events use :allow_offline
|
77
|
+
api.track_events(event, allow_offline: true)
|
75
78
|
|
76
79
|
# You can also track events and user attributes at the same time
|
77
80
|
api.track_multi(event, attribute_hash)
|
@@ -90,12 +93,13 @@ job_id = api.export_data(start_time, end_time)
|
|
90
93
|
response = wait_for_job(job_id)
|
91
94
|
```
|
92
95
|
|
93
|
-
Note well that Leanplum officially recommends use of the automated S3 export instead of API based export. According to a Leanplum engineer these two data export methodologies are completely independent data paths and in our experience we have found API based data export to be missing 10-15% of the data that is eventually returned by the automated export.
|
96
|
+
Note well that Leanplum now officially recommends use of the automated S3 export instead of API based export. According to a Leanplum engineer these two data export methodologies are completely independent data paths and in our experience we have found API based data export to be missing 10-15% of the data that is eventually returned by the automated export.
|
94
97
|
|
95
98
|
## Specs
|
96
99
|
|
97
|
-
|
98
|
-
|
100
|
+
`bundle exec rspec` should work fine at running existing specs.
|
101
|
+
|
102
|
+
To write _new__ specs (or regenerate one of VCR's YAML files), you must set the `LEANPLUM_PRODUCTION_KEY`, `LEANPLUM_APP_ID`, `LEANPLUM_CONTENT_READ_ONLY_KEY`, `LEANPLUM_DEVELOPMENT_KEY`, and `LEANPLUM_DATA_EXPORT_KEY` environment variables (preferably to some development only keys) to something and then run rspec. VCR will create fixture data based on your requests, masking your actual keys so that it's safe to commit the file.
|
99
103
|
|
100
104
|
> BE AWARE THAT IF YOU WRITE A NEW SPEC OR DELETE A VCR FILE, IT'S POSSIBLE THAT REAL DATA WILL BE WRITTEN TO THE `LEANPLUM_APP_ID` YOU CONFIGURE! Certainly a real request will be made to rebuild the VCR file, and while specs run with ```devMode=true```, it's usually a good idea to create a fake app for testing/running specs against.
|
101
105
|
|
@@ -111,12 +115,12 @@ bundle exec rspec
|
|
111
115
|
|
112
116
|
## Debugging
|
113
117
|
|
114
|
-
The LEANPLUM_API_DEBUG environment variable will trigger full printouts of Faraday's debug output to STDERR and to the configured logger.
|
118
|
+
The `LEANPLUM_API_DEBUG` environment variable will trigger full printouts of Faraday's debug output to STDERR and to the configured logger.
|
115
119
|
|
116
120
|
```bash
|
117
121
|
cd /my/app
|
118
122
|
export LEANPLUM_API_DEBUG=true
|
119
|
-
bundle exec
|
123
|
+
bundle exec whatever
|
120
124
|
```
|
121
125
|
|
122
|
-
You can also configure "developer mode". This will use the
|
126
|
+
You can also configure "developer mode". This will use the `devMode=true` parameter on some requests, which seems to sends them to a separate queue which might not count towards Leanplum's usage billing.
|
data/lib/leanplum_api/api.rb
CHANGED
@@ -8,7 +8,6 @@ module LeanplumApi
|
|
8
8
|
|
9
9
|
def initialize(options = {})
|
10
10
|
fail 'LeanplumApi not configured yet!' unless LeanplumApi.configuration
|
11
|
-
@http = LeanplumApi::HTTP.new
|
12
11
|
end
|
13
12
|
|
14
13
|
def set_user_attributes(user_attributes, options = {})
|
@@ -27,12 +26,13 @@ module LeanplumApi
|
|
27
26
|
events = Array.wrap(events)
|
28
27
|
user_attributes = Array.wrap(user_attributes)
|
29
28
|
|
30
|
-
request_data = user_attributes.map { |h| build_user_attributes_hash(h) }
|
31
|
-
|
29
|
+
request_data = user_attributes.map { |h| build_user_attributes_hash(h) }
|
30
|
+
request_data += events.map { |h| build_event_attributes_hash(h, options) }
|
31
|
+
response = production_connection.multi(request_data).body['response']
|
32
32
|
|
33
33
|
if options[:force_anomalous_override]
|
34
34
|
user_ids_to_reset = []
|
35
|
-
response.
|
35
|
+
response.each_with_index do |indicator, i|
|
36
36
|
if indicator['warning'] && indicator['warning']['message'] =~ /Anomaly detected/i
|
37
37
|
# Leanplum does not return their warnings in order!!! So we just have to reset everyone who had any events.
|
38
38
|
# This is what the code should be:
|
@@ -140,7 +140,7 @@ module LeanplumApi
|
|
140
140
|
end
|
141
141
|
|
142
142
|
def get_vars(user_id)
|
143
|
-
|
143
|
+
production_connection.get(action: 'getVars', userId: user_id).body['response'].first['vars']
|
144
144
|
end
|
145
145
|
|
146
146
|
# If you pass old events OR users with old date attributes (i.e. create_date for an old users), leanplum will mark
|
@@ -150,23 +150,27 @@ module LeanplumApi
|
|
150
150
|
def reset_anomalous_users(user_ids)
|
151
151
|
user_ids = Array.wrap(user_ids)
|
152
152
|
request_data = user_ids.map { |user_id| { action: 'setUserAttributes', resetAnomalies: true, userId: user_id } }
|
153
|
-
development_connection.
|
153
|
+
development_connection.multi(request_data)
|
154
154
|
end
|
155
155
|
|
156
156
|
private
|
157
157
|
|
158
|
+
def production_connection
|
159
|
+
@production ||= Connection::Production.new
|
160
|
+
end
|
161
|
+
|
158
162
|
# Only instantiated for data export endpoint calls
|
159
163
|
def data_export_connection
|
160
|
-
@data_export ||=
|
164
|
+
@data_export ||= Connection::DataExport.new
|
161
165
|
end
|
162
166
|
|
163
167
|
# Only instantiated for ContentReadOnly calls (AB tests)
|
164
168
|
def content_read_only_connection
|
165
|
-
@content_read_only ||=
|
169
|
+
@content_read_only ||= Connection::ContentReadOnly.new
|
166
170
|
end
|
167
171
|
|
168
172
|
def development_connection
|
169
|
-
@development ||=
|
173
|
+
@development ||= Connection::Development.new
|
170
174
|
end
|
171
175
|
|
172
176
|
# Deletes the user_id and device_id key/value pairs from the hash parameter.
|
@@ -175,33 +179,32 @@ module LeanplumApi
|
|
175
179
|
device_id = hash.delete(:device_id)
|
176
180
|
fail "No device_id or user_id in hash #{hash}" unless user_id || device_id
|
177
181
|
|
178
|
-
user_id ? {
|
182
|
+
user_id ? { userId: user_id } : { deviceId: device_id }
|
179
183
|
end
|
180
184
|
|
181
185
|
# Action can be any command that takes a userAttributes param. "start" (a session) is the other command that most
|
182
186
|
# obviously takes userAttributes.
|
187
|
+
# As of 2015-10 Leanplum supports ISO8601 date & time strings as user attributes.
|
183
188
|
def build_user_attributes_hash(user_hash, action = 'setUserAttributes')
|
184
189
|
user_hash = HashWithIndifferentAccess.new(user_hash)
|
190
|
+
user_hash.each { |k, v| user_hash[k] = v.iso8601 if v.is_a?(Date) || v.is_a?(Time) || v.is_a?(DateTime) }
|
185
191
|
|
186
|
-
|
187
|
-
user_hash.each do |k,v|
|
188
|
-
user_hash[k] = v.iso8601 if v.is_a?(Date) || v.is_a?(Time) || v.is_a?(DateTime)
|
189
|
-
end
|
190
|
-
|
191
|
-
extract_user_id_or_device_id_hash!(user_hash).merge('action' => action, 'userAttributes' => user_hash)
|
192
|
+
extract_user_id_or_device_id_hash!(user_hash).merge(action: action, userAttributes: user_hash)
|
192
193
|
end
|
193
194
|
|
194
195
|
# Events have a :user_id or :device id, a name (:event) and an optional time (:time)
|
195
|
-
|
196
|
+
# Use the :allow_offline option to send events without creating a new session
|
197
|
+
def build_event_attributes_hash(event_hash, options = {})
|
196
198
|
event_hash = HashWithIndifferentAccess.new(event_hash)
|
197
199
|
event_name = event_hash.delete(:event)
|
198
200
|
fail "Event name or timestamp not provided in #{event_hash}" unless event_name
|
199
201
|
|
200
|
-
event = {
|
201
|
-
time
|
202
|
-
event.merge!(
|
202
|
+
event = { action: 'track', event: event_name }.merge(extract_user_id_or_device_id_hash!(event_hash))
|
203
|
+
event.merge!(time: event_hash.delete(:time).strftime('%s')) if event_hash[:time]
|
204
|
+
event.merge!(info: event_hash.delete(:info)) if event_hash[:info]
|
205
|
+
event.merge!(allowOffline: true) if options[:allow_offline]
|
203
206
|
|
204
|
-
event_hash.keys.size > 0 ? event.merge(
|
207
|
+
event_hash.keys.size > 0 ? event.merge(params: event_hash.symbolize_keys ) : event
|
205
208
|
end
|
206
209
|
end
|
207
210
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require 'leanplum_api/
|
1
|
+
require 'leanplum_api/connections/production'
|
2
2
|
|
3
|
-
module LeanplumApi
|
4
|
-
class ContentReadOnly <
|
3
|
+
module LeanplumApi::Connection
|
4
|
+
class ContentReadOnly < Production
|
5
5
|
def initialize(options = {})
|
6
6
|
raise 'Content read only key not configured!' unless LeanplumApi.configuration.content_read_only_key
|
7
7
|
super
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require 'leanplum_api/
|
1
|
+
require 'leanplum_api/connections/production'
|
2
2
|
|
3
|
-
module LeanplumApi
|
4
|
-
class DataExport <
|
3
|
+
module LeanplumApi::Connection
|
4
|
+
class DataExport < Production
|
5
5
|
def initialize(options = {})
|
6
6
|
raise 'Data export key not configured' unless LeanplumApi.configuration.data_export_key
|
7
7
|
super
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require 'leanplum_api/
|
1
|
+
require 'leanplum_api/connections/production'
|
2
2
|
|
3
|
-
module LeanplumApi
|
4
|
-
class Development <
|
3
|
+
module LeanplumApi::Connection
|
4
|
+
class Development < Production
|
5
5
|
def initialize(options = {})
|
6
6
|
raise 'Development key not configured!' unless LeanplumApi.configuration.development_key
|
7
7
|
super
|
@@ -1,16 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'uri'
|
4
|
-
|
5
|
-
module LeanplumApi
|
6
|
-
class HTTP
|
1
|
+
module LeanplumApi::Connection
|
2
|
+
class Production
|
7
3
|
LEANPLUM_API_PATH = '/api'
|
8
4
|
|
9
5
|
def initialize(options = {})
|
10
6
|
@logger = options[:logger] || Logger.new(STDERR)
|
11
7
|
end
|
12
8
|
|
13
|
-
def
|
9
|
+
def multi(payload)
|
14
10
|
connection.post("#{LEANPLUM_API_PATH}?#{authed_multi_param_string}") do |request|
|
15
11
|
request.body = { data: payload }
|
16
12
|
end
|
@@ -58,11 +54,9 @@ module LeanplumApi
|
|
58
54
|
end
|
59
55
|
|
60
56
|
def authed_multi_param_string
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
URI.encode_www_form(authentication_params.merge(action: 'multi', time: Time.now.utc.strftime('%s')))
|
65
|
-
end
|
57
|
+
params = authentication_params.merge(action: 'multi', time: Time.now.utc.strftime('%s'))
|
58
|
+
params.merge!(devMode: true) if LeanplumApi.configuration.developer_mode
|
59
|
+
URI.encode_www_form(params)
|
66
60
|
end
|
67
61
|
end
|
68
62
|
end
|
data/lib/leanplum_api/logger.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
|
-
require 'logger'
|
2
|
-
|
3
1
|
module LeanplumApi
|
4
2
|
class Logger < ::Logger
|
5
3
|
def format_message(severity, timestamp, progname, msg)
|
6
|
-
@
|
4
|
+
@hide_keys ||= [
|
7
5
|
LeanplumApi.configuration.production_key,
|
8
6
|
LeanplumApi.configuration.app_id,
|
9
7
|
LeanplumApi.configuration.data_export_key,
|
@@ -13,11 +11,8 @@ module LeanplumApi
|
|
13
11
|
LeanplumApi.configuration.s3_access_id
|
14
12
|
].compact
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
else
|
19
|
-
"#{timestamp.strftime('%Y-%m-%d %H:%M:%S')} #{severity} #{msg.gsub(/#{@keys.map { |k| Regexp.quote(k) }.join('|')}/, '<HIDDEN_KEY>')}\n"
|
20
|
-
end
|
14
|
+
msg = msg.gsub(/#{@hide_keys.map { |k| Regexp.quote(k) }.join('|')}/, '<HIDDEN_KEY>') unless @hide_keys.empty?
|
15
|
+
"#{timestamp.strftime('%Y-%m-%d %H:%M:%S')} #{severity} #{msg}\n"
|
21
16
|
end
|
22
17
|
end
|
23
18
|
end
|
data/lib/leanplum_api/version.rb
CHANGED
data/lib/leanplum_api.rb
CHANGED
data/spec/api_spec.rb
CHANGED
@@ -17,9 +17,9 @@ describe LeanplumApi::API do
|
|
17
17
|
context 'users' do
|
18
18
|
it 'build_user_attributes_hash' do
|
19
19
|
expect(api.send(:build_user_attributes_hash, users.first)).to eq({
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
userId: 123456,
|
21
|
+
action: 'setUserAttributes',
|
22
|
+
userAttributes: HashWithIndifferentAccess.new(
|
23
23
|
first_name: 'Mike',
|
24
24
|
last_name: 'Jones',
|
25
25
|
gender: 'm',
|
@@ -98,11 +98,11 @@ describe LeanplumApi::API do
|
|
98
98
|
context '#build_event_attributes_hash' do
|
99
99
|
let(:event_hash) do
|
100
100
|
{
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
101
|
+
userId: 12345,
|
102
|
+
time: Time.now.utc.strftime('%s'),
|
103
|
+
action: 'track',
|
104
|
+
event: 'purchase',
|
105
|
+
params: { some_timestamp: timestamp }
|
106
106
|
}
|
107
107
|
end
|
108
108
|
|
@@ -113,11 +113,17 @@ describe LeanplumApi::API do
|
|
113
113
|
|
114
114
|
context 'without user attributes' do
|
115
115
|
context 'valid request' do
|
116
|
-
it 'should successfully track events' do
|
116
|
+
it 'should successfully track session events' do
|
117
117
|
VCR.use_cassette('track_events') do
|
118
118
|
expect { api.track_events(events) }.to_not raise_error
|
119
119
|
end
|
120
120
|
end
|
121
|
+
|
122
|
+
it 'should successfully track non session events' do
|
123
|
+
VCR.use_cassette('track_offline_events') do
|
124
|
+
expect { api.track_events(events, allow_offline: true) }.to_not raise_error
|
125
|
+
end
|
126
|
+
end
|
121
127
|
end
|
122
128
|
|
123
129
|
context 'invalid request' do
|
data/spec/configuration_spec.rb
CHANGED
@@ -7,17 +7,15 @@ describe LeanplumApi do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'should have a default configuration' do
|
10
|
-
expect(LeanplumApi.configuration.
|
10
|
+
expect(LeanplumApi.configuration.api_version.is_a?(String)).to eq(true)
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should allow configuration' do
|
14
14
|
LeanplumApi.configure do |config|
|
15
|
-
config.log_path = 'test/path'
|
16
15
|
config.production_key = 'new_client_key'
|
17
16
|
config.app_id = 'new_app_id'
|
18
17
|
end
|
19
18
|
|
20
|
-
expect(LeanplumApi.configuration.log_path).to eq('test/path')
|
21
19
|
expect(LeanplumApi.configuration.production_key).to eq('new_client_key')
|
22
20
|
expect(LeanplumApi.configuration.app_id).to eq('new_app_id')
|
23
21
|
expect(LeanplumApi.configuration.api_version).to eq(LeanplumApi::Configuration::DEFAULT_LEANPLUM_API_VERSION)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://www.leanplum.com/api?action=multi&apiVersion=1.0.6&appId=<LEANPLUM_APP_ID>&clientKey=<LEANPLUM_PRODUCTION_KEY>&devMode=false&time=1439337600
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"data":[{"action":"track","event":"purchase","userId":12345,"time":"1439337600","allowOffline":true,"params":{"some_timestamp":"2015-05-01
|
9
|
+
01:02:03"}},{"action":"track","event":"purchase_page_view","userId":54321,"time":"1439337000","allowOffline":true}]}'
|
10
|
+
headers:
|
11
|
+
User-Agent:
|
12
|
+
- Faraday v0.9.2
|
13
|
+
Accept-Encoding:
|
14
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
15
|
+
Accept:
|
16
|
+
- "*/*"
|
17
|
+
response:
|
18
|
+
status:
|
19
|
+
code: 200
|
20
|
+
message: OK
|
21
|
+
headers:
|
22
|
+
Access-Control-Allow-Origin:
|
23
|
+
- "*"
|
24
|
+
Content-Type:
|
25
|
+
- application/json
|
26
|
+
Date:
|
27
|
+
- Thu, 28 Jan 2016 14:24:39 GMT
|
28
|
+
Server:
|
29
|
+
- Google Frontend
|
30
|
+
Cache-Control:
|
31
|
+
- private
|
32
|
+
Alt-Svc:
|
33
|
+
- quic=":443"; ma=604800; v="30,29,28,27,26,25"
|
34
|
+
Transfer-Encoding:
|
35
|
+
- chunked
|
36
|
+
body:
|
37
|
+
encoding: UTF-8
|
38
|
+
string: '{"response":[{"success":true,"warning":{"message":"Anomaly detected:
|
39
|
+
time skew. User will be excluded from analytics."}},{"isOffline":true,"success":true,"warning":{"message":"Anomaly
|
40
|
+
detected: time skew. User will be excluded from analytics."}}]}'
|
41
|
+
http_version:
|
42
|
+
recorded_at: Wed, 12 Aug 2015 00:00:00 GMT
|
43
|
+
recorded_with: VCR 2.9.3
|
data/spec/http_spec.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe LeanplumApi::
|
3
|
+
describe LeanplumApi::Connection::Production do
|
4
4
|
context 'regular mode' do
|
5
5
|
it 'should build the right multi url' do
|
6
6
|
http = described_class.new
|
7
|
-
expect(http.send(:authed_multi_param_string)).to eq("appId=#{
|
7
|
+
expect(http.send(:authed_multi_param_string)).to eq("appId=#{LeanplumApi.configuration.app_id}&clientKey=#{LeanplumApi.configuration.production_key}&apiVersion=1.0.6&devMode=false&action=multi&time=#{Time.now.utc.strftime('%s')}")
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
@@ -17,7 +17,7 @@ describe LeanplumApi::HTTP do
|
|
17
17
|
|
18
18
|
it 'should build the right developer mode url' do
|
19
19
|
http = described_class.new
|
20
|
-
expect(http.send(:authed_multi_param_string)).to eq("appId=#{
|
20
|
+
expect(http.send(:authed_multi_param_string)).to eq("appId=#{LeanplumApi.configuration.app_id}&clientKey=#{LeanplumApi.configuration.production_key}&apiVersion=1.0.6&devMode=true&action=multi&time=#{Time.now.utc.strftime('%s')}")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,44 +1,36 @@
|
|
1
|
-
ENV['RAILS_ENV'] = 'test'
|
2
|
-
require 'rspec'
|
3
1
|
require 'leanplum_api'
|
2
|
+
require 'rspec'
|
4
3
|
require 'timecop'
|
5
4
|
require 'webmock'
|
6
|
-
require 'webmock/rspec'
|
7
5
|
require 'vcr'
|
8
6
|
|
9
|
-
|
10
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
7
|
+
DEFAULT_SPEC_KEY = 'JUNKTASTIC_SPASMASTIC'
|
11
8
|
|
12
9
|
RSpec.configure do |config|
|
13
10
|
config.before(:all) do
|
14
|
-
FileUtils.mkdir('log') unless File.exist?('log')
|
15
|
-
|
16
11
|
LeanplumApi.configure do |configuration|
|
17
|
-
configuration.production_key = ENV
|
18
|
-
configuration.app_id = ENV
|
19
|
-
configuration.data_export_key = ENV
|
20
|
-
configuration.content_read_only_key = ENV
|
21
|
-
configuration.development_key = ENV
|
12
|
+
configuration.production_key = ENV['LEANPLUM_PRODUCTION_KEY'] || DEFAULT_SPEC_KEY
|
13
|
+
configuration.app_id = ENV['LEANPLUM_APP_ID'] || DEFAULT_SPEC_KEY
|
14
|
+
configuration.data_export_key = ENV['LEANPLUM_DATA_EXPORT_KEY'] || DEFAULT_SPEC_KEY
|
15
|
+
configuration.content_read_only_key = ENV['LEANPLUM_CONTENT_READ_ONLY_KEY'] || DEFAULT_SPEC_KEY
|
16
|
+
configuration.development_key = ENV['LEANPLUM_DEVELOPMENT_KEY'] || DEFAULT_SPEC_KEY
|
22
17
|
configuration.logger.level = Logger::FATAL
|
23
18
|
end
|
24
19
|
|
20
|
+
# Leanplum requires passing the time in some requests so we freeze it.
|
25
21
|
Timecop.freeze('2015-08-12'.to_time.utc)
|
26
22
|
end
|
27
|
-
|
28
|
-
config.after(:suite) do
|
29
|
-
Dir['log/*.log'].each { |file| File.delete(file) }
|
30
|
-
FileUtils.rmdir('log')
|
31
|
-
end
|
32
23
|
end
|
33
24
|
|
34
25
|
VCR.configure do |c|
|
35
26
|
c.cassette_library_dir = 'spec/fixtures/vcr'
|
36
27
|
c.hook_into :webmock
|
37
|
-
|
38
|
-
c.filter_sensitive_data('<
|
39
|
-
c.filter_sensitive_data('<
|
40
|
-
c.filter_sensitive_data('<
|
41
|
-
c.filter_sensitive_data('<
|
28
|
+
|
29
|
+
c.filter_sensitive_data('<LEANPLUM_PRODUCTION_KEY>') { ENV['LEANPLUM_PRODUCTION_KEY'] || DEFAULT_SPEC_KEY }
|
30
|
+
c.filter_sensitive_data('<LEANPLUM_APP_ID>') { ENV['LEANPLUM_APP_ID'] || DEFAULT_SPEC_KEY }
|
31
|
+
c.filter_sensitive_data('<LEANPLUM_CONTENT_READ_ONLY_KEY>') { ENV['LEANPLUM_CONTENT_READ_ONLY_KEY'] || DEFAULT_SPEC_KEY }
|
32
|
+
c.filter_sensitive_data('<LEANPLUM_DATA_EXPORT_KEY>') { ENV['LEANPLUM_DATA_EXPORT_KEY'] || DEFAULT_SPEC_KEY}
|
33
|
+
c.filter_sensitive_data('<LEANPLUM_DEVELOPMENT_KEY>') { ENV['LEANPLUM_DEVELOPMENT_KEY'] || DEFAULT_SPEC_KEY }
|
42
34
|
|
43
35
|
c.default_cassette_options = {
|
44
36
|
match_requests_on: [:method, :uri, :body]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leanplum_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lumos Labs, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -156,11 +156,11 @@ files:
|
|
156
156
|
- lib/leanplum_api.rb
|
157
157
|
- lib/leanplum_api/api.rb
|
158
158
|
- lib/leanplum_api/configuration.rb
|
159
|
-
- lib/leanplum_api/content_read_only.rb
|
160
|
-
- lib/leanplum_api/data_export.rb
|
161
|
-
- lib/leanplum_api/development.rb
|
159
|
+
- lib/leanplum_api/connections/content_read_only.rb
|
160
|
+
- lib/leanplum_api/connections/data_export.rb
|
161
|
+
- lib/leanplum_api/connections/development.rb
|
162
|
+
- lib/leanplum_api/connections/production.rb
|
162
163
|
- lib/leanplum_api/faraday_middleware/response_validation.rb
|
163
|
-
- lib/leanplum_api/http.rb
|
164
164
|
- lib/leanplum_api/logger.rb
|
165
165
|
- lib/leanplum_api/version.rb
|
166
166
|
- spec/api_spec.rb
|
@@ -179,6 +179,7 @@ files:
|
|
179
179
|
- spec/fixtures/vcr/track_events.yml
|
180
180
|
- spec/fixtures/vcr/track_events_and_attributes.yml
|
181
181
|
- spec/fixtures/vcr/track_events_anomaly_overrider.yml
|
182
|
+
- spec/fixtures/vcr/track_offline_events.yml
|
182
183
|
- spec/http_spec.rb
|
183
184
|
- spec/spec_helper.rb
|
184
185
|
homepage: http://www.github.com/lumoslabs/leanplum_api
|
@@ -222,6 +223,7 @@ test_files:
|
|
222
223
|
- spec/fixtures/vcr/track_events.yml
|
223
224
|
- spec/fixtures/vcr/track_events_and_attributes.yml
|
224
225
|
- spec/fixtures/vcr/track_events_anomaly_overrider.yml
|
226
|
+
- spec/fixtures/vcr/track_offline_events.yml
|
225
227
|
- spec/http_spec.rb
|
226
228
|
- spec/spec_helper.rb
|
227
229
|
has_rdoc:
|