adjust 0.0.2 → 0.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/.rubocop.yml +3 -0
- data/.travis.yml +3 -0
- data/README.md +32 -6
- data/lib/adjust/core/configurable.rb +9 -5
- data/lib/adjust/core/configuration.rb +36 -11
- data/lib/adjust/core/tokens.rb +35 -0
- data/lib/adjust/core.rb +1 -1
- data/lib/adjust/version.rb +1 -1
- data/lib/adjust.rb +8 -10
- data/spec/core/configuration_spec.rb +40 -22
- data/spec/fixtures/config/adjust.yml +33 -0
- data/spec/integration/sending_a_revenue_spec.rb +2 -1
- data/spec/integration/sending_an_event_spec.rb +6 -1
- data/spec/spec_helper.rb +1 -3
- metadata +5 -3
- data/lib/adjust/core/errors.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 394b43447458b304090b06fbc93ebf860f94949f
|
4
|
+
data.tar.gz: 3176c978c5b815e5e92db9be77b3b2717e733e72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3a95181c80beb4fe83913ee6b2adb472b1733eecefe8b69a76d2b234dbb072f94a00319e55191613d8334a1483cc669d1b8bc4e164a1f32ce2684b044f543ec
|
7
|
+
data.tar.gz: 4230cf55d66d62c0066cb7393a2f9fa8f5d4e8d6a7416041c24f5bae70cdb6c5d0b54a3758f3700ac3b3688a43a5167fb40aeb90040bf2ac4b25eacd976207ed
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -20,11 +20,37 @@ This gem is meant for use with server to server integration with Adjust. More in
|
|
20
20
|
|
21
21
|
##### Configuration
|
22
22
|
|
23
|
+
By default the configurations will be read from `config/adjust.yml`. Also of note the environment loaded will be that of RACK_ENV, RAILS_ENV or as a last resort default of 'development'.
|
24
|
+
|
25
|
+
Example config:
|
26
|
+
```yaml
|
27
|
+
development:
|
28
|
+
environment: sandbox
|
29
|
+
dev_app:
|
30
|
+
app_token: app_token
|
31
|
+
event1:
|
32
|
+
event_token: event_token
|
33
|
+
```
|
34
|
+
|
35
|
+
We would then be able to refer to the token using the key given in the config:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
Adjust.event(app: :dev_app, event: :event1, idfa: :idfa).track!
|
39
|
+
```
|
40
|
+
|
41
|
+
Or by their tokens
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
Adjust.event(app: :app_token, event: :event_token, idfa: :idfa).track!
|
45
|
+
```
|
46
|
+
|
47
|
+
Loading the configurations
|
48
|
+
|
23
49
|
```ruby
|
24
|
-
Adjust.
|
25
|
-
|
26
|
-
|
27
|
-
|
50
|
+
Adjust.load(environment: 'test') # => {...}
|
51
|
+
Adjust.load('path/to/adjust.yml') # => {...}
|
52
|
+
Adjust.load('path/to/adjust.yml', environment: 'staging') # => {...}
|
53
|
+
|
28
54
|
```
|
29
55
|
|
30
56
|
##### Event tracking
|
@@ -32,7 +58,7 @@ end
|
|
32
58
|
*`idfa` can also be any other values such as `android_id` or `gps_adid` check Adjust's documentation for details.*
|
33
59
|
|
34
60
|
```ruby
|
35
|
-
Adjust.event(
|
61
|
+
Adjust.event(app: :app, event: :event, idfa: :idfa).track!
|
36
62
|
```
|
37
63
|
|
38
64
|
|
@@ -41,7 +67,7 @@ Adjust.event(token: :token, idfa: :idfa).track!
|
|
41
67
|
*`idfa` can also be any other values such as `android_id` or `gps_adid` check Adjust's documentation for details.*
|
42
68
|
|
43
69
|
```ruby
|
44
|
-
Adjust.revenue(
|
70
|
+
Adjust.revenue(app: :app, event: :event, revenue: 1.25, currency: 'USD|CAD|EUR', idfa: :idfa).track!
|
45
71
|
```
|
46
72
|
|
47
73
|
## Contributing
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module Adjust
|
2
2
|
module Core
|
3
3
|
module Configurable
|
4
|
-
|
5
|
-
|
6
|
-
def configure
|
7
|
-
yield configuration
|
4
|
+
def load(path = 'config/adjust.yml', environment: nil)
|
5
|
+
configuration.load path, environment: environment
|
8
6
|
end
|
9
7
|
|
10
8
|
def configuration
|
@@ -13,7 +11,13 @@ module Adjust
|
|
13
11
|
|
14
12
|
private
|
15
13
|
|
16
|
-
|
14
|
+
def environment
|
15
|
+
configuration.active_environment
|
16
|
+
end
|
17
|
+
|
18
|
+
def tokens(app, event)
|
19
|
+
configuration.tokens(app, event)
|
20
|
+
end
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
@@ -1,25 +1,50 @@
|
|
1
|
-
require '
|
1
|
+
require 'yaml'
|
2
|
+
require 'erb'
|
2
3
|
|
3
4
|
module Adjust
|
4
5
|
module Core
|
5
6
|
class Configuration
|
6
|
-
|
7
|
+
def load(path, environment: nil)
|
8
|
+
@environment = environment || default_environment
|
9
|
+
@configurations = read_configurations path
|
10
|
+
end
|
7
11
|
|
8
12
|
def environment
|
9
|
-
@environment ||=
|
13
|
+
@environment ||= default_environment
|
14
|
+
end
|
15
|
+
|
16
|
+
def configurations
|
17
|
+
@configurations ||= read_configurations
|
18
|
+
end
|
19
|
+
|
20
|
+
def active
|
21
|
+
configurations[environment]
|
22
|
+
end
|
23
|
+
|
24
|
+
def active_environment
|
25
|
+
active['environment']
|
10
26
|
end
|
11
27
|
|
12
|
-
def
|
13
|
-
|
28
|
+
def tokens(app, event)
|
29
|
+
Tokens.new(app, event, active).find
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def default_environment
|
35
|
+
ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
|
36
|
+
end
|
37
|
+
|
38
|
+
def read_configurations(path = 'config/adjust.yml')
|
39
|
+
YAML.load parse read path
|
40
|
+
end
|
14
41
|
|
15
|
-
|
42
|
+
def read(path)
|
43
|
+
File.read path
|
16
44
|
end
|
17
45
|
|
18
|
-
def
|
19
|
-
|
20
|
-
environment: environment,
|
21
|
-
app_token: app_token
|
22
|
-
}
|
46
|
+
def parse(file)
|
47
|
+
ERB.new(file).result
|
23
48
|
end
|
24
49
|
end
|
25
50
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Adjust
|
2
|
+
module Core
|
3
|
+
class Tokens
|
4
|
+
def initialize(app, event, config)
|
5
|
+
@app = app.to_s
|
6
|
+
@event = event.to_s
|
7
|
+
@config = config[@app]
|
8
|
+
end
|
9
|
+
|
10
|
+
def find
|
11
|
+
{ app_token: app_token, event_token: event_token }
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
attr_reader :app, :event, :config
|
17
|
+
|
18
|
+
def app_token
|
19
|
+
return app unless config
|
20
|
+
|
21
|
+
config.fetch('app_token') { app }
|
22
|
+
end
|
23
|
+
|
24
|
+
def event_token
|
25
|
+
return event unless config
|
26
|
+
|
27
|
+
if config.include?(event)
|
28
|
+
config[event].fetch('event_token') { event }
|
29
|
+
else
|
30
|
+
event
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/adjust/core.rb
CHANGED
data/lib/adjust/version.rb
CHANGED
data/lib/adjust.rb
CHANGED
@@ -9,24 +9,22 @@ module Adjust
|
|
9
9
|
class << self
|
10
10
|
include Core::Configurable
|
11
11
|
|
12
|
-
def event(
|
13
|
-
Clients::Event.new
|
14
|
-
|
15
|
-
app_token: app_token,
|
12
|
+
def event(app:, event:, time: current_time, **device)
|
13
|
+
Clients::Event.new(
|
14
|
+
**tokens(app, event),
|
16
15
|
environment: environment,
|
17
16
|
created_at: time,
|
18
|
-
**device
|
17
|
+
**device)
|
19
18
|
end
|
20
19
|
|
21
|
-
def revenue(
|
22
|
-
Clients::Revenue.new
|
23
|
-
|
24
|
-
app_token: app_token,
|
20
|
+
def revenue(app:, event:, revenue:, currency:, time: current_time, **device)
|
21
|
+
Clients::Revenue.new(
|
22
|
+
**tokens(app, event),
|
25
23
|
environment: environment,
|
26
24
|
created_at: time,
|
27
25
|
revenue: revenue,
|
28
26
|
currency: currency,
|
29
|
-
**device
|
27
|
+
**device)
|
30
28
|
end
|
31
29
|
|
32
30
|
def current_time
|
@@ -3,37 +3,55 @@ require 'spec_helper'
|
|
3
3
|
module Adjust
|
4
4
|
module Core
|
5
5
|
describe Configuration do
|
6
|
-
|
7
|
-
|
8
|
-
expect(subject.environment).to eq :sandbox
|
9
|
-
end
|
6
|
+
let(:path) { 'spec/fixtures/config/adjust.yml' }
|
7
|
+
subject(:config) { Configuration.new }
|
10
8
|
|
11
|
-
|
12
|
-
|
9
|
+
context 'with an explicit environment' do
|
10
|
+
subject(:load!) { config.load(path, environment: 'test') }
|
11
|
+
before { expect { load! }.to_not raise_error }
|
13
12
|
|
14
|
-
|
13
|
+
describe '#load' do
|
14
|
+
it 'sets an environment' do
|
15
|
+
expect(config.environment).to eq 'test'
|
16
|
+
end
|
15
17
|
end
|
16
|
-
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
describe '#configurations' do
|
20
|
+
it 'caches the configurations' do
|
21
|
+
expect(config.configurations).to include 'test'
|
22
|
+
end
|
21
23
|
end
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
describe '#active' do
|
26
|
+
it 'contains the configuration for current env' do
|
27
|
+
expect(config.active).to include 'test_app'
|
28
|
+
end
|
27
29
|
end
|
28
|
-
end
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
describe '#active_environment' do
|
32
|
+
it 'returns the adjust environment for current env' do
|
33
|
+
expect(config.active_environment).to eq 'sandbox'
|
34
|
+
end
|
35
|
+
end
|
32
36
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
+
describe '#active_tokens' do
|
38
|
+
it 'returns arguments if app was not matched' do
|
39
|
+
expect(config.tokens('foo', 'bar')).to eq \
|
40
|
+
app_token: 'foo',
|
41
|
+
event_token: 'bar'
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns app_token if app matched and event not matched' do
|
45
|
+
expect(config.tokens('test_app', 'bar')).to eq \
|
46
|
+
app_token: 'app_token',
|
47
|
+
event_token: 'bar'
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'returns tokens if app matched and event matched' do
|
51
|
+
expect(config.tokens('test_app', 'event1')).to eq \
|
52
|
+
app_token: 'app_token',
|
53
|
+
event_token: 'event_token'
|
54
|
+
end
|
37
55
|
end
|
38
56
|
end
|
39
57
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
development:
|
2
|
+
environment: 'sandbox'
|
3
|
+
|
4
|
+
dev_app:
|
5
|
+
app_token: 'app_token'
|
6
|
+
event1:
|
7
|
+
event_token: 'event_token'
|
8
|
+
|
9
|
+
test:
|
10
|
+
environment: 'sandbox'
|
11
|
+
|
12
|
+
test_app:
|
13
|
+
app_token: 'app_token'
|
14
|
+
event1:
|
15
|
+
event_token: 'event_token'
|
16
|
+
|
17
|
+
integration:
|
18
|
+
environment: 'sandbox'
|
19
|
+
|
20
|
+
test_app:
|
21
|
+
app_token: <%= ENV['ADJUST_APP_TOKEN'] %>
|
22
|
+
event1:
|
23
|
+
event_token: 'tawmb9'
|
24
|
+
event2:
|
25
|
+
event_token: 'fbv8to'
|
26
|
+
|
27
|
+
production:
|
28
|
+
environment: 'production'
|
29
|
+
|
30
|
+
prod_app:
|
31
|
+
app_token: 'app_token'
|
32
|
+
event1:
|
33
|
+
event_token: 'event_token'
|
@@ -2,7 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'Sending an event' do
|
4
4
|
context 'with success', vcr: { cassette_name: :event_success } do
|
5
|
-
subject
|
5
|
+
subject do
|
6
|
+
Adjust.event \
|
7
|
+
app: :test_app,
|
8
|
+
event: :event1,
|
9
|
+
idfa: ENV['ADJUST_TEST_IDFA']
|
10
|
+
end
|
6
11
|
|
7
12
|
it 'succeeds' do
|
8
13
|
expect(subject.track!).to be_success
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adjust
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hugo Bastien
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -189,7 +189,7 @@ files:
|
|
189
189
|
- lib/adjust/core.rb
|
190
190
|
- lib/adjust/core/configurable.rb
|
191
191
|
- lib/adjust/core/configuration.rb
|
192
|
-
- lib/adjust/core/
|
192
|
+
- lib/adjust/core/tokens.rb
|
193
193
|
- lib/adjust/representers.rb
|
194
194
|
- lib/adjust/representers/event_representer.rb
|
195
195
|
- lib/adjust/transport/faraday.rb
|
@@ -197,6 +197,7 @@ files:
|
|
197
197
|
- spec/clients/event_spec.rb
|
198
198
|
- spec/clients/revenue_spec.rb
|
199
199
|
- spec/core/configuration_spec.rb
|
200
|
+
- spec/fixtures/config/adjust.yml
|
200
201
|
- spec/fixtures/responses/event_success.yml
|
201
202
|
- spec/fixtures/responses/revenue_success.yml
|
202
203
|
- spec/integration/sending_a_revenue_spec.rb
|
@@ -231,6 +232,7 @@ test_files:
|
|
231
232
|
- spec/clients/event_spec.rb
|
232
233
|
- spec/clients/revenue_spec.rb
|
233
234
|
- spec/core/configuration_spec.rb
|
235
|
+
- spec/fixtures/config/adjust.yml
|
234
236
|
- spec/fixtures/responses/event_success.yml
|
235
237
|
- spec/fixtures/responses/revenue_success.yml
|
236
238
|
- spec/integration/sending_a_revenue_spec.rb
|