tracksale 0.0.4 → 0.0.5
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/README.md +31 -0
- data/lib/tracksale/answer.rb +71 -0
- data/lib/tracksale/campaign.rb +6 -0
- data/lib/tracksale/configuration.rb +1 -1
- data/lib/tracksale/dummy_client.rb +9 -7
- data/lib/tracksale.rb +1 -0
- data/test/test_tracksale.rb +2 -2
- data/test/test_tracksale_answer.rb +88 -0
- data/test/test_tracksale_campaign.rb +18 -6
- data/test/test_tracksale_dummyclient.rb +6 -6
- data/tracksale.gemspec +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: af7f8274dff3ad33e55832a593f15e4965e99419
|
|
4
|
+
data.tar.gz: c2d60b9ee85c3ceea683c2eef7dcf67a3234173e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 392b16321685edc724ec7554d4d44fbd34f7c8762ed3e67a11602ff5e887523d0d484abb9767252987cdbf195c4eb726dc5cf39f20fc7527e635c5abee48178f
|
|
7
|
+
data.tar.gz: bcf6f73d574e113f7b1f8f16059c74a35309b2cf8d65c616d368d789987048e91c916af326d506aacfa66e1dfe5a658d8ad025439ecb9117be24a0b1734bf746
|
data/README.md
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
[](https://badge.fury.io/rb/tracksale)
|
|
1
2
|
# Tracksale
|
|
2
3
|
Tracksale v2 API integration gem.
|
|
3
4
|
|
|
@@ -17,7 +18,37 @@ Tracksale.configure do |config|
|
|
|
17
18
|
end
|
|
18
19
|
```
|
|
19
20
|
|
|
21
|
+
If you want to run the dummy client, which prevents the gem from accessing the API (useful for developers without tracksale credential access) you can:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
Tracksale.configure do |config|
|
|
25
|
+
config.force_dummy_client
|
|
26
|
+
end
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Also the dummy client accepts a default response that you can set and may be useful for some testings as in:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
> Tracksale::DummyClient.response = nil # default value
|
|
33
|
+
=> nil
|
|
34
|
+
> Tracksale::Campaign.all
|
|
35
|
+
=> []
|
|
36
|
+
|
|
37
|
+
> Tracksale::DummyClient.response = [{
|
|
38
|
+
'name' => 'foo',
|
|
39
|
+
'code' => 'bar',
|
|
40
|
+
'detractors' => '0' ,
|
|
41
|
+
'passives' => 1,
|
|
42
|
+
'promoters' => 2
|
|
43
|
+
}]
|
|
44
|
+
=> [{"name"=>"foo", "code"=>"bar", "detractors"=>"0", "passives"=>1, "promoters"=>2}]
|
|
45
|
+
> Tracksale::Campaign.all
|
|
46
|
+
=> [#<Tracksale::Campaign:0x0055ea11d2b738 @code="bar", @name="foo", @score={:detractors=>"0", :passives=>1, :promoters=>2}>]
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
|
|
20
50
|
Key generation instructions can be found on the official documentation at: https://api.tracksale.co/?lang=en#submenu1
|
|
51
|
+
|
|
21
52
|
## Using
|
|
22
53
|
|
|
23
54
|
After configuration you should be able to use it easily as in
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
module Tracksale
|
|
2
|
+
class Answer
|
|
3
|
+
LIMIT = -1
|
|
4
|
+
|
|
5
|
+
attr_accessor :time, :type, :name,
|
|
6
|
+
:email, :identification, :phone,
|
|
7
|
+
:nps_answer, :last_nps_answer, :nps_comment,
|
|
8
|
+
:campaign_name, :campaign_code, :id,
|
|
9
|
+
:deadline, :elapsed_time, :dispatch_time,
|
|
10
|
+
:reminder_time, :status, :tags,
|
|
11
|
+
:categories, :justifications
|
|
12
|
+
|
|
13
|
+
def campaign
|
|
14
|
+
Tracksale::Campaign.find_by_code(campaign_code)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class << self
|
|
18
|
+
def all
|
|
19
|
+
raw_all.map { |answer| create_from_response(answer) }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def create_from_response(raw_response)
|
|
23
|
+
new.tap do |answer|
|
|
24
|
+
answer.time = Time.at(raw_response['time'].to_i)
|
|
25
|
+
answer.type = raw_response['type']
|
|
26
|
+
answer.name = raw_response['name']
|
|
27
|
+
answer.email = raw_response['email']
|
|
28
|
+
answer.identification = raw_response['identification']
|
|
29
|
+
answer.phone = raw_response['phone']
|
|
30
|
+
answer.nps_answer = raw_response['nps_answer']
|
|
31
|
+
answer.last_nps_answer = raw_response['last_nps_answer']
|
|
32
|
+
answer.nps_comment = raw_response['nps_comment']
|
|
33
|
+
answer.campaign_name = raw_response['campaign_name']
|
|
34
|
+
answer.campaign_code = raw_response['campaign_code']
|
|
35
|
+
answer.id = raw_response['id']
|
|
36
|
+
answer.deadline = raw_response['deadline']
|
|
37
|
+
answer.elapsed_time = raw_response['elapsed_time']
|
|
38
|
+
answer.dispatch_time = raw_response['dispatch_time']
|
|
39
|
+
answer.reminder_time = raw_response['reminder_time']
|
|
40
|
+
answer.status = raw_response['status']
|
|
41
|
+
answer.tags = convert_tags(raw_response['tags'])
|
|
42
|
+
answer.categories = raw_response['categories'].map { |c| c['name'] }
|
|
43
|
+
answer.justifications = convert_justif(raw_response['justifications'])
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def raw_all
|
|
48
|
+
client.get('report/answer?tags=true&limit=' + LIMIT.to_s)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def client
|
|
52
|
+
Tracksale.configuration.client.new
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def convert_tags(tags)
|
|
56
|
+
tags.map do |tag|
|
|
57
|
+
{ tag['name'] => tag['value'] }
|
|
58
|
+
end.reduce(&:merge)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def convert_justif(multiple_answers)
|
|
62
|
+
multiple_answers.map do |single_answer|
|
|
63
|
+
{
|
|
64
|
+
JSON.parse(single_answer['name']).values.first =>
|
|
65
|
+
single_answer['children'].map { |c| JSON.parse(c).values.first }
|
|
66
|
+
}
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
data/lib/tracksale/campaign.rb
CHANGED
|
@@ -21,6 +21,12 @@ module Tracksale
|
|
|
21
21
|
create_from_response(campaign_found_by_name)
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
+
def self.find_by_code(code)
|
|
25
|
+
campaign_found_by_code = client.get('campaign/' + code.to_s).first
|
|
26
|
+
return nil if campaign_found_by_code.nil?
|
|
27
|
+
create_from_response(campaign_found_by_code)
|
|
28
|
+
end
|
|
29
|
+
|
|
24
30
|
def self.all
|
|
25
31
|
raw_all.map { |campaign| create_from_response(campaign) }
|
|
26
32
|
end
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
module Tracksale
|
|
2
2
|
class DummyClient
|
|
3
3
|
class << self
|
|
4
|
-
attr_accessor :response #Easy way to force a response
|
|
4
|
+
attr_accessor :response # Easy way to force a response
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
def initialize
|
|
8
8
|
puts 'running tracksale dummy client, do not expect real responses.' if $DEBUG
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
# maintaining the same method signature as the real client
|
|
12
|
+
def get(_endpoint_path, _extra_headers = {})
|
|
13
|
+
response
|
|
13
14
|
end
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
# maintaining the same method signature as the real client
|
|
17
|
+
def post(_endpoint_path, _body, _extra_headers = {})
|
|
18
|
+
response
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
def default_response_object
|
|
@@ -23,11 +25,11 @@ module Tracksale
|
|
|
23
25
|
true
|
|
24
26
|
end
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
response
|
|
27
29
|
end
|
|
28
30
|
|
|
29
31
|
def response
|
|
30
|
-
#definies a default valid response unless explicity defined.
|
|
32
|
+
# definies a default valid response unless explicity defined.
|
|
31
33
|
self.class.response || default_response_object
|
|
32
34
|
end
|
|
33
35
|
end
|
data/lib/tracksale.rb
CHANGED
data/test/test_tracksale.rb
CHANGED
|
@@ -11,9 +11,9 @@ class TracksaleTest < Minitest::Test
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def test_configure_client
|
|
14
|
-
Tracksale.configure {|c| c.force_dummy_client(false) } #default
|
|
14
|
+
Tracksale.configure { |c| c.force_dummy_client(false) } # default
|
|
15
15
|
assert_equal Tracksale::Client, Tracksale.configuration.client
|
|
16
|
-
Tracksale.configure
|
|
16
|
+
Tracksale.configure(&:force_dummy_client)
|
|
17
17
|
assert_equal Tracksale::DummyClient, Tracksale.configuration.client
|
|
18
18
|
end
|
|
19
19
|
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
require 'minitest/autorun'
|
|
2
|
+
require 'webmock/minitest'
|
|
3
|
+
require 'tracksale'
|
|
4
|
+
|
|
5
|
+
class TestTracksaleAnswer < Minitest::Test
|
|
6
|
+
def setup
|
|
7
|
+
Tracksale.configure { |c| c.key = 'foobar'; c.force_dummy_client(false) }
|
|
8
|
+
|
|
9
|
+
body_for_campaign = '[{"name":"random - name",' \
|
|
10
|
+
'"code":7, "detractors":1,' \
|
|
11
|
+
'"passives":2, "promoters":3 }]'
|
|
12
|
+
|
|
13
|
+
stub_request(:get, 'http://api.tracksale.co/v2/campaign/7')
|
|
14
|
+
.with(headers: { 'authorization' => 'bearer foobar' })
|
|
15
|
+
.to_return(body: body_for_campaign,
|
|
16
|
+
headers: { content_type: 'application/json' }, status: 200)
|
|
17
|
+
|
|
18
|
+
stub_request(:get, 'http://api.tracksale.co/v2/report/answer?tags=true&limit=' + Tracksale::Answer::LIMIT.to_s)
|
|
19
|
+
.with(headers: { 'authorization' => 'bearer foobar' })
|
|
20
|
+
.to_return(body: '[{
|
|
21
|
+
"time": 1532611646,
|
|
22
|
+
"type": "Email",
|
|
23
|
+
"name": "Um Dois Tres Quatro",
|
|
24
|
+
"email": "emailaleatorio@gmail.com",
|
|
25
|
+
"identification": null,
|
|
26
|
+
"phone": null,
|
|
27
|
+
"alternative_email": null,
|
|
28
|
+
"alternative_phone": null,
|
|
29
|
+
"nps_answer": 10,
|
|
30
|
+
"last_nps_answer": null,
|
|
31
|
+
"nps_comment": null,
|
|
32
|
+
"campaign_name": "Campanha de Teste",
|
|
33
|
+
"campaign_code": 7,
|
|
34
|
+
"id": 11112222,
|
|
35
|
+
"deadline": null,
|
|
36
|
+
"elapsed_time": 116,
|
|
37
|
+
"dispatch_time": null,
|
|
38
|
+
"reminder_time": null,
|
|
39
|
+
"status": "Não precisa contatar",
|
|
40
|
+
"priority": "Nenhuma",
|
|
41
|
+
"assignee": "Boris",
|
|
42
|
+
"picture": null,
|
|
43
|
+
"tags": [
|
|
44
|
+
{
|
|
45
|
+
"name": "test1",
|
|
46
|
+
"value": "test2"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"name": "test3",
|
|
50
|
+
"value": "test4"
|
|
51
|
+
}
|
|
52
|
+
],
|
|
53
|
+
"categories": [],
|
|
54
|
+
"justifications": [
|
|
55
|
+
{
|
|
56
|
+
"name": "{\"pt-br\":\"foo\"}",
|
|
57
|
+
"children": [
|
|
58
|
+
"{\"pt-br\":\"bar\"}",
|
|
59
|
+
"{\"pt-br\":\"bar2\"}",
|
|
60
|
+
"{\"pt-br\":\"bar3\"}"
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
]',
|
|
66
|
+
headers: { content_type: 'application/json' }, status: 200)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_answer_tags
|
|
70
|
+
assert subject.respond_to? :tags
|
|
71
|
+
expected_tags = { 'test1' => 'test2', 'test3' => 'test4' }
|
|
72
|
+
assert_equal expected_tags, subject.tags
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def test_justifications
|
|
76
|
+
assert subject.respond_to? :justifications
|
|
77
|
+
expected_justifications = [{ 'foo' => %w[bar bar2 bar3] }]
|
|
78
|
+
assert_equal expected_justifications, subject.justifications
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def test_campaign
|
|
82
|
+
assert subject.campaign.is_a? Tracksale::Campaign
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def subject
|
|
86
|
+
Tracksale::Answer.all.first
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -6,12 +6,19 @@ class TestTracksaleCampaign < Minitest::Test
|
|
|
6
6
|
def setup
|
|
7
7
|
Tracksale.configure { |c| c.key = 'foobar'; c.force_dummy_client(false) }
|
|
8
8
|
|
|
9
|
+
body_for_campaign = '[{"name":"random - name",' \
|
|
10
|
+
'"code":1234, "detractors":1,' \
|
|
11
|
+
'"passives":2, "promoters":3 }]'
|
|
12
|
+
|
|
9
13
|
stub_request(:get, 'http://api.tracksale.co/v2/campaign')
|
|
10
14
|
.with(headers: { 'authorization' => 'bearer foobar' })
|
|
11
|
-
.to_return(body:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
.to_return(body: body_for_campaign,
|
|
16
|
+
headers: { content_type: 'application/json' }, status: 200)
|
|
17
|
+
|
|
18
|
+
stub_request(:get, 'http://api.tracksale.co/v2/campaign/771')
|
|
19
|
+
.with(headers: { 'authorization' => 'bearer foobar' })
|
|
20
|
+
.to_return(body: body_for_campaign,
|
|
21
|
+
headers: { content_type: 'application/json' }, status: 200)
|
|
15
22
|
|
|
16
23
|
stub_dispatch(121, 200, '{ "msg": "scheduled" }')
|
|
17
24
|
stub_dispatch(123, 400, '{ "error": "Invalid Time"}')
|
|
@@ -22,9 +29,9 @@ class TestTracksaleCampaign < Minitest::Test
|
|
|
22
29
|
url = 'http://api.tracksale.co/v2/campaign/' + code.to_s + '/dispatch'
|
|
23
30
|
stub_request(:post, url)
|
|
24
31
|
.with(headers: { 'authorization' => 'bearer foobar',
|
|
25
|
-
|
|
32
|
+
'content-type' => 'application/json' }, body: '"foo"')
|
|
26
33
|
.to_return(body: body,
|
|
27
|
-
|
|
34
|
+
headers: { content_type: 'application/json' }, status: status)
|
|
28
35
|
end
|
|
29
36
|
|
|
30
37
|
def test_dispatch_successful
|
|
@@ -77,6 +84,11 @@ class TestTracksaleCampaign < Minitest::Test
|
|
|
77
84
|
assert Tracksale::Campaign.all.first.is_a? Tracksale::Campaign
|
|
78
85
|
end
|
|
79
86
|
|
|
87
|
+
def test_find_by_code
|
|
88
|
+
assert Tracksale::Campaign.find_by_code(771).respond_to? :name
|
|
89
|
+
assert_equal 'random - name', Tracksale::Campaign.find_by_code(771).name
|
|
90
|
+
end
|
|
91
|
+
|
|
80
92
|
private
|
|
81
93
|
|
|
82
94
|
def subject
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
class TestTracksaleDummyClient < Minitest::Test
|
|
2
2
|
def setup
|
|
3
|
-
Tracksale.configure
|
|
3
|
+
Tracksale.configure(&:force_dummy_client)
|
|
4
4
|
end
|
|
5
5
|
|
|
6
6
|
def test_campaign_all_dummy
|
|
@@ -13,16 +13,16 @@ class TestTracksaleDummyClient < Minitest::Test
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def test_campaign_dispatch_dummy
|
|
16
|
-
assert_equal
|
|
16
|
+
assert_equal({}, Tracksale::Campaign.schedule_dispatch('code', 'body'))
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def test_allow_explict_response
|
|
20
20
|
response = Object.new
|
|
21
|
-
response.send :define_singleton_method, :success?, proc {true}
|
|
22
|
-
Tracksale::DummyClient.response=response
|
|
21
|
+
response.send :define_singleton_method, :success?, (proc { true })
|
|
22
|
+
Tracksale::DummyClient.response = response
|
|
23
23
|
|
|
24
|
-
assert_equal response,Tracksale::Campaign.schedule_dispatch('code','body')
|
|
24
|
+
assert_equal response, Tracksale::Campaign.schedule_dispatch('code', 'body')
|
|
25
25
|
|
|
26
|
-
Tracksale::DummyClient.response=nil # revert to default
|
|
26
|
+
Tracksale::DummyClient.response = nil # revert to default
|
|
27
27
|
end
|
|
28
28
|
end
|
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.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Estudar
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-07-
|
|
11
|
+
date: 2018-07-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: byebug
|
|
@@ -92,11 +92,13 @@ files:
|
|
|
92
92
|
- README.md
|
|
93
93
|
- Rakefile
|
|
94
94
|
- lib/tracksale.rb
|
|
95
|
+
- lib/tracksale/answer.rb
|
|
95
96
|
- lib/tracksale/campaign.rb
|
|
96
97
|
- lib/tracksale/client.rb
|
|
97
98
|
- lib/tracksale/configuration.rb
|
|
98
99
|
- lib/tracksale/dummy_client.rb
|
|
99
100
|
- test/test_tracksale.rb
|
|
101
|
+
- test/test_tracksale_answer.rb
|
|
100
102
|
- test/test_tracksale_campaign.rb
|
|
101
103
|
- test/test_tracksale_dummyclient.rb
|
|
102
104
|
- tracksale.gemspec
|
|
@@ -127,5 +129,6 @@ specification_version: 4
|
|
|
127
129
|
summary: Integration gem for tracksale api v2
|
|
128
130
|
test_files:
|
|
129
131
|
- test/test_tracksale.rb
|
|
132
|
+
- test/test_tracksale_answer.rb
|
|
130
133
|
- test/test_tracksale_campaign.rb
|
|
131
134
|
- test/test_tracksale_dummyclient.rb
|