tracksale 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4ee4955e64c757ed13403bdc85f6de1f94fbd18
4
- data.tar.gz: 8ace256d58b4f8e8b92df5d6f93322078e8163cb
3
+ metadata.gz: bc9497560ff278fd545941e496e823648e3be86a
4
+ data.tar.gz: 331fb28a461e177c9c5c52775424080d0403d4d9
5
5
  SHA512:
6
- metadata.gz: fc9914aa27e379689092d0fe4aabb26db35cee8f68b39fde6065b0ea4d56681a91319c35211437cacec0ffea04eed1aef2b6355681de3958765cf8691a3931f2
7
- data.tar.gz: dc73293c9a5f32fd2d4da32c171aad6e75611d6beebfafdb7c4bc5746f082473808c883b69a389fd17e149a73f08444769c83b2dd42f81f815cbeac9f604ff8c
6
+ metadata.gz: 744ff04e223a033848675a63c5f5a98812ec1636fbadcf82576c8af3cebfc59c8237306d1d693faa02afead7da73337c1fa131f67da6ef4e603fbea92e93fc41
7
+ data.tar.gz: a5f76e98b0c85a8d61216c9dc5b7d6c4df1d2bd01d21a79149d61e67c2ff6fad8ba24fa97b51aae059f245c9dde54eba238040842f6b46d15bc1674df6b30c04
@@ -3,11 +3,16 @@ module Tracksale
3
3
  attr_accessor :name, :code, :score
4
4
 
5
5
  def schedule_dispatch(body)
6
- Tracksale::Campaign.client.post('campaign/'+self.code.to_s+'/dispatch',body)
6
+ self.class.schedule_dispatch(code, body)
7
7
  end
8
8
 
9
- def self.schedule_dispatch(code,body)
10
- client.post('campaign/'+code.to_s+'/dispatch',body)
9
+ def self.schedule_dispatch(code, body)
10
+ response = client.post('campaign/' + code.to_s + '/dispatch', body)
11
+
12
+ return response if response.success?
13
+
14
+ raise ArgumentError, response['error'] if response['error']
15
+ raise response.response.error!
11
16
  end
12
17
 
13
18
  def self.find_by_name(name)
@@ -25,12 +25,13 @@ module Tracksale
25
25
  end
26
26
 
27
27
  def post(endpoint_path, body, extra_headers = {})
28
- headers = { 'authorization' => 'bearer ' + key ,
29
- 'Content-Type' => 'application/json'}.merge(extra_headers)
28
+ headers = { 'authorization' => 'bearer ' + key,
29
+ 'Content-Type' => 'application/json' }.merge(extra_headers)
30
30
 
31
31
  headers[:debug_output] = STDOUT if $DEBUG
32
32
 
33
- self.class.post(default_path + endpoint_path, headers: headers, body: body.to_json)
33
+ endpoint = default_path + endpoint_path
34
+ self.class.post(endpoint, headers: headers, body: body.to_json)
34
35
  end
35
36
  end
36
37
  end
@@ -9,11 +9,41 @@ class TracksaleCampaignTest < Minitest::Test
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,' \
13
- '"detractors":1,' \
14
- '"passives":2,' \
15
- '"promoters":3 }]',
12
+ '"code":1234, "detractors":1,' \
13
+ '"passives":2, "promoters":3 }]',
16
14
  headers: { content_type: 'application/json' }, status: 200)
15
+
16
+ stub_dispatch(121, 200, '{ "msg": "scheduled" }')
17
+ stub_dispatch(123, 400, '{ "error": "Invalid Time"}')
18
+ stub_dispatch(124, 500, '{ "foo": "bar"}')
19
+ end
20
+
21
+ def stub_dispatch(code, status, body)
22
+ url = 'http://api.tracksale.co/v2/campaign/' + code.to_s + '/dispatch'
23
+ stub_request(:post, url)
24
+ .with(headers: { 'authorization' => 'bearer foobar',
25
+ 'content-type' => 'application/json' }, body: '"foo"')
26
+ .to_return(body: body,
27
+ headers: { content_type: 'application/json' }, status: status)
28
+ end
29
+
30
+ def test_dispatch_successful
31
+ dispatch = Tracksale::Campaign.schedule_dispatch(121, 'foo')
32
+ assert_equal dispatch['msg'], 'scheduled'
33
+ end
34
+
35
+ def test_dispatch_inavlid_params_error
36
+ error = assert_raises ArgumentError do
37
+ Tracksale::Campaign.schedule_dispatch(123, 'foo')
38
+ end
39
+ assert_match(/Invalid Time/, error.message)
40
+ end
41
+
42
+ def test_dispatch_server_error
43
+ error = assert_raises Net::HTTPFatalError do
44
+ Tracksale::Campaign.schedule_dispatch(124, 'foo')
45
+ end
46
+ assert_match(/500/, error.message)
17
47
  end
18
48
 
19
49
  def test_return_right_amount_of_items
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.2'
3
+ s.version = '0.0.3'
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.2
4
+ version: 0.0.3
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-08 00:00:00.000000000 Z
11
+ date: 2018-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug