swrve 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ repo_token: zB3skKYGsJ4tILoEEsIEAa7TLRWfJz6y7
2
+ service_name: travis-ci
data/README.md CHANGED
@@ -32,7 +32,7 @@ Swrve.session_end('user uuid')
32
32
 
33
33
  ### Resources
34
34
  ```ruby
35
- json_resource = Swrve.resource(UniqueUserIdentifier, "ab_test_name")
35
+ json_resource = Swrve.resource('user uuid', "ab_test_name")
36
36
  ```
37
37
 
38
38
  [Usage Examples]: #usage-examples
@@ -13,9 +13,13 @@ module Swrve
13
13
 
14
14
  def_delegators :@resource_getter, :resources, :resources_diff, :resource
15
15
  def_delegators :@event_sender, :session_start, :session_end, :create_event, :purchase, :buy_in, :currency_given, :update_user
16
+ def_delegators :@event_sender, :session_start, :session_end, :create_event, :purchase, :buy_in, :currency_given, :update_user
17
+ def_delegators :@config, :build_endpoints, :validate!
16
18
 
17
19
  def configure
18
20
  yield(config) if block_given?
21
+ validate!
22
+ build_endpoints
19
23
  @event_sender = Swrve::Api::Events.new
20
24
  @resource_getter = Swrve::Api::Resources.new
21
25
  end
@@ -11,9 +11,9 @@ module Swrve
11
11
  def_instance_delegator :@api_endpoint, :post
12
12
 
13
13
  def initialize
14
- @api_endpoint = Swrve::Middleware::Http.new(Swrve.config.api_url + "/#{Swrve.config.api_version}")
15
- @web_app_version = Swrve.config.web_app_version
16
- @api_key = Swrve.config.api_key
14
+ @api_endpoint = Swrve::Middleware::Http.new(Swrve.config.api_url + "/#{Swrve.config.api_version}")
15
+ @app_version = Swrve.config.app_version
16
+ @api_key = Swrve.config.api_key
17
17
  end
18
18
 
19
19
  # Starts the user game session
@@ -87,7 +87,7 @@ module Swrve
87
87
  end
88
88
 
89
89
  def query_options(uuid, payload = {})
90
- { api_key: @api_key, app_version: @web_app_version, user: uuid }.merge(payload)
90
+ { api_key: @api_key, app_version: @app_version, user: uuid }.merge(payload)
91
91
  end
92
92
 
93
93
  #The swrve api does not accept nul JSON values
@@ -49,7 +49,7 @@ module Swrve
49
49
  {
50
50
  user: uuid,
51
51
  api_key: Swrve.config.api_key,
52
- app_version: Swrve.config.web_app_version,
52
+ app_version: Swrve.config.app_version,
53
53
  joined: (created_at || Time.now).to_i * 1000
54
54
  }
55
55
  end
@@ -2,17 +2,31 @@ require 'faraday'
2
2
 
3
3
  module Swrve
4
4
  class Configuration
5
- attr_accessor :ab_test_url, :api_url, :web_app_version, :api_key, :local_resource_path, :game_id, :debug_url,
5
+ attr_accessor :ab_test_url, :api_url, :app_version, :api_key, :local_resource_path, :game_id,
6
6
  :load_local_resources, :debug, :http_adapter, :api_version, :resource_timeout
7
+ DEFAULT_API_ENDPOINT = 'api.swrve.com'
8
+ DEFAULT_ABTEST_ENDPOINT = 'abtest.swrve.com'
7
9
 
8
10
  def initialize
9
- @ab_test_url = 'https://abtest.swrve.com'
10
- @api_url = 'https://api.swrve.com'
11
- @web_app_version = '1.0'
12
- @debug_url = 'https://debug.api.swrve.com'
13
- @http_adapter = Faraday.default_adapter
14
- @api_version = 1
11
+ @app_version = '0.0'
12
+ @http_adapter = Faraday.default_adapter
13
+ @api_version = 1
15
14
  @resource_timeout = 4
16
15
  end
16
+
17
+ def build_endpoints
18
+ return if @api_url && @ab_test_url
19
+ @api_url, @ab_test_url = [ "https://#{game_id}.#{DEFAULT_API_ENDPOINT}",
20
+ "https://#{game_id}.#{DEFAULT_ABTEST_ENDPOINT}" ]
21
+ end
22
+
23
+ def validate!
24
+ [:game_id, :api_key].each do |check_valid|
25
+ raise ConfigurationError, "#{check_valid} is a required configuration setting" if self.send(check_valid).nil?
26
+ end
27
+ warn 'app_version is a highly recommended configuration setting, defaulting to 0.0' if app_version == '0.0'
28
+ end
17
29
  end
30
+
31
+ class ConfigurationError < Exception; end
18
32
  end
@@ -1,3 +1,3 @@
1
1
  module Swrve
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -7,7 +7,7 @@ module Swrve
7
7
  subject { Events.new }
8
8
 
9
9
  let(:http_middleware) { mock('http_middleware') }
10
- let(:config) { stub_everything('config', web_app_version: '1', api_version: 1, api_key: 'KEY', api_url: 'http://api_url') }
10
+ let(:config) { stub_everything('config', app_version: '1', api_version: 1, api_key: 'KEY', api_url: 'http://api_url') }
11
11
 
12
12
  before do
13
13
  Swrve.stubs(config: config)
@@ -23,7 +23,7 @@ module Swrve
23
23
  before { Swrve::Middleware::Http.stubs(new: http_middleware) }
24
24
 
25
25
  it 'sets the correct app_version' do
26
- config.expects(:web_app_version)
26
+ config.expects(:app_version)
27
27
 
28
28
  subject
29
29
  end
@@ -3,16 +3,14 @@ require 'swrve/middleware/http'
3
3
  module Swrve
4
4
  module Api
5
5
  describe Resources do
6
-
6
+
7
7
  subject { Resources.new }
8
-
9
- describe '.new' do
10
- let(:config) { stub_everything('config', ab_test_url: 'http://ab_test_url', api_version: 1) }
11
8
 
12
- before do
13
- Swrve.stubs(config: config)
14
- end
9
+ let(:config) { stub_everything('config', ab_test_url: 'http://ab_test_url', api_version: 1) }
15
10
 
11
+ before { Swrve.stubs(config: config) }
12
+
13
+ describe '.new' do
16
14
  it 'Creates a resources endpoint' do
17
15
  Middleware::Http.expects(:new).with([config.ab_test_url, 'api', config.api_version].join('/'))
18
16
 
@@ -27,7 +25,7 @@ module Swrve
27
25
 
28
26
  it 'delegates it to the resources endpoint' do
29
27
  resources_endpoint.expects(:get)
30
-
28
+
31
29
  subject.send(:get)
32
30
  end
33
31
  end
@@ -9,7 +9,11 @@ describe Swrve do
9
9
  before do
10
10
  Swrve::Api::Events.stubs(new: event_sender)
11
11
  Swrve::Api::Resources.stubs(new: resource_getter)
12
- Swrve.configure
12
+ Swrve.configure do |config|
13
+ config.game_id = 1
14
+ config.api_key = 'key'
15
+ config.app_version = '9.9'
16
+ end
13
17
  end
14
18
 
15
19
  describe ".config" do
@@ -18,7 +22,7 @@ describe Swrve do
18
22
  end
19
23
 
20
24
  it 'responds to required configurations' do
21
- [:ab_test_url, :api_url, :web_app_version, :api_key, :local_resource_path, :game_id, :debug_url,
25
+ [:ab_test_url, :api_url, :app_version, :api_key, :local_resource_path, :game_id,
22
26
  :load_local_resources, :debug, :http_adapter].map do |value|
23
27
  Swrve.config.respond_to?(value)
24
28
  end.uniq.should == [true]
@@ -27,10 +31,10 @@ describe Swrve do
27
31
 
28
32
  describe '.configure' do
29
33
 
30
- before { Swrve.configure { |config| config.web_app_version = '11' }}
34
+ before { Swrve.configure { |config| config.app_version = '11' }}
31
35
 
32
36
  it 'should be configurable' do
33
- Swrve.config.web_app_version.should == '11'
37
+ Swrve.config.app_version.should == '11'
34
38
  end
35
39
 
36
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swrve
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-26 00:00:00.000000000 Z
12
+ date: 2013-07-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -254,6 +254,7 @@ executables: []
254
254
  extensions: []
255
255
  extra_rdoc_files: []
256
256
  files:
257
+ - .coveralls.yml
257
258
  - .gitignore
258
259
  - .travis.yml
259
260
  - Gemfile