adtraction-api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +79 -0
- data/LICENSE.txt +21 -0
- data/README.md +63 -0
- data/Rakefile +6 -0
- data/adtraction-api.gemspec +48 -0
- data/bin/console +30 -0
- data/bin/setup +8 -0
- data/credentials.yml.example +1 -0
- data/lib/adtraction/api.rb +43 -0
- data/lib/adtraction/api/affiliate/channels.rb +13 -0
- data/lib/adtraction/api/affiliate/programs.rb +25 -0
- data/lib/adtraction/api/client.rb +76 -0
- data/lib/adtraction/api/configuration.rb +24 -0
- data/lib/adtraction/api/constants.rb +49 -0
- data/lib/adtraction/api/extensions/string.rb +13 -0
- data/lib/adtraction/api/models/channel.rb +19 -0
- data/lib/adtraction/api/models/program.rb +84 -0
- data/lib/adtraction/api/version.rb +5 -0
- metadata +195 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 791a80074ca0d07d36224a23f07d40ffe8a3cd97bcda28aab518402e0a2a6b04
|
4
|
+
data.tar.gz: 7a8f2a76b0aa1311495eff2d2eb315ff4e4f70e0e936b0a01fa6e98e21d34c48
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 03602252b4366d99c6d7eb95d10cea8ff7faacc7b277d56c9238c2130b8d85a818a5e81eda5727b86a69e799b9ea4956ec4ebd0b38fbc8ce32b2c244cc285d3b
|
7
|
+
data.tar.gz: be7519431ca4d53331d3bae97aae027f0d238cd904037aa04e2eb4bffc655b2d82db8376e26e8ac446d8767ad980704ad9e6aae7535822453ef40659cfa3d2d3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at sebastian.johnsson@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
adtraction-api (0.1.0)
|
5
|
+
faraday (>= 0.15.4)
|
6
|
+
faraday_middleware (>= 0.13.1)
|
7
|
+
virtus (>= 1.0.5)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
addressable (2.6.0)
|
13
|
+
public_suffix (>= 2.0.2, < 4.0)
|
14
|
+
axiom-types (0.1.1)
|
15
|
+
descendants_tracker (~> 0.0.4)
|
16
|
+
ice_nine (~> 0.11.0)
|
17
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
18
|
+
coderay (1.1.2)
|
19
|
+
coercible (1.0.0)
|
20
|
+
descendants_tracker (~> 0.0.1)
|
21
|
+
crack (0.4.3)
|
22
|
+
safe_yaml (~> 1.0.0)
|
23
|
+
descendants_tracker (0.0.4)
|
24
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
25
|
+
diff-lcs (1.3)
|
26
|
+
equalizer (0.0.11)
|
27
|
+
faraday (0.15.4)
|
28
|
+
multipart-post (>= 1.2, < 3)
|
29
|
+
faraday_middleware (0.13.1)
|
30
|
+
faraday (>= 0.7.4, < 1.0)
|
31
|
+
hashdiff (0.3.8)
|
32
|
+
ice_nine (0.11.2)
|
33
|
+
method_source (0.9.2)
|
34
|
+
multipart-post (2.0.0)
|
35
|
+
pry (0.12.2)
|
36
|
+
coderay (~> 1.1.0)
|
37
|
+
method_source (~> 0.9.0)
|
38
|
+
public_suffix (3.0.3)
|
39
|
+
rake (12.3.2)
|
40
|
+
rspec (3.8.0)
|
41
|
+
rspec-core (~> 3.8.0)
|
42
|
+
rspec-expectations (~> 3.8.0)
|
43
|
+
rspec-mocks (~> 3.8.0)
|
44
|
+
rspec-core (3.8.0)
|
45
|
+
rspec-support (~> 3.8.0)
|
46
|
+
rspec-expectations (3.8.2)
|
47
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
+
rspec-support (~> 3.8.0)
|
49
|
+
rspec-mocks (3.8.0)
|
50
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
+
rspec-support (~> 3.8.0)
|
52
|
+
rspec-support (3.8.0)
|
53
|
+
safe_yaml (1.0.5)
|
54
|
+
thread_safe (0.3.6)
|
55
|
+
vcr (4.0.0)
|
56
|
+
virtus (1.0.5)
|
57
|
+
axiom-types (~> 0.1)
|
58
|
+
coercible (~> 1.0)
|
59
|
+
descendants_tracker (~> 0.0, >= 0.0.3)
|
60
|
+
equalizer (~> 0.0, >= 0.0.9)
|
61
|
+
webmock (3.5.1)
|
62
|
+
addressable (>= 2.3.6)
|
63
|
+
crack (>= 0.3.2)
|
64
|
+
hashdiff
|
65
|
+
|
66
|
+
PLATFORMS
|
67
|
+
ruby
|
68
|
+
|
69
|
+
DEPENDENCIES
|
70
|
+
adtraction-api!
|
71
|
+
bundler (>= 1.17)
|
72
|
+
pry (~> 0.12.2)
|
73
|
+
rake (>= 10.0)
|
74
|
+
rspec (>= 3.0)
|
75
|
+
vcr (>= 4.0)
|
76
|
+
webmock (>= 3.5.1)
|
77
|
+
|
78
|
+
BUNDLED WITH
|
79
|
+
1.17.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Sebastian Johnsson
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Adtraction::Api
|
2
|
+
|
3
|
+
Adtraction::Api is a Ruby client to interact with [Adtraction's](https://adtraction.com) [API](https://adtraction.docs.apiary.io/#).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'adtraction-api'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install adtraction-api
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
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
|
+
|
25
|
+
```ruby
|
26
|
+
Adtraction::Api.configure do |config|
|
27
|
+
config.api_key = "YOUR_API_KEY"
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
If you're using Ruby on Rails, just put this in an initializer e.g. under config/initializers/adtraction_api.rb.
|
32
|
+
|
33
|
+
If you're trying to access the API using multiple API keys, then initialize each client with its own separate config:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
Adtraction::Api::Client.new(configuration: Adtraction::Api::Configuration.new(api_key: "SOME_OTHER_API_KEY"))
|
37
|
+
```
|
38
|
+
|
39
|
+
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.
|
40
|
+
|
41
|
+
Feel free to fork and submit your own pull requests if you decide to add more endpoints :)
|
42
|
+
|
43
|
+
## Development
|
44
|
+
|
45
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
46
|
+
|
47
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
48
|
+
|
49
|
+
## Testing
|
50
|
+
|
51
|
+
Please be aware that removing any of the VCR cassettes under spec/fixtures/vcr_cassettes and re-running the specs might lead to sensitive/personal data being stored in the newly generated cassettes!
|
52
|
+
|
53
|
+
## Contributing
|
54
|
+
|
55
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/SebastianJ/adtraction-api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
56
|
+
|
57
|
+
## License
|
58
|
+
|
59
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
60
|
+
|
61
|
+
## Code of Conduct
|
62
|
+
|
63
|
+
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/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "adtraction/api/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "adtraction-api"
|
8
|
+
spec.version = Adtraction::Api::VERSION
|
9
|
+
spec.authors = ["Sebastian Johnsson"]
|
10
|
+
spec.email = ["sebastian.johnsson@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Adtraction Ruby API Client}
|
13
|
+
spec.description = %q{Ruby client to interact with Adtraction's API}
|
14
|
+
spec.homepage = "https://github.com/SebastianJ/adtraction-api"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
21
|
+
spec.metadata["source_code_uri"] = "https://github.com/SebastianJ/adtraction-api"
|
22
|
+
spec.metadata["changelog_uri"] = "https://github.com/SebastianJ/adtraction-api/CHANGELOG.md"
|
23
|
+
else
|
24
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
25
|
+
"public gem pushes."
|
26
|
+
end
|
27
|
+
|
28
|
+
# Specify which files should be added to the gem when it is released.
|
29
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
30
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
31
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
32
|
+
end
|
33
|
+
spec.bindir = "exe"
|
34
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
35
|
+
spec.require_paths = ["lib"]
|
36
|
+
|
37
|
+
spec.add_dependency "faraday", ">= 0.15.4"
|
38
|
+
spec.add_dependency "faraday_middleware", ">= 0.13.1"
|
39
|
+
spec.add_dependency "virtus", ">= 1.0.5"
|
40
|
+
|
41
|
+
spec.add_development_dependency "bundler", ">= 1.17"
|
42
|
+
spec.add_development_dependency "rake", ">= 10.0"
|
43
|
+
spec.add_development_dependency "rspec", ">= 3.0"
|
44
|
+
spec.add_development_dependency "vcr", ">= 4.0"
|
45
|
+
spec.add_development_dependency "webmock", ">= 3.5.1"
|
46
|
+
|
47
|
+
spec.add_development_dependency "pry", "~> 0.12.2"
|
48
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "adtraction/api"
|
5
|
+
require "yaml"
|
6
|
+
|
7
|
+
cfg_path = File.join(File.dirname(__FILE__), "../credentials.yml")
|
8
|
+
|
9
|
+
if ::File.exists?(cfg_path)
|
10
|
+
cfg = YAML.load_file(cfg_path)
|
11
|
+
|
12
|
+
Adtraction::Api.configure do |config|
|
13
|
+
config.api_key = cfg["api_key"]
|
14
|
+
|
15
|
+
config.faraday = {
|
16
|
+
user_agent: "Adtraction Ruby Client #{::Adtraction::Api::VERSION}",
|
17
|
+
verbose: true
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
23
|
+
# with your gem easier. You can also use a different console, if you like.
|
24
|
+
|
25
|
+
require "pry"
|
26
|
+
Pry.config.history.file = File.join(__FILE__, "../.pry_history")
|
27
|
+
Pry.start
|
28
|
+
|
29
|
+
#require "irb"
|
30
|
+
#IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
api_key: "ENTER_YOUR_API_KEY_HERE_AND_THEN_RENAME_THE_FILE"
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "faraday_middleware"
|
3
|
+
require "virtus"
|
4
|
+
|
5
|
+
require "adtraction/api/version"
|
6
|
+
require "adtraction/api/configuration"
|
7
|
+
require "adtraction/api/constants"
|
8
|
+
|
9
|
+
require "adtraction/api/models/channel"
|
10
|
+
require "adtraction/api/models/program"
|
11
|
+
|
12
|
+
require "adtraction/api/affiliate/channels"
|
13
|
+
require "adtraction/api/affiliate/programs"
|
14
|
+
|
15
|
+
require "adtraction/api/client"
|
16
|
+
|
17
|
+
if !String.instance_methods(false).include?(:camelize)
|
18
|
+
require "adtraction/api/extensions/string"
|
19
|
+
end
|
20
|
+
|
21
|
+
module Adtraction
|
22
|
+
module Api
|
23
|
+
|
24
|
+
class << self
|
25
|
+
attr_writer :configuration
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.configuration
|
29
|
+
@configuration ||= ::Adtraction::Api::Configuration.new
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.reset
|
33
|
+
@configuration = ::Adtraction::Api::Configuration.new
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.configure
|
37
|
+
yield(configuration)
|
38
|
+
end
|
39
|
+
|
40
|
+
class Error < StandardError; end
|
41
|
+
class InvalidApiKeyError < Error; end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Adtraction
|
2
|
+
module Api
|
3
|
+
module Affiliate
|
4
|
+
module Channels
|
5
|
+
|
6
|
+
def approved_channels(path: "/affiliate/approvedchannels", options: {})
|
7
|
+
::Adtraction::Api::Models::Channel.parse(get(path, options: options)&.body)
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Adtraction
|
2
|
+
module Api
|
3
|
+
module Affiliate
|
4
|
+
module Programs
|
5
|
+
|
6
|
+
def programs(channel_id:, market: nil, approval_status: nil, coupon_marketing: nil, feed: nil, email_marketing: nil, social_marketing: nil, currency: nil, cashback_marketing: nil, sem_marketing: nil, program_id: nil, path: "/affiliate/programs", options: {})
|
7
|
+
data = {}
|
8
|
+
possible_params = [:channel_id, :market, :approval_status, :coupon_marketing, :feed, :email_marketing, :social_marketing, :currency, :cashback_marketing, :sem_marketing, :program_id]
|
9
|
+
|
10
|
+
possible_params.each do |param|
|
11
|
+
value = eval("#{param}")
|
12
|
+
data[param.to_s.camelize(false)] = value unless value.nil?
|
13
|
+
end
|
14
|
+
|
15
|
+
::Adtraction::Api::Models::Program.parse(post(path, data: data, options: options)&.body)
|
16
|
+
end
|
17
|
+
|
18
|
+
def program_info(program_id, path: "/affiliate/programinfo", options: {})
|
19
|
+
get("#{path}/#{program_id}", options: options)&.body
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Adtraction
|
2
|
+
module Api
|
3
|
+
class Client
|
4
|
+
attr_accessor :configuration
|
5
|
+
|
6
|
+
def initialize(configuration: ::Adtraction::Api.configuration)
|
7
|
+
self.configuration = configuration
|
8
|
+
raise InvalidApiKeyError, "You need to supply a valid API key!" if self.configuration.api_key.to_s.empty?
|
9
|
+
end
|
10
|
+
|
11
|
+
include Adtraction::Api::Affiliate::Channels
|
12
|
+
include Adtraction::Api::Affiliate::Programs
|
13
|
+
|
14
|
+
def to_uri(path)
|
15
|
+
path = path.gsub(/^\//i, "")
|
16
|
+
path =~ /^http(s)?:\/\// ? path : "https://#{self.configuration.host}/v#{self.configuration.api_version}/#{path}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def get(path, params: {}, headers: {}, options: {})
|
20
|
+
request path, method: :get, params: params, headers: headers, options: options
|
21
|
+
end
|
22
|
+
|
23
|
+
def post(path, params: {}, data: {}, headers: {}, options: {})
|
24
|
+
request path, method: :post, params: params, data: data, headers: {}, options: options
|
25
|
+
end
|
26
|
+
|
27
|
+
def patch(path, params: {}, data: {}, headers: {}, options: {})
|
28
|
+
request path, method: :patch, params: params, data: data, headers: {}, options: options
|
29
|
+
end
|
30
|
+
|
31
|
+
def head(path, headers: {}, options: {})
|
32
|
+
request path, method: :head, headers: headers, options: options
|
33
|
+
end
|
34
|
+
|
35
|
+
def request(path, method: :get, params: {}, data: {}, headers: {}, options: {})
|
36
|
+
headers = {
|
37
|
+
"X-Token" => self.configuration.api_key,
|
38
|
+
"User-Agent" => self.configuration.faraday.fetch(:user_agent, "Adtraction Ruby Client #{::Adtraction::Api::VERSION}"),
|
39
|
+
"Content-Type" => "application/json"
|
40
|
+
}.merge(headers)
|
41
|
+
|
42
|
+
connection = Faraday.new(url: to_uri(path)) do |builder|
|
43
|
+
builder.response :logger if self.configuration.verbose_faraday?
|
44
|
+
|
45
|
+
builder.headers = headers
|
46
|
+
builder.response :json
|
47
|
+
|
48
|
+
yield builder if block_given?
|
49
|
+
|
50
|
+
builder.adapter self.configuration.faraday.fetch(:adapter, :net_http)
|
51
|
+
end
|
52
|
+
|
53
|
+
response = case method
|
54
|
+
when :get
|
55
|
+
connection.get do |request|
|
56
|
+
request.params = params if params && !params.empty?
|
57
|
+
end
|
58
|
+
when :post, :patch
|
59
|
+
connection.send(method) do |request|
|
60
|
+
request.body = data.to_json if data && !data.empty?
|
61
|
+
request.params = params if params && !params.empty?
|
62
|
+
end
|
63
|
+
when :head
|
64
|
+
connection.send(method)
|
65
|
+
end
|
66
|
+
|
67
|
+
return response
|
68
|
+
end
|
69
|
+
|
70
|
+
def log(message)
|
71
|
+
puts "[Adtraction::Api::Client] - #{Time.now}: #{message}" if !message.to_s.empty? && self.verbose
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Adtraction
|
2
|
+
module Api
|
3
|
+
class Configuration
|
4
|
+
attr_accessor :host, :api_version, :api_key, :faraday
|
5
|
+
|
6
|
+
def initialize(host: "api.adtraction.com", api_version: 1, api_key: nil)
|
7
|
+
self.host = host
|
8
|
+
self.api_version = api_version
|
9
|
+
self.api_key = api_key
|
10
|
+
|
11
|
+
self.faraday = {
|
12
|
+
adapter: :net_http,
|
13
|
+
user_agent: "Adtraction Ruby Client #{::Adtraction::Api::VERSION}",
|
14
|
+
verbose: false
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def verbose_faraday?
|
19
|
+
self.faraday.fetch(:verbose, false)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Adtraction
|
2
|
+
module Api
|
3
|
+
module Constants
|
4
|
+
|
5
|
+
TRANSACTION_TYPE_ENUM = {
|
6
|
+
2 => :unknown, # Some programs have this value
|
7
|
+
3 => :sale,
|
8
|
+
4 => :lead,
|
9
|
+
31 => :isale, #iSale (post impression Sale)
|
10
|
+
41 => :ilead #iLead (post impression Lead)
|
11
|
+
}
|
12
|
+
|
13
|
+
APPROVAL_STATUS_ENUM = {
|
14
|
+
0 => :rejected,
|
15
|
+
1 => :approved,
|
16
|
+
2 => :pending_review,
|
17
|
+
3 => :not_applied,
|
18
|
+
}
|
19
|
+
|
20
|
+
EMAIL_MARKETING_ENUM = {
|
21
|
+
0 => :not_allowed,
|
22
|
+
1 => :allowed,
|
23
|
+
2 => :restricted # Preview required
|
24
|
+
}
|
25
|
+
|
26
|
+
SEM_MARKETING_ENUM = {
|
27
|
+
0 => :not_allowed,
|
28
|
+
1 => :allowed,
|
29
|
+
2 => :restricted # No brand bidding
|
30
|
+
}
|
31
|
+
|
32
|
+
SOCIAL_MARKETING_ENUM = {
|
33
|
+
0 => :not_allowed,
|
34
|
+
1 => :allowed
|
35
|
+
}
|
36
|
+
|
37
|
+
CASHBACK_MARKETING_ENUM = {
|
38
|
+
0 => :not_allowed,
|
39
|
+
1 => :allowed
|
40
|
+
}
|
41
|
+
|
42
|
+
COUPON_MARKETING_ENUM = {
|
43
|
+
0 => :not_allowed,
|
44
|
+
1 => :allowed
|
45
|
+
}
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class String
|
2
|
+
|
3
|
+
def camelize(uppercase_first_letter = true)
|
4
|
+
string = self
|
5
|
+
if uppercase_first_letter
|
6
|
+
string = string.sub(/^[a-z\d]*/) { $&.capitalize }
|
7
|
+
else
|
8
|
+
string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase }
|
9
|
+
end
|
10
|
+
string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::')
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Adtraction
|
2
|
+
module Api
|
3
|
+
module Models
|
4
|
+
|
5
|
+
class Channel
|
6
|
+
include Virtus.model
|
7
|
+
|
8
|
+
attribute :id, Integer
|
9
|
+
attribute :name, String
|
10
|
+
|
11
|
+
def self.parse(data)
|
12
|
+
data&.collect { |item| self.new(id: item.fetch("channelId")&.to_i, name: item.fetch("channelName")) }
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Adtraction
|
2
|
+
module Api
|
3
|
+
module Models
|
4
|
+
|
5
|
+
class Program
|
6
|
+
include Virtus.model
|
7
|
+
|
8
|
+
attribute :id, Integer
|
9
|
+
attribute :channel_id, Integer
|
10
|
+
attribute :market, String
|
11
|
+
attribute :currency, String
|
12
|
+
|
13
|
+
attribute :name, String
|
14
|
+
attribute :url, String
|
15
|
+
attribute :tracking_url, String
|
16
|
+
attribute :ad_id, Integer
|
17
|
+
attribute :logo_url, String
|
18
|
+
attribute :category, String
|
19
|
+
|
20
|
+
attribute :approval_status, Symbol
|
21
|
+
attribute :feed, Boolean
|
22
|
+
attribute :sem_marketing, Symbol
|
23
|
+
attribute :social_marketing, Symbol
|
24
|
+
attribute :email_marketing, Symbol
|
25
|
+
attribute :cashback_marketing, Symbol
|
26
|
+
attribute :coupon_marketing, Symbol
|
27
|
+
|
28
|
+
attribute :current_segment, String
|
29
|
+
attribute :pending_active, Boolean
|
30
|
+
attribute :cookie_duration, Integer
|
31
|
+
|
32
|
+
attribute :compensations, Array
|
33
|
+
|
34
|
+
def self.parse(data)
|
35
|
+
programs = []
|
36
|
+
|
37
|
+
mappings = {
|
38
|
+
"channelId" => :channel_id,
|
39
|
+
"programId" => :id,
|
40
|
+
"market" => :market,
|
41
|
+
"currency" => :currency,
|
42
|
+
"feed" => :feed,
|
43
|
+
"programName" => :name,
|
44
|
+
"programURL" => :url,
|
45
|
+
"currentSegment" => :current_segment,
|
46
|
+
"pendingActive" => :pending_active,
|
47
|
+
"cookieDuration" => :cookie_duration,
|
48
|
+
"adId" => :ad_id,
|
49
|
+
"compensations" => :compensations,
|
50
|
+
"logoURL" => :logo_url,
|
51
|
+
"trackingURL" => :tracking_url,
|
52
|
+
"category" => :category
|
53
|
+
}
|
54
|
+
|
55
|
+
data.each do |item|
|
56
|
+
program = self.new
|
57
|
+
|
58
|
+
mappings.each do |api_column, column|
|
59
|
+
program.send("#{column}=", item.fetch(api_column, nil))
|
60
|
+
end
|
61
|
+
|
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
|
+
|
69
|
+
program.compensations&.each do |compensation|
|
70
|
+
enum = Adtraction::Api::Constants::TRANSACTION_TYPE_ENUM.fetch(compensation["transactionType"], nil)
|
71
|
+
compensation["transactionType"] = enum unless enum.nil?
|
72
|
+
end
|
73
|
+
|
74
|
+
programs << program
|
75
|
+
end
|
76
|
+
|
77
|
+
return programs
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
metadata
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: adtraction-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sebastian Johnsson
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.15.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.15.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.13.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.13.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: virtus
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.0.5
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.5
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.17'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.17'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: vcr
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '4.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '4.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 3.5.1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 3.5.1
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.12.2
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.12.2
|
139
|
+
description: Ruby client to interact with Adtraction's API
|
140
|
+
email:
|
141
|
+
- sebastian.johnsson@gmail.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".rspec"
|
148
|
+
- ".travis.yml"
|
149
|
+
- CODE_OF_CONDUCT.md
|
150
|
+
- Gemfile
|
151
|
+
- Gemfile.lock
|
152
|
+
- LICENSE.txt
|
153
|
+
- README.md
|
154
|
+
- Rakefile
|
155
|
+
- adtraction-api.gemspec
|
156
|
+
- bin/console
|
157
|
+
- bin/setup
|
158
|
+
- credentials.yml.example
|
159
|
+
- lib/adtraction/api.rb
|
160
|
+
- lib/adtraction/api/affiliate/channels.rb
|
161
|
+
- lib/adtraction/api/affiliate/programs.rb
|
162
|
+
- lib/adtraction/api/client.rb
|
163
|
+
- lib/adtraction/api/configuration.rb
|
164
|
+
- lib/adtraction/api/constants.rb
|
165
|
+
- lib/adtraction/api/extensions/string.rb
|
166
|
+
- lib/adtraction/api/models/channel.rb
|
167
|
+
- lib/adtraction/api/models/program.rb
|
168
|
+
- lib/adtraction/api/version.rb
|
169
|
+
homepage: https://github.com/SebastianJ/adtraction-api
|
170
|
+
licenses:
|
171
|
+
- MIT
|
172
|
+
metadata:
|
173
|
+
homepage_uri: https://github.com/SebastianJ/adtraction-api
|
174
|
+
source_code_uri: https://github.com/SebastianJ/adtraction-api
|
175
|
+
changelog_uri: https://github.com/SebastianJ/adtraction-api/CHANGELOG.md
|
176
|
+
post_install_message:
|
177
|
+
rdoc_options: []
|
178
|
+
require_paths:
|
179
|
+
- lib
|
180
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
181
|
+
requirements:
|
182
|
+
- - ">="
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
version: '0'
|
185
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
|
+
requirements:
|
187
|
+
- - ">="
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '0'
|
190
|
+
requirements: []
|
191
|
+
rubygems_version: 3.0.1
|
192
|
+
signing_key:
|
193
|
+
specification_version: 4
|
194
|
+
summary: Adtraction Ruby API Client
|
195
|
+
test_files: []
|