adtraction-api 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile.lock +52 -0
- data/README.md +10 -6
- data/adtraction-api.gemspec +3 -1
- data/bin/console +2 -2
- data/lib/adtraction/api.rb +3 -3
- data/lib/adtraction/api/affiliate/channels.rb +2 -2
- data/lib/adtraction/api/affiliate/programs.rb +3 -3
- data/lib/adtraction/api/client.rb +6 -6
- data/lib/adtraction/api/configuration.rb +2 -2
- data/lib/adtraction/api/constants.rb +1 -1
- data/lib/adtraction/api/extensions/string.rb +8 -3
- data/lib/adtraction/api/models/channel.rb +1 -1
- data/lib/adtraction/api/models/program.rb +8 -8
- data/lib/adtraction/api/version.rb +2 -2
- data/lib/generators/adtraction/api/install_generator.rb +22 -0
- data/lib/generators/adtraction/api/templates/config.rb +3 -0
- metadata +17 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44351005560cd321ae257c4c827faede38685b4edc723a4a0d30f9389f478012
|
4
|
+
data.tar.gz: 194329ea1b9319cd3bdeeff05548cf8a0211b0bd142d40e3773aeea91c9c6c75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a9e416e3af3dd4252732943ca676709d61f44f6bf42a92364363054c4a9f263c63b8928bb2086841da46dd640ce032675891fdff256549c46455696b77895d7
|
7
|
+
data.tar.gz: 33b0178996f9a83a3a39c20679a829a69b81bb42fb931205096f4f0d2e7ef1ef49627de2147656acb2585960a8149316033842c0645e00e5b79e2f42152e1aa1
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -9,33 +9,81 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
+
actionpack (5.2.2)
|
13
|
+
actionview (= 5.2.2)
|
14
|
+
activesupport (= 5.2.2)
|
15
|
+
rack (~> 2.0)
|
16
|
+
rack-test (>= 0.6.3)
|
17
|
+
rails-dom-testing (~> 2.0)
|
18
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
19
|
+
actionview (5.2.2)
|
20
|
+
activesupport (= 5.2.2)
|
21
|
+
builder (~> 3.1)
|
22
|
+
erubi (~> 1.4)
|
23
|
+
rails-dom-testing (~> 2.0)
|
24
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
25
|
+
activesupport (5.2.2)
|
26
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
27
|
+
i18n (>= 0.7, < 2)
|
28
|
+
minitest (~> 5.1)
|
29
|
+
tzinfo (~> 1.1)
|
12
30
|
addressable (2.6.0)
|
13
31
|
public_suffix (>= 2.0.2, < 4.0)
|
14
32
|
axiom-types (0.1.1)
|
15
33
|
descendants_tracker (~> 0.0.4)
|
16
34
|
ice_nine (~> 0.11.0)
|
17
35
|
thread_safe (~> 0.3, >= 0.3.1)
|
36
|
+
builder (3.2.3)
|
18
37
|
coderay (1.1.2)
|
19
38
|
coercible (1.0.0)
|
20
39
|
descendants_tracker (~> 0.0.1)
|
40
|
+
concurrent-ruby (1.1.5)
|
21
41
|
crack (0.4.3)
|
22
42
|
safe_yaml (~> 1.0.0)
|
43
|
+
crass (1.0.4)
|
23
44
|
descendants_tracker (0.0.4)
|
24
45
|
thread_safe (~> 0.3, >= 0.3.1)
|
25
46
|
diff-lcs (1.3)
|
26
47
|
equalizer (0.0.11)
|
48
|
+
erubi (1.8.0)
|
27
49
|
faraday (0.15.4)
|
28
50
|
multipart-post (>= 1.2, < 3)
|
29
51
|
faraday_middleware (0.13.1)
|
30
52
|
faraday (>= 0.7.4, < 1.0)
|
53
|
+
generator_spec (0.9.4)
|
54
|
+
activesupport (>= 3.0.0)
|
55
|
+
railties (>= 3.0.0)
|
31
56
|
hashdiff (0.3.8)
|
57
|
+
i18n (1.6.0)
|
58
|
+
concurrent-ruby (~> 1.0)
|
32
59
|
ice_nine (0.11.2)
|
60
|
+
loofah (2.2.3)
|
61
|
+
crass (~> 1.0.2)
|
62
|
+
nokogiri (>= 1.5.9)
|
33
63
|
method_source (0.9.2)
|
64
|
+
mini_portile2 (2.4.0)
|
65
|
+
minitest (5.11.3)
|
34
66
|
multipart-post (2.0.0)
|
67
|
+
nokogiri (1.10.1)
|
68
|
+
mini_portile2 (~> 2.4.0)
|
35
69
|
pry (0.12.2)
|
36
70
|
coderay (~> 1.1.0)
|
37
71
|
method_source (~> 0.9.0)
|
38
72
|
public_suffix (3.0.3)
|
73
|
+
rack (2.0.6)
|
74
|
+
rack-test (1.1.0)
|
75
|
+
rack (>= 1.0, < 3)
|
76
|
+
rails-dom-testing (2.0.3)
|
77
|
+
activesupport (>= 4.2.0)
|
78
|
+
nokogiri (>= 1.6)
|
79
|
+
rails-html-sanitizer (1.0.4)
|
80
|
+
loofah (~> 2.2, >= 2.2.2)
|
81
|
+
railties (5.2.2)
|
82
|
+
actionpack (= 5.2.2)
|
83
|
+
activesupport (= 5.2.2)
|
84
|
+
method_source
|
85
|
+
rake (>= 0.8.7)
|
86
|
+
thor (>= 0.19.0, < 2.0)
|
39
87
|
rake (12.3.2)
|
40
88
|
rspec (3.8.0)
|
41
89
|
rspec-core (~> 3.8.0)
|
@@ -51,7 +99,10 @@ GEM
|
|
51
99
|
rspec-support (~> 3.8.0)
|
52
100
|
rspec-support (3.8.0)
|
53
101
|
safe_yaml (1.0.5)
|
102
|
+
thor (0.20.3)
|
54
103
|
thread_safe (0.3.6)
|
104
|
+
tzinfo (1.2.5)
|
105
|
+
thread_safe (~> 0.1)
|
55
106
|
vcr (4.0.0)
|
56
107
|
virtus (1.0.5)
|
57
108
|
axiom-types (~> 0.1)
|
@@ -69,6 +120,7 @@ PLATFORMS
|
|
69
120
|
DEPENDENCIES
|
70
121
|
adtraction-api!
|
71
122
|
bundler (>= 1.17)
|
123
|
+
generator_spec (>= 0.9.4)
|
72
124
|
pry (~> 0.12.2)
|
73
125
|
rake (>= 10.0)
|
74
126
|
rspec (>= 3.0)
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# Adtraction::
|
1
|
+
# Adtraction::API
|
2
2
|
|
3
|
-
Adtraction::
|
3
|
+
Adtraction::API is a Ruby client to interact with [Adtraction's](https://adtraction.com) [API](https://adtraction.docs.apiary.io/#).
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -23,17 +23,21 @@ Or install it yourself as:
|
|
23
23
|
First of all you need an Adtraction account in order to get your API key. After you've gotten ahold of your API key, configure the client to use it:
|
24
24
|
|
25
25
|
```ruby
|
26
|
-
Adtraction::
|
26
|
+
Adtraction::API.configure do |config|
|
27
27
|
config.api_key = "YOUR_API_KEY"
|
28
28
|
end
|
29
29
|
```
|
30
30
|
|
31
|
-
If you're using Ruby on Rails,
|
31
|
+
If you're using Ruby on Rails, you can generate an initializer using:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
rails g adtraction:api:install Adtraction
|
35
|
+
```
|
32
36
|
|
33
37
|
If you're trying to access the API using multiple API keys, then initialize each client with its own separate config:
|
34
38
|
|
35
39
|
```ruby
|
36
|
-
Adtraction::
|
40
|
+
Adtraction::API::Client.new(configuration: Adtraction::API::Configuration.new(api_key: "SOME_OTHER_API_KEY"))
|
37
41
|
```
|
38
42
|
|
39
43
|
This project is a WIP and not all endpoints have been implemented. They'll be gradually implemented depending on what I personally need to use from the API.
|
@@ -60,4 +64,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
60
64
|
|
61
65
|
## Code of Conduct
|
62
66
|
|
63
|
-
Everyone interacting in the Adtraction::
|
67
|
+
Everyone interacting in the Adtraction::API project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/SebastianJ/adtraction-api/blob/master/CODE_OF_CONDUCT.md).
|
data/adtraction-api.gemspec
CHANGED
@@ -5,7 +5,7 @@ require "adtraction/api/version"
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "adtraction-api"
|
8
|
-
spec.version = Adtraction::
|
8
|
+
spec.version = Adtraction::API::VERSION
|
9
9
|
spec.authors = ["Sebastian Johnsson"]
|
10
10
|
spec.email = ["sebastian.johnsson@gmail.com"]
|
11
11
|
|
@@ -44,5 +44,7 @@ Gem::Specification.new do |spec|
|
|
44
44
|
spec.add_development_dependency "vcr", ">= 4.0"
|
45
45
|
spec.add_development_dependency "webmock", ">= 3.5.1"
|
46
46
|
|
47
|
+
spec.add_development_dependency "generator_spec", ">= 0.9.4"
|
48
|
+
|
47
49
|
spec.add_development_dependency "pry", "~> 0.12.2"
|
48
50
|
end
|
data/bin/console
CHANGED
@@ -9,11 +9,11 @@ cfg_path = File.join(File.dirname(__FILE__), "../credentials.yml"
|
|
9
9
|
if ::File.exists?(cfg_path)
|
10
10
|
cfg = YAML.load_file(cfg_path)
|
11
11
|
|
12
|
-
Adtraction::
|
12
|
+
Adtraction::API.configure do |config|
|
13
13
|
config.api_key = cfg["api_key"]
|
14
14
|
|
15
15
|
config.faraday = {
|
16
|
-
user_agent: "Adtraction Ruby Client #{::Adtraction::
|
16
|
+
user_agent: "Adtraction Ruby Client #{::Adtraction::API::VERSION}",
|
17
17
|
verbose: true
|
18
18
|
}
|
19
19
|
end
|
data/lib/adtraction/api.rb
CHANGED
@@ -19,18 +19,18 @@ if !String.instance_methods(false).include?(:camelize)
|
|
19
19
|
end
|
20
20
|
|
21
21
|
module Adtraction
|
22
|
-
module
|
22
|
+
module API
|
23
23
|
|
24
24
|
class << self
|
25
25
|
attr_writer :configuration
|
26
26
|
end
|
27
27
|
|
28
28
|
def self.configuration
|
29
|
-
@configuration ||= ::Adtraction::
|
29
|
+
@configuration ||= ::Adtraction::API::Configuration.new
|
30
30
|
end
|
31
31
|
|
32
32
|
def self.reset
|
33
|
-
@configuration = ::Adtraction::
|
33
|
+
@configuration = ::Adtraction::API::Configuration.new
|
34
34
|
end
|
35
35
|
|
36
36
|
def self.configure
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module Adtraction
|
2
|
-
module
|
2
|
+
module API
|
3
3
|
module Affiliate
|
4
4
|
module Channels
|
5
5
|
|
6
6
|
def approved_channels(path: "/affiliate/approvedchannels", options: {})
|
7
|
-
::Adtraction::
|
7
|
+
::Adtraction::API::Models::Channel.parse(get(path, options: options)&.body)
|
8
8
|
end
|
9
9
|
|
10
10
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Adtraction
|
2
|
-
module
|
2
|
+
module API
|
3
3
|
module Affiliate
|
4
4
|
module Programs
|
5
5
|
|
@@ -9,10 +9,10 @@ module Adtraction
|
|
9
9
|
|
10
10
|
possible_params.each do |param|
|
11
11
|
value = eval("#{param}")
|
12
|
-
data[param.to_s.camelize(
|
12
|
+
data[param.to_s.camelize(:lower)] = value unless value.nil?
|
13
13
|
end
|
14
14
|
|
15
|
-
::Adtraction::
|
15
|
+
::Adtraction::API::Models::Program.parse(post(path, data: data, options: options)&.body)
|
16
16
|
end
|
17
17
|
|
18
18
|
def program_info(program_id, path: "/affiliate/programinfo", options: {})
|
@@ -1,15 +1,15 @@
|
|
1
1
|
module Adtraction
|
2
|
-
module
|
2
|
+
module API
|
3
3
|
class Client
|
4
4
|
attr_accessor :configuration
|
5
5
|
|
6
|
-
def initialize(configuration: ::Adtraction::
|
6
|
+
def initialize(configuration: ::Adtraction::API.configuration)
|
7
7
|
self.configuration = configuration
|
8
8
|
raise InvalidApiKeyError, "You need to supply a valid API key!" if self.configuration.api_key.to_s.empty?
|
9
9
|
end
|
10
10
|
|
11
|
-
include Adtraction::
|
12
|
-
include Adtraction::
|
11
|
+
include Adtraction::API::Affiliate::Channels
|
12
|
+
include Adtraction::API::Affiliate::Programs
|
13
13
|
|
14
14
|
def to_uri(path)
|
15
15
|
path = path.gsub(/^\//i, "")
|
@@ -35,7 +35,7 @@ module Adtraction
|
|
35
35
|
def request(path, method: :get, params: {}, data: {}, headers: {}, options: {})
|
36
36
|
headers = {
|
37
37
|
"X-Token" => self.configuration.api_key,
|
38
|
-
"User-Agent" => self.configuration.faraday.fetch(:user_agent, "Adtraction Ruby Client #{::Adtraction::
|
38
|
+
"User-Agent" => self.configuration.faraday.fetch(:user_agent, "Adtraction Ruby Client #{::Adtraction::API::VERSION}"),
|
39
39
|
"Content-Type" => "application/json"
|
40
40
|
}.merge(headers)
|
41
41
|
|
@@ -68,7 +68,7 @@ module Adtraction
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def log(message)
|
71
|
-
puts "[Adtraction::
|
71
|
+
puts "[Adtraction::API::Client] - #{Time.now}: #{message}" if !message.to_s.empty? && self.verbose
|
72
72
|
end
|
73
73
|
|
74
74
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Adtraction
|
2
|
-
module
|
2
|
+
module API
|
3
3
|
class Configuration
|
4
4
|
attr_accessor :host, :api_version, :api_key, :faraday
|
5
5
|
|
@@ -10,7 +10,7 @@ module Adtraction
|
|
10
10
|
|
11
11
|
self.faraday = {
|
12
12
|
adapter: :net_http,
|
13
|
-
user_agent: "Adtraction Ruby Client #{::Adtraction::
|
13
|
+
user_agent: "Adtraction Ruby Client #{::Adtraction::API::VERSION}",
|
14
14
|
verbose: false
|
15
15
|
}
|
16
16
|
end
|
@@ -1,12 +1,17 @@
|
|
1
1
|
class String
|
2
2
|
|
3
|
-
def camelize(
|
3
|
+
def camelize(first_letter = :upper)
|
4
4
|
string = self
|
5
|
-
|
5
|
+
|
6
|
+
case first_letter
|
7
|
+
when :upper
|
6
8
|
string = string.sub(/^[a-z\d]*/) { $&.capitalize }
|
7
|
-
|
9
|
+
when :lower
|
8
10
|
string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase }
|
11
|
+
else
|
12
|
+
raise ArgumentError, "Invalid option, use either :upper or :lower."
|
9
13
|
end
|
14
|
+
|
10
15
|
string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::')
|
11
16
|
end
|
12
17
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Adtraction
|
2
|
-
module
|
2
|
+
module API
|
3
3
|
module Models
|
4
4
|
|
5
5
|
class Program
|
@@ -59,15 +59,15 @@ module Adtraction
|
|
59
59
|
program.send("#{column}=", item.fetch(api_column, nil))
|
60
60
|
end
|
61
61
|
|
62
|
-
program.approval_status = Adtraction::
|
63
|
-
program.email_marketing = Adtraction::
|
64
|
-
program.sem_marketing = Adtraction::
|
65
|
-
program.social_marketing = Adtraction::
|
66
|
-
program.cashback_marketing = Adtraction::
|
67
|
-
program.coupon_marketing = Adtraction::
|
62
|
+
program.approval_status = Adtraction::API::Constants::APPROVAL_STATUS_ENUM.fetch(item.fetch("approvalStatus"))
|
63
|
+
program.email_marketing = Adtraction::API::Constants::EMAIL_MARKETING_ENUM.fetch(item.fetch("emailMarketing"))
|
64
|
+
program.sem_marketing = Adtraction::API::Constants::SEM_MARKETING_ENUM.fetch(item.fetch("semMarketing"))
|
65
|
+
program.social_marketing = Adtraction::API::Constants::SOCIAL_MARKETING_ENUM.fetch(item.fetch("socialMarketing"))
|
66
|
+
program.cashback_marketing = Adtraction::API::Constants::CASHBACK_MARKETING_ENUM.fetch(item.fetch("cashbackMarketing"))
|
67
|
+
program.coupon_marketing = Adtraction::API::Constants::COUPON_MARKETING_ENUM.fetch(item.fetch("couponMarketing"))
|
68
68
|
|
69
69
|
program.compensations&.each do |compensation|
|
70
|
-
enum = Adtraction::
|
70
|
+
enum = Adtraction::API::Constants::TRANSACTION_TYPE_ENUM.fetch(compensation["transactionType"], nil)
|
71
71
|
compensation["transactionType"] = enum unless enum.nil?
|
72
72
|
end
|
73
73
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/generators/base"
|
4
|
+
|
5
|
+
module Adtraction
|
6
|
+
module API
|
7
|
+
module Generators
|
8
|
+
class InstallGenerator < Rails::Generators::NamedBase
|
9
|
+
include Rails::Generators::ResourceHelpers
|
10
|
+
|
11
|
+
source_root File.expand_path('templates', __dir__)
|
12
|
+
|
13
|
+
desc "Creates an initializer for Adtraction::API for your Rails application."
|
14
|
+
|
15
|
+
def copy_initializer_file
|
16
|
+
copy_file "config.rb", "config/initializers/adtraction_api.rb"
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adtraction-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Johnsson
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: 3.5.1
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: generator_spec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.9.4
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.9.4
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: pry
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,6 +180,8 @@ files:
|
|
166
180
|
- lib/adtraction/api/models/channel.rb
|
167
181
|
- lib/adtraction/api/models/program.rb
|
168
182
|
- lib/adtraction/api/version.rb
|
183
|
+
- lib/generators/adtraction/api/install_generator.rb
|
184
|
+
- lib/generators/adtraction/api/templates/config.rb
|
169
185
|
homepage: https://github.com/SebastianJ/adtraction-api
|
170
186
|
licenses:
|
171
187
|
- MIT
|