tracksale 0.0.3 → 0.0.4

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc9497560ff278fd545941e496e823648e3be86a
4
- data.tar.gz: 331fb28a461e177c9c5c52775424080d0403d4d9
3
+ metadata.gz: 76d53474a5c3b1fa9024934278723ff0c662f7ed
4
+ data.tar.gz: b6f11b4978a21bde64d3be153d23756761a398a0
5
5
  SHA512:
6
- metadata.gz: 744ff04e223a033848675a63c5f5a98812ec1636fbadcf82576c8af3cebfc59c8237306d1d693faa02afead7da73337c1fa131f67da6ef4e603fbea92e93fc41
7
- data.tar.gz: a5f76e98b0c85a8d61216c9dc5b7d6c4df1d2bd01d21a79149d61e67c2ff6fad8ba24fa97b51aae059f245c9dde54eba238040842f6b46d15bc1674df6b30c04
6
+ metadata.gz: 10747530be997594f6037c8ca6052fa27dd5d96adfe3c3c76e193d50effdea0200ca5201a1283e08f3827adf2cc98931835cdda320b891be1a2f6667dc0a33ad
7
+ data.tar.gz: 966369ca3f566efd8dd7e8db0a85fd997f411614822c7805aff934dddc378255c66b57550131ffa002611177e589b1ff7bd08cb2b3b5680b47b9509bc6fcb22c
@@ -42,7 +42,7 @@ module Tracksale
42
42
  end
43
43
 
44
44
  def self.client
45
- Tracksale::Client.new
45
+ Tracksale.configuration.client.new
46
46
  end
47
47
  end
48
48
  end
@@ -1,5 +1,16 @@
1
1
  module Tracksale
2
2
  class Configuration
3
3
  attr_accessor :key
4
+ attr_accessor :client
5
+
6
+ def client
7
+ @client ||= Tracksale::Client
8
+ end
9
+
10
+ def force_dummy_client(on=true)
11
+ @client = on ?
12
+ Tracksale::DummyClient :
13
+ Tracksale::Client
14
+ end
4
15
  end
5
16
  end
@@ -0,0 +1,34 @@
1
+ module Tracksale
2
+ class DummyClient
3
+ class << self
4
+ attr_accessor :response #Easy way to force a response
5
+ end
6
+
7
+ def initialize
8
+ puts 'running tracksale dummy client, do not expect real responses.' if $DEBUG
9
+ end
10
+
11
+ def get(endpoint_path, extra_headers = {}) #maintaining the same method signature as the real client
12
+ self.response
13
+ end
14
+
15
+ def post(endpoint_path, body, extra_headers = {}) #maintaining the same method signature as the real client
16
+ self.response
17
+ end
18
+
19
+ def default_response_object
20
+ response = {}
21
+
22
+ def response.success?
23
+ true
24
+ end
25
+
26
+ return response
27
+ end
28
+
29
+ def response
30
+ #definies a default valid response unless explicity defined.
31
+ self.class.response || default_response_object
32
+ end
33
+ end
34
+ end
data/lib/tracksale.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'httparty'
2
2
  require 'tracksale/configuration'
3
3
  require 'tracksale/client'
4
+ require 'tracksale/dummy_client'
4
5
  require 'tracksale/campaign'
5
6
 
6
7
  module Tracksale
@@ -2,11 +2,18 @@ require 'minitest/autorun'
2
2
  require 'tracksale'
3
3
 
4
4
  class TracksaleTest < Minitest::Test
5
- def test_configure
5
+ def test_configure_key
6
6
  Tracksale.configure do |config|
7
7
  config.key = 'foobar'
8
8
  end
9
9
 
10
10
  assert_equal 'foobar', Tracksale::Client.new.key
11
11
  end
12
+
13
+ def test_configure_client
14
+ Tracksale.configure {|c| c.force_dummy_client(false) } #default
15
+ assert_equal Tracksale::Client, Tracksale.configuration.client
16
+ Tracksale.configure {|c| c.force_dummy_client }
17
+ assert_equal Tracksale::DummyClient, Tracksale.configuration.client
18
+ end
12
19
  end
@@ -2,16 +2,16 @@ require 'minitest/autorun'
2
2
  require 'webmock/minitest'
3
3
  require 'tracksale'
4
4
 
5
- class TracksaleCampaignTest < Minitest::Test
5
+ class TestTracksaleCampaign < Minitest::Test
6
6
  def setup
7
- Tracksale.configure { |c| c.key = 'foobar' }
7
+ Tracksale.configure { |c| c.key = 'foobar'; c.force_dummy_client(false) }
8
8
 
9
9
  stub_request(:get, 'http://api.tracksale.co/v2/campaign')
10
10
  .with(headers: { 'authorization' => 'bearer foobar' })
11
11
  .to_return(body: '[{"name":"random - name",' \
12
- '"code":1234, "detractors":1,' \
13
- '"passives":2, "promoters":3 }]',
14
- headers: { content_type: 'application/json' }, status: 200)
12
+ '"code":1234, "detractors":1,' \
13
+ '"passives":2, "promoters":3 }]',
14
+ headers: { content_type: 'application/json' }, status: 200)
15
15
 
16
16
  stub_dispatch(121, 200, '{ "msg": "scheduled" }')
17
17
  stub_dispatch(123, 400, '{ "error": "Invalid Time"}')
@@ -22,9 +22,9 @@ class TracksaleCampaignTest < Minitest::Test
22
22
  url = 'http://api.tracksale.co/v2/campaign/' + code.to_s + '/dispatch'
23
23
  stub_request(:post, url)
24
24
  .with(headers: { 'authorization' => 'bearer foobar',
25
- 'content-type' => 'application/json' }, body: '"foo"')
25
+ 'content-type' => 'application/json' }, body: '"foo"')
26
26
  .to_return(body: body,
27
- headers: { content_type: 'application/json' }, status: status)
27
+ headers: { content_type: 'application/json' }, status: status)
28
28
  end
29
29
 
30
30
  def test_dispatch_successful
@@ -0,0 +1,28 @@
1
+ class TestTracksaleDummyClient < Minitest::Test
2
+ def setup
3
+ Tracksale.configure { |c| c.force_dummy_client }
4
+ end
5
+
6
+ def test_campaign_all_dummy
7
+ assert Tracksale::Campaign.all.is_a? Array
8
+ assert_equal [], Tracksale::Campaign.all
9
+ end
10
+
11
+ def test_campaign_find_by_name_dummy
12
+ assert_nil Tracksale::Campaign.find_by_name('foobar')
13
+ end
14
+
15
+ def test_campaign_dispatch_dummy
16
+ assert_equal Hash.new, Tracksale::Campaign.schedule_dispatch('code','body')
17
+ end
18
+
19
+ def test_allow_explict_response
20
+ response = Object.new
21
+ response.send :define_singleton_method, :success?, proc {true}
22
+ Tracksale::DummyClient.response=response
23
+
24
+ assert_equal response,Tracksale::Campaign.schedule_dispatch('code','body')
25
+
26
+ Tracksale::DummyClient.response=nil # revert to default
27
+ end
28
+ end
data/tracksale.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'tracksale'
3
- s.version = '0.0.3'
3
+ s.version = '0.0.4'
4
4
  s.licenses = ['MIT']
5
5
  s.summary = 'Integration gem for tracksale api v2'
6
6
  s.description = 'Integration gem for tracksale api v2'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tracksale
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Estudar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-15 00:00:00.000000000 Z
11
+ date: 2018-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -95,8 +95,10 @@ files:
95
95
  - lib/tracksale/campaign.rb
96
96
  - lib/tracksale/client.rb
97
97
  - lib/tracksale/configuration.rb
98
+ - lib/tracksale/dummy_client.rb
98
99
  - test/test_tracksale.rb
99
100
  - test/test_tracksale_campaign.rb
101
+ - test/test_tracksale_dummyclient.rb
100
102
  - tracksale.gemspec
101
103
  homepage: https://github.com/estudar/tracksale
102
104
  licenses:
@@ -126,3 +128,4 @@ summary: Integration gem for tracksale api v2
126
128
  test_files:
127
129
  - test/test_tracksale.rb
128
130
  - test/test_tracksale_campaign.rb
131
+ - test/test_tracksale_dummyclient.rb