tracksale 0.0.1
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 +7 -0
- data/.gitignore +50 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +42 -0
- data/Rakefile +8 -0
- data/lib/tracksale/campaign.rb +35 -0
- data/lib/tracksale/client.rb +27 -0
- data/lib/tracksale/configuration.rb +5 -0
- data/lib/tracksale.rb +18 -0
- data/test/test_tracksale.rb +12 -0
- data/test/test_tracksale_campaign.rb +55 -0
- data/tracksale.gemspec +23 -0
- metadata +128 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 8695bde4a00982ac1f031c9640f99bcdc1ea5035
|
|
4
|
+
data.tar.gz: fdea0cf19cd340c25af8806d9965da41401cc4ad
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: '08a49e848d33033fc14577ed8811eee42c721157ddda393efe1ba435f6220c9891adfcd18bf9a89c2c96f258fcb25177a4513754621f524029c54ab9d19b94d8'
|
|
7
|
+
data.tar.gz: 77df3b07d468014360939c5dff9d6843982deba6e6414253c7bd408c836d0ceb92c5a72f6ba93899ab125151ba21be6c4013fa8a1d3658578a087ab987c6ea43
|
data/.gitignore
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
/.config
|
|
4
|
+
/coverage/
|
|
5
|
+
/InstalledFiles
|
|
6
|
+
/pkg/
|
|
7
|
+
/spec/reports/
|
|
8
|
+
/spec/examples.txt
|
|
9
|
+
/test/tmp/
|
|
10
|
+
/test/version_tmp/
|
|
11
|
+
/tmp/
|
|
12
|
+
|
|
13
|
+
# Used by dotenv library to load environment variables.
|
|
14
|
+
# .env
|
|
15
|
+
|
|
16
|
+
## Specific to RubyMotion:
|
|
17
|
+
.dat*
|
|
18
|
+
.repl_history
|
|
19
|
+
build/
|
|
20
|
+
*.bridgesupport
|
|
21
|
+
build-iPhoneOS/
|
|
22
|
+
build-iPhoneSimulator/
|
|
23
|
+
|
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
|
25
|
+
#
|
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
|
29
|
+
#
|
|
30
|
+
# vendor/Pods/
|
|
31
|
+
|
|
32
|
+
## Documentation cache and generated files:
|
|
33
|
+
/.yardoc/
|
|
34
|
+
/_yardoc/
|
|
35
|
+
/doc/
|
|
36
|
+
/rdoc/
|
|
37
|
+
|
|
38
|
+
## Environment normalization:
|
|
39
|
+
/.bundle/
|
|
40
|
+
/vendor/bundle
|
|
41
|
+
/lib/bundler/man/
|
|
42
|
+
|
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
45
|
+
# Gemfile.lock
|
|
46
|
+
# .ruby-version
|
|
47
|
+
# .ruby-gemset
|
|
48
|
+
|
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
50
|
+
.rvmrc
|
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Fundação Estudar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Tracksale
|
|
2
|
+
Tracksale v2 API integration gem.
|
|
3
|
+
|
|
4
|
+
## Install
|
|
5
|
+
|
|
6
|
+
1. Add `gem 'tracksale', github: 'estudar/tracksale'` into your Gemfile.
|
|
7
|
+
2. run `bundle install`
|
|
8
|
+
|
|
9
|
+
## Configure
|
|
10
|
+
|
|
11
|
+
You must generate a Tracksale key on tracksale.co website and configure it on rails you can use an initializer.
|
|
12
|
+
|
|
13
|
+
config/initializers/tracksale.rb
|
|
14
|
+
```
|
|
15
|
+
Tracksale.configure do |config|
|
|
16
|
+
config.key = 'YOUR_KEY_HERE'
|
|
17
|
+
end
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Key generation instructions can be found on the official documentation at: https://api.tracksale.co/?lang=en#submenu1
|
|
21
|
+
## Using
|
|
22
|
+
|
|
23
|
+
After configuration you should be able to use it easily as in
|
|
24
|
+
```
|
|
25
|
+
Tracksale::Campaign.find_by_name('foobar') => #<Tracksale::Campaign:0x00559c458ec128
|
|
26
|
+
@code=123,
|
|
27
|
+
@name="foobar",
|
|
28
|
+
@score={:detractors=>1, :passives=>2, :promoters=>3}>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Debug
|
|
32
|
+
|
|
33
|
+
You can enable the HTTParty debug on the request by using the '-d' option on IRB or Ruby
|
|
34
|
+
|
|
35
|
+
## Limitations
|
|
36
|
+
|
|
37
|
+
This gem is on early stages of development and you will only be able to:
|
|
38
|
+
|
|
39
|
+
* Find campaigns by name ( `Tracksale::Campaign.find_by_name(name)` )
|
|
40
|
+
* List all campaigns ( `Tracksale::Campaign.all` )
|
|
41
|
+
|
|
42
|
+
Also you can only access 5 items from a campaign (name, code, detractors, passives and promoters).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Tracksale
|
|
2
|
+
class Campaign
|
|
3
|
+
attr_accessor :name, :code, :score
|
|
4
|
+
|
|
5
|
+
def self.find_by_name(name)
|
|
6
|
+
campaign_found_by_name = raw_all.keep_if { |c| c['name'] == name }.first
|
|
7
|
+
return nil if campaign_found_by_name.nil?
|
|
8
|
+
create_from_response(campaign_found_by_name)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.all
|
|
12
|
+
raw_all.map { |campaign| create_from_response(campaign) }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.create_from_response(raw_reponse)
|
|
16
|
+
new.tap do |campaign|
|
|
17
|
+
campaign.name = raw_reponse['name']
|
|
18
|
+
campaign.code = raw_reponse['code']
|
|
19
|
+
campaign.score = {
|
|
20
|
+
detractors: raw_reponse['detractors'],
|
|
21
|
+
passives: raw_reponse['passives'],
|
|
22
|
+
promoters: raw_reponse['promoters']
|
|
23
|
+
}
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.raw_all
|
|
28
|
+
client.get('campaign')
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.client
|
|
32
|
+
Tracksale::Client.new
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Tracksale
|
|
2
|
+
class Client
|
|
3
|
+
attr_accessor :key
|
|
4
|
+
attr_accessor :default_path
|
|
5
|
+
include HTTParty
|
|
6
|
+
# api.tracksale.co/v2/login
|
|
7
|
+
base_uri 'http://api.tracksale.co'
|
|
8
|
+
|
|
9
|
+
def initialize
|
|
10
|
+
if Tracksale.configuration.key.nil?
|
|
11
|
+
raise 'API Key not found , please configure as explained in the readme.'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
@key = Tracksale.configuration.key
|
|
15
|
+
@default_path = '/v2/'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def get(endpoint_path, extra_headers = {})
|
|
19
|
+
headers = { 'authorization' => 'bearer ' + key }.merge(extra_headers)
|
|
20
|
+
request_params = {
|
|
21
|
+
headers: headers
|
|
22
|
+
}
|
|
23
|
+
request_params[:debug_output] = STDOUT if $DEBUG
|
|
24
|
+
self.class.get(default_path + endpoint_path, request_params)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
data/lib/tracksale.rb
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'httparty'
|
|
2
|
+
require 'tracksale/configuration'
|
|
3
|
+
require 'tracksale/client'
|
|
4
|
+
require 'tracksale/campaign'
|
|
5
|
+
|
|
6
|
+
module Tracksale
|
|
7
|
+
class << self
|
|
8
|
+
attr_writer :configuration
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.configuration
|
|
12
|
+
@configuration ||= Configuration.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.configure
|
|
16
|
+
yield(configuration)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'minitest/autorun'
|
|
2
|
+
require 'webmock/minitest'
|
|
3
|
+
require 'tracksale'
|
|
4
|
+
|
|
5
|
+
class TracksaleCampaignTest < Minitest::Test
|
|
6
|
+
def setup
|
|
7
|
+
Tracksale.configure { |c| c.key = 'foobar' }
|
|
8
|
+
|
|
9
|
+
stub_request(:get, 'http://api.tracksale.co/v2/campaign')
|
|
10
|
+
.with(headers: { 'authorization' => 'bearer foobar' })
|
|
11
|
+
.to_return(body: '[{"name":"random - name",' \
|
|
12
|
+
'"code":1234,' \
|
|
13
|
+
'"detractors":1,' \
|
|
14
|
+
'"passives":2,' \
|
|
15
|
+
'"promoters":3 }]',
|
|
16
|
+
headers: { content_type: 'application/json' }, status: 200)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_return_right_amount_of_items
|
|
20
|
+
assert_equal 1, Tracksale::Campaign.all.size
|
|
21
|
+
assert !subject.nil?
|
|
22
|
+
assert Tracksale::Campaign.find_by_name('random - another name').nil?
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_find_return_a_campaign
|
|
26
|
+
assert subject.is_a? Tracksale::Campaign
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_campaign_has_a_name
|
|
30
|
+
assert subject.respond_to? :name
|
|
31
|
+
assert_equal 'random - name', subject.name
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_campaign_has_a_code
|
|
35
|
+
assert subject.respond_to? :code
|
|
36
|
+
assert_equal 1234, subject.code
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_campaign_scores
|
|
40
|
+
campaign = subject
|
|
41
|
+
assert campaign.respond_to? :score
|
|
42
|
+
expected_score = { detractors: 1, passives: 2, promoters: 3 }
|
|
43
|
+
assert_equal expected_score, campaign.score
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_all_returns_campaigns
|
|
47
|
+
assert Tracksale::Campaign.all.first.is_a? Tracksale::Campaign
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def subject
|
|
53
|
+
Tracksale::Campaign.find_by_name('random - name')
|
|
54
|
+
end
|
|
55
|
+
end
|
data/tracksale.gemspec
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
s.name = 'tracksale'
|
|
3
|
+
s.version = '0.0.1'
|
|
4
|
+
s.licenses = ['MIT']
|
|
5
|
+
s.summary = 'Integration gem for tracksale api v2'
|
|
6
|
+
s.description = 'Integration gem for tracksale api v2'
|
|
7
|
+
s.authors = ['Estudar']
|
|
8
|
+
s.email = 'regis@estudar.org.br'
|
|
9
|
+
s.homepage = 'https://github.com/estudar/tracksale'
|
|
10
|
+
s.metadata = { 'source_code_uri' =>
|
|
11
|
+
'https://github.com/estudar/tracksale' }
|
|
12
|
+
|
|
13
|
+
s.files = `git ls-files -z`.split("\x0")
|
|
14
|
+
s.test_files = s.files.grep(%r{^test/})
|
|
15
|
+
s.require_paths = ['lib']
|
|
16
|
+
|
|
17
|
+
s.add_development_dependency 'byebug'
|
|
18
|
+
s.add_development_dependency 'pry-byebug'
|
|
19
|
+
s.add_development_dependency 'rubocop'
|
|
20
|
+
s.add_development_dependency 'webmock'
|
|
21
|
+
|
|
22
|
+
s.add_dependency 'httparty'
|
|
23
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: tracksale
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Estudar
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-05-30 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: byebug
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: pry-byebug
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rubocop
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: webmock
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: httparty
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
description: Integration gem for tracksale api v2
|
|
84
|
+
email: regis@estudar.org.br
|
|
85
|
+
executables: []
|
|
86
|
+
extensions: []
|
|
87
|
+
extra_rdoc_files: []
|
|
88
|
+
files:
|
|
89
|
+
- ".gitignore"
|
|
90
|
+
- Gemfile
|
|
91
|
+
- LICENSE
|
|
92
|
+
- README.md
|
|
93
|
+
- Rakefile
|
|
94
|
+
- lib/tracksale.rb
|
|
95
|
+
- lib/tracksale/campaign.rb
|
|
96
|
+
- lib/tracksale/client.rb
|
|
97
|
+
- lib/tracksale/configuration.rb
|
|
98
|
+
- test/test_tracksale.rb
|
|
99
|
+
- test/test_tracksale_campaign.rb
|
|
100
|
+
- tracksale.gemspec
|
|
101
|
+
homepage: https://github.com/estudar/tracksale
|
|
102
|
+
licenses:
|
|
103
|
+
- MIT
|
|
104
|
+
metadata:
|
|
105
|
+
source_code_uri: https://github.com/estudar/tracksale
|
|
106
|
+
post_install_message:
|
|
107
|
+
rdoc_options: []
|
|
108
|
+
require_paths:
|
|
109
|
+
- lib
|
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
|
+
requirements:
|
|
112
|
+
- - ">="
|
|
113
|
+
- !ruby/object:Gem::Version
|
|
114
|
+
version: '0'
|
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
|
+
requirements:
|
|
117
|
+
- - ">="
|
|
118
|
+
- !ruby/object:Gem::Version
|
|
119
|
+
version: '0'
|
|
120
|
+
requirements: []
|
|
121
|
+
rubyforge_project:
|
|
122
|
+
rubygems_version: 2.6.14
|
|
123
|
+
signing_key:
|
|
124
|
+
specification_version: 4
|
|
125
|
+
summary: Integration gem for tracksale api v2
|
|
126
|
+
test_files:
|
|
127
|
+
- test/test_tracksale.rb
|
|
128
|
+
- test/test_tracksale_campaign.rb
|