adtraction-api 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 791a80074ca0d07d36224a23f07d40ffe8a3cd97bcda28aab518402e0a2a6b04
4
- data.tar.gz: 7a8f2a76b0aa1311495eff2d2eb315ff4e4f70e0e936b0a01fa6e98e21d34c48
3
+ metadata.gz: 44351005560cd321ae257c4c827faede38685b4edc723a4a0d30f9389f478012
4
+ data.tar.gz: 194329ea1b9319cd3bdeeff05548cf8a0211b0bd142d40e3773aeea91c9c6c75
5
5
  SHA512:
6
- metadata.gz: 03602252b4366d99c6d7eb95d10cea8ff7faacc7b277d56c9238c2130b8d85a818a5e81eda5727b86a69e799b9ea4956ec4ebd0b38fbc8ce32b2c244cc285d3b
7
- data.tar.gz: be7519431ca4d53331d3bae97aae027f0d238cd904037aa04e2eb4bffc655b2d82db8376e26e8ac446d8767ad980704ad9e6aae7535822453ef40659cfa3d2d3
6
+ metadata.gz: 8a9e416e3af3dd4252732943ca676709d61f44f6bf42a92364363054c4a9f263c63b8928bb2086841da46dd640ce032675891fdff256549c46455696b77895d7
7
+ data.tar.gz: 33b0178996f9a83a3a39c20679a829a69b81bb42fb931205096f4f0d2e7ef1ef49627de2147656acb2585960a8149316033842c0645e00e5b79e2f42152e1aa1
data/.gitignore CHANGED
@@ -7,6 +7,8 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
 
10
+ /spec/tmp/
11
+
10
12
  # rspec failure tracking
11
13
  .rspec_status
12
14
 
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::Api
1
+ # Adtraction::API
2
2
 
3
- Adtraction::Api is a Ruby client to interact with [Adtraction's](https://adtraction.com) [API](https://adtraction.docs.apiary.io/#).
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::Api.configure do |config|
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, just put this in an initializer e.g. under config/initializers/adtraction_api.rb.
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::Api::Client.new(configuration: Adtraction::Api::Configuration.new(api_key: "SOME_OTHER_API_KEY"))
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::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).
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).
@@ -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::Api::VERSION
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::Api.configure do |config|
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::Api::VERSION}",
16
+ user_agent: "Adtraction Ruby Client #{::Adtraction::API::VERSION}",
17
17
  verbose: true
18
18
  }
19
19
  end
@@ -19,18 +19,18 @@ if !String.instance_methods(false).include?(:camelize)
19
19
  end
20
20
 
21
21
  module Adtraction
22
- module Api
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::Api::Configuration.new
29
+ @configuration ||= ::Adtraction::API::Configuration.new
30
30
  end
31
31
 
32
32
  def self.reset
33
- @configuration = ::Adtraction::Api::Configuration.new
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 Api
2
+ module API
3
3
  module Affiliate
4
4
  module Channels
5
5
 
6
6
  def approved_channels(path: "/affiliate/approvedchannels", options: {})
7
- ::Adtraction::Api::Models::Channel.parse(get(path, options: options)&.body)
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 Api
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(false)] = value unless value.nil?
12
+ data[param.to_s.camelize(:lower)] = value unless value.nil?
13
13
  end
14
14
 
15
- ::Adtraction::Api::Models::Program.parse(post(path, data: data, options: options)&.body)
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 Api
2
+ module API
3
3
  class Client
4
4
  attr_accessor :configuration
5
5
 
6
- def initialize(configuration: ::Adtraction::Api.configuration)
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::Api::Affiliate::Channels
12
- include Adtraction::Api::Affiliate::Programs
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::Api::VERSION}"),
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::Api::Client] - #{Time.now}: #{message}" if !message.to_s.empty? && self.verbose
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 Api
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::Api::VERSION}",
13
+ user_agent: "Adtraction Ruby Client #{::Adtraction::API::VERSION}",
14
14
  verbose: false
15
15
  }
16
16
  end
@@ -1,5 +1,5 @@
1
1
  module Adtraction
2
- module Api
2
+ module API
3
3
  module Constants
4
4
 
5
5
  TRANSACTION_TYPE_ENUM = {
@@ -1,12 +1,17 @@
1
1
  class String
2
2
 
3
- def camelize(uppercase_first_letter = true)
3
+ def camelize(first_letter = :upper)
4
4
  string = self
5
- if uppercase_first_letter
5
+
6
+ case first_letter
7
+ when :upper
6
8
  string = string.sub(/^[a-z\d]*/) { $&.capitalize }
7
- else
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 Api
2
+ module API
3
3
  module Models
4
4
 
5
5
  class Channel
@@ -1,5 +1,5 @@
1
1
  module Adtraction
2
- module Api
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::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"))
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::Api::Constants::TRANSACTION_TYPE_ENUM.fetch(compensation["transactionType"], nil)
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
 
@@ -1,5 +1,5 @@
1
1
  module Adtraction
2
- module Api
3
- VERSION = "0.1.0"
2
+ module API
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -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
@@ -0,0 +1,3 @@
1
+ Adtraction::API.configure do |config|
2
+ config.api_key = "ENTER_YOUR_API_KEY_HERE"
3
+ 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.0
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