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 +4 -4
- data/lib/tracksale/campaign.rb +8 -3
- data/lib/tracksale/client.rb +4 -3
- data/test/test_tracksale_campaign.rb +34 -4
- data/tracksale.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bc9497560ff278fd545941e496e823648e3be86a
|
|
4
|
+
data.tar.gz: 331fb28a461e177c9c5c52775424080d0403d4d9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 744ff04e223a033848675a63c5f5a98812ec1636fbadcf82576c8af3cebfc59c8237306d1d693faa02afead7da73337c1fa131f67da6ef4e603fbea92e93fc41
|
|
7
|
+
data.tar.gz: a5f76e98b0c85a8d61216c9dc5b7d6c4df1d2bd01d21a79149d61e67c2ff6fad8ba24fa97b51aae059f245c9dde54eba238040842f6b46d15bc1674df6b30c04
|
data/lib/tracksale/campaign.rb
CHANGED
|
@@ -3,11 +3,16 @@ module Tracksale
|
|
|
3
3
|
attr_accessor :name, :code, :score
|
|
4
4
|
|
|
5
5
|
def schedule_dispatch(body)
|
|
6
|
-
|
|
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)
|
data/lib/tracksale/client.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
-
'"
|
|
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
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.
|
|
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-
|
|
11
|
+
date: 2018-06-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: byebug
|