adjust 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea93c8799fff1c88cc738596e945187354965c01
4
- data.tar.gz: a46542aea7d375d383d338bd5daf8bedb087c558
3
+ metadata.gz: 394b43447458b304090b06fbc93ebf860f94949f
4
+ data.tar.gz: 3176c978c5b815e5e92db9be77b3b2717e733e72
5
5
  SHA512:
6
- metadata.gz: 35a4de163640fb0f1005239bb0e64a09a75e9f1a7dbc9078fbe8797f0c2ca9edb386ae7c7e5dba13c621e975854a66d75985d1501c9ef74629f96e4a4f19bdea
7
- data.tar.gz: 1c74755f03d5ff97656a4e734a1a4c03daa9de830c6896f18ccefe109c8d871dcc698289fd7e34e88d7b234a98b49dce703c07aa1c48c21bd7392d97d8ecbeb6
6
+ metadata.gz: d3a95181c80beb4fe83913ee6b2adb472b1733eecefe8b69a76d2b234dbb072f94a00319e55191613d8334a1483cc669d1b8bc4e164a1f32ce2684b044f543ec
7
+ data.tar.gz: 4230cf55d66d62c0066cb7393a2f9fa8f5d4e8d6a7416041c24f5bae70cdb6c5d0b54a3758f3700ac3b3688a43a5167fb40aeb90040bf2ac4b25eacd976207ed
data/.rubocop.yml CHANGED
@@ -1,2 +1,5 @@
1
1
  Documentation:
2
2
  Enabled: false
3
+
4
+ Metrics/ParameterLists:
5
+ CountKeywordArgs: false
data/.travis.yml CHANGED
@@ -5,3 +5,6 @@ rvm:
5
5
  - rbx-2
6
6
  - ruby-head
7
7
  - jruby-head
8
+
9
+ notifications:
10
+ email: false
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.configure do |config|
25
- config.app_token = '<YOUR_ADJUST_APP_TOKEN>'
26
- config.environment = '<production|sandbox>'
27
- end
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(token: :token, idfa: :idfa).track!
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(token: :token, revenue: 1.25, currency: 'USD|CAD|EUR', idfa: :idfa).track!
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
- extend Forwardable
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
- def_delegators :configuration, :app_token, :environment
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 'forwardable'
1
+ require 'yaml'
2
+ require 'erb'
2
3
 
3
4
  module Adjust
4
5
  module Core
5
6
  class Configuration
6
- attr_accessor :app_token, :environment
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 ||= :sandbox
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 app_token
13
- fail MissingAppTokenError unless @app_token
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
- @app_token
42
+ def read(path)
43
+ File.read path
16
44
  end
17
45
 
18
- def to_hash
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
@@ -1,3 +1,3 @@
1
- require 'adjust/core/errors'
1
+ require 'adjust/core/tokens'
2
2
  require 'adjust/core/configurable'
3
3
  require 'adjust/core/configuration'
@@ -1,3 +1,3 @@
1
1
  module Adjust
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
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(token:, time: current_time, **device)
13
- Clients::Event.new \
14
- event_token: token,
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(token:, revenue:, currency:, time: current_time, **device)
22
- Clients::Revenue.new \
23
- event_token: token,
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
- context '#environment' do
7
- it 'defaults to sandbox' do
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
- it 'can be overriden' do
12
- subject.environment = :production
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
- expect(subject.environment).to eq :production
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
- context '#app_token' do
19
- it 'raises an exception if not set' do
20
- expect { subject.app_token }.to raise_error(MissingAppTokenError)
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
- it 'can be set' do
24
- subject.app_token = :app_token
25
-
26
- expect(subject.app_token).to eq :app_token
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
- context '#to_hash' do
31
- before { subject.app_token = :app_token }
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
- it 'returns configs as a hash' do
34
- expect(subject.to_hash).to eq \
35
- environment: :sandbox,
36
- app_token: :app_token
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'
@@ -4,7 +4,8 @@ describe 'Sending a revenue' do
4
4
  context 'with success', vcr: { cassette_name: :revenue_success } do
5
5
  subject do
6
6
  Adjust.revenue \
7
- token: 'fbv8to',
7
+ app: :test_app,
8
+ event: :event2,
8
9
  revenue: 2.0,
9
10
  currency: 'CAD',
10
11
  idfa: ENV['ADJUST_TEST_IDFA']
@@ -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 { Adjust.event(token: 'tawmb9', idfa: ENV['ADJUST_TEST_IDFA']) }
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
@@ -10,6 +10,4 @@ Dotenv.load
10
10
  require 'adjust'
11
11
  require 'support/vcr'
12
12
 
13
- Adjust.configure do |config|
14
- config.app_token = ENV['ADJUST_APP_TOKEN']
15
- end
13
+ Adjust.load('spec/fixtures/config/adjust.yml', environment: 'integration')
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.2
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-06 00:00:00.000000000 Z
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/errors.rb
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
@@ -1,6 +0,0 @@
1
- module Adjust
2
- module Core
3
- class MissingAppTokenError < StandardError
4
- end
5
- end
6
- end