admitad 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d2acaa7d5ba4571e4252ebc8625f973269670c2abcf345f4a9a0cbac3773dc5d
4
+ data.tar.gz: fc741785992f1fea246731b3547a96b4c80e476b150701abaf5850321e925880
5
+ SHA512:
6
+ metadata.gz: b46a1a352d83ee941e323efeda3a7d6572b4dbe028c4019ac6af22329a242c17cb49395ff4b075246494af50e013ec098410a5f6bbcb1ef1b0f10c65e659a26f
7
+ data.tar.gz: 45416ee336648ba40b0035799f36c87e6c7dbc4502079818bcc858c29586eedef48e7756a0ace4a01223a6aa04d963117b110133b4abde4762414389aa1c4bec
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ secrets.yml
10
+ .idea/
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,14 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+ Exclude:
4
+ - 'bin/*'
5
+ - 'spec/**/*'
6
+
7
+ Documentation:
8
+ Enabled: false
9
+
10
+ Style/FrozenStringLiteralComment:
11
+ Enabled: false
12
+
13
+ Metrics/LineLength:
14
+ Max: 120
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in admitad.gemspec
6
+ gemspec
@@ -0,0 +1,92 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ admitad (0.0.1)
5
+ activesupport (>= 4.2.0)
6
+ httparty (~> 0.16.2)
7
+ virtus (~> 1.0.5)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (5.2.0)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 0.7, < 2)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ ast (2.4.0)
18
+ axiom-types (0.1.1)
19
+ descendants_tracker (~> 0.0.4)
20
+ ice_nine (~> 0.11.0)
21
+ thread_safe (~> 0.3, >= 0.3.1)
22
+ coderay (1.1.2)
23
+ coercible (1.0.0)
24
+ descendants_tracker (~> 0.0.1)
25
+ concurrent-ruby (1.0.5)
26
+ descendants_tracker (0.0.4)
27
+ thread_safe (~> 0.3, >= 0.3.1)
28
+ diff-lcs (1.3)
29
+ equalizer (0.0.11)
30
+ httparty (0.16.2)
31
+ multi_xml (>= 0.5.2)
32
+ i18n (1.0.1)
33
+ concurrent-ruby (~> 1.0)
34
+ ice_nine (0.11.2)
35
+ jaro_winkler (1.5.1)
36
+ method_source (0.9.0)
37
+ minitest (5.11.3)
38
+ multi_xml (0.6.0)
39
+ parallel (1.12.1)
40
+ parser (2.5.1.2)
41
+ ast (~> 2.4.0)
42
+ powerpack (0.1.1)
43
+ pry (0.11.3)
44
+ coderay (~> 1.1.0)
45
+ method_source (~> 0.9.0)
46
+ rainbow (3.0.0)
47
+ rake (10.5.0)
48
+ rspec (3.7.0)
49
+ rspec-core (~> 3.7.0)
50
+ rspec-expectations (~> 3.7.0)
51
+ rspec-mocks (~> 3.7.0)
52
+ rspec-core (3.7.1)
53
+ rspec-support (~> 3.7.0)
54
+ rspec-expectations (3.7.0)
55
+ diff-lcs (>= 1.2.0, < 2.0)
56
+ rspec-support (~> 3.7.0)
57
+ rspec-mocks (3.7.0)
58
+ diff-lcs (>= 1.2.0, < 2.0)
59
+ rspec-support (~> 3.7.0)
60
+ rspec-support (3.7.1)
61
+ rubocop (0.58.1)
62
+ jaro_winkler (~> 1.5.1)
63
+ parallel (~> 1.10)
64
+ parser (>= 2.5, != 2.5.1.1)
65
+ powerpack (~> 0.1)
66
+ rainbow (>= 2.2.2, < 4.0)
67
+ ruby-progressbar (~> 1.7)
68
+ unicode-display_width (~> 1.0, >= 1.0.1)
69
+ ruby-progressbar (1.9.0)
70
+ thread_safe (0.3.6)
71
+ tzinfo (1.2.5)
72
+ thread_safe (~> 0.1)
73
+ unicode-display_width (1.1.3)
74
+ virtus (1.0.5)
75
+ axiom-types (~> 0.1)
76
+ coercible (~> 1.0)
77
+ descendants_tracker (~> 0.0, >= 0.0.3)
78
+ equalizer (~> 0.0, >= 0.0.9)
79
+
80
+ PLATFORMS
81
+ ruby
82
+
83
+ DEPENDENCIES
84
+ admitad!
85
+ bundler (~> 1.16)
86
+ pry (~> 0)
87
+ rake (~> 10.0)
88
+ rspec (~> 3.0)
89
+ rubocop (~> 0)
90
+
91
+ BUNDLED WITH
92
+ 1.16.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 alexandr-senyuk
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.
@@ -0,0 +1,54 @@
1
+ # Admitad
2
+
3
+ Link to api [https://developers.admitad.com/en/doc/](https://developers.admitad.com/en/doc/)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'admitad'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install admitad
20
+
21
+ ## Usage
22
+
23
+
24
+ ### Configure your app
25
+
26
+
27
+ ```ruby
28
+ # config/initializers/admitad.rb
29
+
30
+ Admitad.config do |c|
31
+ c.client_id = Rails.application.secrets.admitad[:client_id]
32
+ c.client_secret = Rails.application.secrets.admitad[:client_secret]
33
+ c.scope = Rails.application.secrets.admitad[:scope]
34
+ end
35
+ ```
36
+ If no scope is specified, will be used the whole
37
+
38
+ ### Start to use
39
+
40
+ The best documentation is the source code. Use it in conjunction with the API documentation
41
+
42
+ ## Development
43
+
44
+ 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.
45
+
46
+ 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).
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/admitad
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,39 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'admitad/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'admitad'
7
+ spec.version = Admitad::VERSION
8
+ spec.authors = ['alexandr-senyuk']
9
+ spec.email = ['alexandr.030197@gmail.com']
10
+
11
+ spec.summary = 'Simple wrapper for admitad api'
12
+ spec.description = 'This interface helps you to create applications for Admitad affiliate network.
13
+ You can build up applications to analyze your own statistics and accounting records or
14
+ to put them up for sale in the Admitad App Store.'
15
+ spec.homepage = 'https://github.com/alexandr-senyuk/admitad-ruby-api'
16
+ spec.license = 'MIT'
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.16'
31
+ spec.add_development_dependency 'pry', '~> 0'
32
+ spec.add_development_dependency 'rake', '~> 10.0'
33
+ spec.add_development_dependency 'rspec', '~> 3.0'
34
+ spec.add_development_dependency 'rubocop', '~> 0'
35
+
36
+ spec.add_runtime_dependency 'activesupport', '~> 4.2', '>= 4.2.0'
37
+ spec.add_runtime_dependency 'httparty', '~> 0.16.2'
38
+ spec.add_runtime_dependency 'virtus', '~> 1.0', '>= 1.0.5'
39
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'admitad'
5
+ require 'yaml'
6
+ require 'pry'
7
+
8
+ secrets = YAML.load_file('secrets.yml')
9
+
10
+ Admitad.config do |c|
11
+ c.client_id = secrets['client_id']
12
+ c.client_secret = secrets['client_secret']
13
+ c.scope = secrets['scope']
14
+ end
15
+
16
+ Pry.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ require 'virtus'
2
+ require 'admitad/config'
3
+ require 'admitad/version'
4
+ require 'admitad/constants'
5
+ require 'admitad/models/result'
6
+
7
+ Dir[File.join(__dir__, 'admitad', 'models', '*.rb')].map(&method(:require))
8
+ Dir[File.join(__dir__, 'admitad', '*.rb')].map(&method(:require))
9
+
10
+ module Admitad
11
+ def configuration
12
+ @configuration ||= Config.new
13
+ end
14
+
15
+ def config
16
+ config = configuration
17
+ yield(config)
18
+ end
19
+
20
+ module_function :configuration, :config
21
+
22
+ AdSpace = AdSpaces::AdSpace
23
+ AffiliateProgram = AffiliatePrograms::AffiliateProgram
24
+ Coupon = Coupons::Coupon
25
+ end
26
+
27
+ AdmitadAPI = Admitad
@@ -0,0 +1,121 @@
1
+ require 'httparty'
2
+
3
+ module Admitad
4
+ class Client
5
+ include HTTParty
6
+ headers 'Content-Type' => 'application/x-www-form-urlencoded'
7
+ debug_output $stdout
8
+ base_uri Constants::BASE_URI
9
+
10
+ def initialize(access_token = nil)
11
+ @client_id = Admitad.configuration.client_id
12
+ @client_secret = Admitad.configuration.client_secret
13
+ @scope = Admitad.configuration.scope || Constants::SCOPES.join(' ')
14
+ @access_token = access_token
15
+ end
16
+
17
+ def coupons_categories(**params)
18
+ path = '/coupons/categories/'
19
+ path << "#{params[:id]}/"
20
+ get(path, query: params.slice(*Constants::BASE_PARAMS))
21
+ end
22
+
23
+ def coupons(**params)
24
+ path = '/coupons/'
25
+ path << "#{params[:id]}/" if params[:id]
26
+ get(path, query: params.slice(*Constants::BASE_PARAMS))
27
+ end
28
+
29
+ def coupons_website(**params)
30
+ path = '/coupons/'
31
+ path << "#{params[:c_id]}/" if params[:c_id]
32
+ path << 'website/'
33
+ path << "#{params[:w_id]}/" if params[:w_id]
34
+
35
+ get(path, query: params.slice(*Constants::COUPONS_PARAMS))
36
+ end
37
+
38
+ def websites(**params)
39
+ path = '/websites/'
40
+ path << "#{params[:id]}/" if params[:id]
41
+ get(path, query: params.slice(*Constants::AD_SPACE_PARAMS))
42
+ end
43
+
44
+ def advcampaigns(**params)
45
+ path = '/advcampaigns/'
46
+ path << "#{params[:id]}/" if params[:id]
47
+
48
+ get(path, query: params.slice(*Constants::AFFILIATE_PROGRAMS_PARAMS))
49
+ end
50
+
51
+ def advcampaigns_website(**params)
52
+ path = '/advcampaigns/'
53
+ path << "#{params[:c_id]}/" if params[:c_id]
54
+ path << 'website/'
55
+ path << "#{params[:w_id]}/" if params[:w_id]
56
+
57
+ get(path, query: params.slice(*Constants::AFFILIATE_PROGRAMS_PARAMS))
58
+ end
59
+
60
+ %w[attach detach].each do |api_method|
61
+ define_method "advcampaigns_#{api_method}" do |**params|
62
+ path = '/advcampaigns/'
63
+ path << "#{params[:c_id]}/" if params[:c_id]
64
+ path << "#{api_method}/"
65
+ path << "#{params[:w_id]}/" if params[:w_id]
66
+
67
+ post(path, body: params.slice(*Constants::AFFILIATE_PROGRAMS_PARAMS))
68
+ end
69
+ end
70
+
71
+ def token(**params)
72
+ self.class.post('/token/', body: token_body(params), headers: token_headers(params))
73
+ end
74
+
75
+ def statistics_actions(**params)
76
+ get('/statistics/actions/', query: params.slice(*Constants::STATISTIC_ACTIONS_PARAMS))
77
+ end
78
+
79
+ def deeplink(**params)
80
+ get("/deeplink/#{params[:w_id]}/advcampaign/#{params[:c_id]}/", query: params.slice(:subid, :ulp))
81
+ end
82
+
83
+ def websites_regions(**params)
84
+ get('/websites/regions/', query: params.slice(*Constants::BASE_PARAMS))
85
+ end
86
+
87
+ def categories(**params)
88
+ get('/categories/', query: params.slice(*Constants::BASE_PARAMS))
89
+ end
90
+
91
+ private
92
+
93
+ def post(path, options = {}, &block)
94
+ options[:headers] = { Authorization: "Bearer #{access_token}" }
95
+ self.class.post(path, options, &block)
96
+ end
97
+
98
+ def get(path, options = {}, &block)
99
+ options[:headers] = { Authorization: "Bearer #{access_token}" }
100
+ self.class.get(path, options, &block)
101
+ end
102
+
103
+ def token_body(params)
104
+ if params[:grant_type] == :client_credentials
105
+ params.slice(:grant_type).merge(client_id: @client_id, scope: @scope)
106
+ else
107
+ params.slice(:refresh_token, :grant_type).merge(client_id: @client_id, client_secret: @client_secret)
108
+ end
109
+ end
110
+
111
+ def token_headers(params)
112
+ if params[:grant_type] == :client_credentials
113
+ { Authorization: "Basic #{Base64.strict_encode64("#{@client_id}:#{@client_secret}")}" }
114
+ else
115
+ self.class.headers
116
+ end
117
+ end
118
+
119
+ attr_reader :access_token
120
+ end
121
+ end
@@ -0,0 +1,15 @@
1
+ require 'active_support'
2
+
3
+ module Admitad
4
+ class Config
5
+ include ActiveSupport::Configurable
6
+
7
+ config_accessor :client_id, :scope, :client_secret
8
+
9
+ def initialize(**options)
10
+ options.each do |key, value|
11
+ config.send("#{key}=", value)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,95 @@
1
+ module Admitad
2
+ module Constants
3
+ SCOPES = %i[
4
+ public_data
5
+ websites
6
+ manage_websites
7
+ advcampaigns
8
+ advcampaigns_for_website
9
+ manage_advcampaigns
10
+ banners
11
+ landings
12
+ banners_for_website
13
+ payments
14
+ manage_payments
15
+ announcements
16
+ referrals
17
+ coupons
18
+ coupons_for_website
19
+ private_data
20
+ tickets
21
+ manage_tickets
22
+ private_data_email
23
+ private_data_phone
24
+ private_data_balance
25
+ validate_links
26
+ deeplink_generator
27
+ statistics
28
+ opt_codes
29
+ manage_opt_codes
30
+ webmaster_retag
31
+ manage_webmaster_retag
32
+ broken_links
33
+ manage_broken_links
34
+ lost_orders
35
+ manage_lost_orders
36
+ broker_application
37
+ manage_broker_application
38
+ ].freeze
39
+
40
+ BASE_URI = 'https://api.admitad.com'.freeze
41
+
42
+ STATISTIC_ACTIONS_PARAMS = %i[
43
+ offset
44
+ limit
45
+ date_start
46
+ date_end
47
+ closing_date_start
48
+ closing_date_end
49
+ status_updated_start
50
+ status_updated_end
51
+ website
52
+ campaign
53
+ subid
54
+ subid1
55
+ subid2
56
+ subid3
57
+ subid4
58
+ source
59
+ status
60
+ keyword
61
+ action
62
+ action_id
63
+ banner
64
+ action_type
65
+ processed
66
+ paid
67
+ total
68
+ order_by
69
+ ].freeze
70
+
71
+ BASE_PARAMS = %i[offset limit].freeze
72
+
73
+ AFFILIATE_PROGRAMS_PARAMS = %i[offset limit language website has_tool traffic_id connection_status].freeze
74
+
75
+ AD_SPACE_PARAMS = %i[offset limit status campaign_status access_token id].freeze
76
+
77
+ COUPONS_PARAMS = %i[
78
+ campaign
79
+ category
80
+ campaign_category
81
+ type
82
+ search
83
+ date_start
84
+ date_end
85
+ offset
86
+ limit
87
+ region
88
+ order_by
89
+ ].freeze
90
+
91
+ BUFFER_TIME = 10
92
+
93
+ ERRORS = %w[error_description error_code error].freeze
94
+ end
95
+ end
@@ -0,0 +1,59 @@
1
+ module Admitad
2
+ class Position < Success
3
+ attribute :id, Integer
4
+ attribute :tariff_id, Integer
5
+ attribute :datetime, DateTime
6
+ attribute :amount, String
7
+ attribute :payment, String
8
+ attribute :rate, String
9
+ attribute :product_url, String
10
+ attribute :product_id, Integer
11
+ attribute :product_name, String
12
+ attribute :product_image, String
13
+ attribute :percentage, String
14
+ end
15
+
16
+ class Action < Success
17
+ attribute :action_id, Integer
18
+ attribute :advcampaign_name, String
19
+ attribute :advcampaign_id, Integer
20
+ attribute :website_name, String
21
+ attribute :status, String
22
+ attribute :comment, String
23
+ attribute :action_date, DateTime
24
+ attribute :action_type, String
25
+ attribute :payment, String
26
+ attribute :action, String
27
+ attribute :tariff_id, Integer
28
+ attribute :currency, String
29
+ attribute :conversion_time, Integer
30
+ attribute :keyword, String
31
+ attribute :cart, String
32
+ attribute :subid, Integer
33
+ attribute :subid1, Integer
34
+ attribute :subid2, Integer
35
+ attribute :subid3, Integer
36
+ attribute :subid4, Integer
37
+ attribute :click_date, DateTime
38
+ attribute :click_user_referer, String
39
+ attribute :banner_id, Integer
40
+ attribute :closing_date, DateTime
41
+ attribute :status_updated, DateTime
42
+ attribute :processed, Integer
43
+ attribute :paid, Integer
44
+ attribute :order_id, Integer
45
+ attribute :positions, Array[Admitad::Position]
46
+
47
+ def self.where(**params)
48
+ ActionsResponse.create(Wrapper.action_statistic(params))
49
+ end
50
+ end
51
+
52
+ class ActionsResponse < Success
53
+ attribute :results, Array[Admitad::Action]
54
+ attribute :_meta, Hash
55
+
56
+ alias actions results
57
+ alias metadata _meta
58
+ end
59
+ end
@@ -0,0 +1,63 @@
1
+ module Admitad
2
+ module AdSpaces
3
+ class Region < Success
4
+ attribute :id, Integer
5
+ attribute :region, String
6
+ end
7
+
8
+ class Category < Success
9
+ attribute :id, Integer
10
+ attribute :parent, Category
11
+ attribute :name, String
12
+ attribute :language, String
13
+ end
14
+
15
+ class AdSpace < Success
16
+ attribute :id, Integer
17
+ attribute :regions, Array[Region]
18
+ attribute :categories, Array[Category]
19
+ attribute :status, String
20
+ attribute :account_id, String
21
+ attribute :kind, String
22
+ attribute :is_old, Boolean
23
+ attribute :name, String
24
+ attribute :collecting_method, String
25
+ attribute :verification_code, String
26
+ attribute :mailing_targeting, Boolean
27
+ attribute :site_url, String
28
+ attribute :db_size, String
29
+ attribute :adservice, String
30
+ attribute :creation_date, String
31
+ attribute :validation_passed, Boolean
32
+ attribute :description, String
33
+
34
+ class << self
35
+ def where(**params)
36
+ Response.create(Wrapper.ad_spaces_where(params))
37
+ end
38
+
39
+ def find(id)
40
+ create(Wrapper.find_ad_space_by_id(id))
41
+ end
42
+ end
43
+ end
44
+
45
+ class Response < Success
46
+ attribute :results, Array[AdSpace]
47
+ attribute :_meta, Hash
48
+
49
+ def self.create(attributes)
50
+ if Constants::ERRORS.any? { |error| attributes.key?(error) }
51
+ Error.new(attributes)
52
+ elsif attributes['results']
53
+ new(attributes)
54
+ else
55
+ AdSpace.new(attributes)
56
+ end
57
+ end
58
+
59
+ alias ad_spaces results
60
+ alias metadata _meta
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,126 @@
1
+ module Admitad
2
+ module AffiliatePrograms
3
+ class Success < Admitad::Success
4
+ attribute :message, String
5
+ attribute :success, String
6
+ end
7
+
8
+ class Action < Admitad::Success
9
+ attribute :hold_time, Integer
10
+ attribute :payment_size, String
11
+ attribute :type, String
12
+ attribute :name, String
13
+ attribute :id, Integer
14
+ end
15
+
16
+ class Traffic < Admitad::Success
17
+ attribute :name, String
18
+ attribute :enabled, Boolean
19
+ end
20
+
21
+ class Category < Admitad::Success
22
+ attribute :id, Integer
23
+ attribute :parent, Category
24
+ attribute :name, String
25
+ attribute :language, String
26
+ end
27
+
28
+ class AffiliateProgram < Admitad::Success
29
+ attribute :goto_cookie_lifetime, Integer
30
+ attribute :rating, String
31
+ attribute :exclusive, Boolean
32
+ attribute :image, String
33
+ attribute :actions, Array[Action]
34
+ attribute :avg_money_transfer_time, Integer
35
+ attribute :currency, String
36
+ attribute :activation_date, String
37
+ attribute :cr, Float
38
+ attribute :max_hold_time, String
39
+ attribute :id, Integer
40
+ attribute :avg_hold_time, Integer
41
+ attribute :ecpc, Float
42
+ attribute :connection_status, String
43
+ attribute :gotolink, String
44
+ attribute :site_url, String
45
+ attribute :regions, Array
46
+ attribute :actions_detail, Array
47
+ attribute :epc_trend, String
48
+ attribute :geotargeting, Boolean
49
+ attribute :products_xml_link, String
50
+ attribute :status, String
51
+ attribute :coupon_iframe_denied, Boolean
52
+ attribute :traffics, Array[Traffic]
53
+ attribute :description, String
54
+ attribute :cr_trend, String
55
+ attribute :raw_description, String
56
+ attribute :modified_date, String
57
+ attribute :denynewwms, Boolean
58
+ attribute :moderation, Boolean
59
+ attribute :categories, Array[Category]
60
+ attribute :name, String
61
+ attribute :retag, Boolean
62
+ attribute :products_csv_link, String
63
+ attribute :feeds_info, Array
64
+ attribute :landing_code, String
65
+ attribute :ecpc_trend, String
66
+ attribute :landing_title, String
67
+ attribute :epc, Float
68
+ attribute :allow_deeplink, Boolean
69
+ attribute :show_products_links, Boolean
70
+
71
+ class << self
72
+ def find(id)
73
+ create(Wrapper.affiliate_programs_where(id: id))
74
+ end
75
+
76
+ def where(**params)
77
+ params[:w_id] = params.delete(:ad_space_id)
78
+ params[:c_id] = params.delete(:affiliate_program_id)
79
+
80
+ attributes = if params[:w_id]
81
+ Wrapper.affiliate_programs_for_ad_space(params[:w_id], params)
82
+ else
83
+ Wrapper.affiliate_programs_where(params)
84
+ end
85
+ Response.create(attributes)
86
+ end
87
+
88
+ def attach(affiliate_program, ad_space)
89
+ AffiliatePrograms::Success.create(Wrapper.connect_affiliate_program(ad_space, affiliate_program))
90
+ end
91
+
92
+ def detach(affiliate_program, ad_space)
93
+ AffiliatePrograms::Success.create(Wrapper.disconnect_affiliate_program(ad_space, affiliate_program))
94
+ end
95
+ end
96
+
97
+ def attach(ad_space)
98
+ self.class.attach(self, ad_space)
99
+ end
100
+
101
+ def detach(ad_space)
102
+ self.class.detach(self, ad_space)
103
+ end
104
+ end
105
+
106
+ class Response < Admitad::Success
107
+ attribute :results, Array[AffiliateProgram]
108
+ attribute :_meta, Hash
109
+
110
+ def self.create(attributes)
111
+ if Constants::ERRORS.any? { |error| attributes.key?(error) }
112
+ Error.new(attributes)
113
+ elsif attributes['results']
114
+ new(attributes)
115
+ elsif attributes['success']
116
+ Success.new(attributes)
117
+ else
118
+ AffiliateProgram.new(attributes)
119
+ end
120
+ end
121
+
122
+ alias affiliate_programs results
123
+ alias metadata _meta
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,20 @@
1
+ module Admitad
2
+ class Category < Success
3
+ attribute :id, Integer
4
+ attribute :parent, Category
5
+ attribute :name, String
6
+ attribute :language, String
7
+
8
+ def self.where(**params)
9
+ CategoryResponse.create(Wrapper.categories(params))
10
+ end
11
+ end
12
+
13
+ class CategoryResponse < Success
14
+ attribute :results, Array[Category]
15
+ attribute :_meta, Hash
16
+
17
+ alias categories results
18
+ alias metadata _meta
19
+ end
20
+ end
@@ -0,0 +1,69 @@
1
+ module Admitad
2
+ module Coupons
3
+ class Field < Success
4
+ attribute :name, String
5
+ attribute :id, Integer
6
+ end
7
+
8
+ class Category < Field
9
+ class << self
10
+ def where(**params)
11
+ CategoriesList.create(Wrapper.coupon_categories(params))
12
+ end
13
+
14
+ def find(id)
15
+ create(Wrapper.coupon_categories(id: id))
16
+ end
17
+ end
18
+ end
19
+
20
+ class Type < Field; end
21
+ class Campaign < Field; end
22
+
23
+ class CategoriesList < Success
24
+ attribute :results, Array[Category]
25
+ attribute :_meta, Hash
26
+
27
+ alias categories results
28
+ alias metadata _meta
29
+ end
30
+
31
+ class Coupon < Success
32
+ attribute :status, String
33
+ attribute :rating, String
34
+ attribute :campaign, Campaign
35
+ attribute :name, String
36
+ attribute :short_name, String
37
+ attribute :date_end, String
38
+ attribute :date_start, String
39
+ attribute :exclusive, Boolean
40
+ attribute :discount, String
41
+ attribute :species, String
42
+ attribute :categories, Array[Category]
43
+ attribute :image, String
44
+ attribute :id, Integer
45
+ attribute :regions, Array[String]
46
+ attribute :types, Array[Type]
47
+ attribute :description, String
48
+
49
+ class << self
50
+ def find(id)
51
+ create(Wrapper.find_coupon(id))
52
+ end
53
+
54
+ def where(**params)
55
+ attributes = params[:ad_space_id] ? Wrapper.coupons_for_website(**params) : Wrapper.coupons(params)
56
+ Response.create(attributes)
57
+ end
58
+ end
59
+ end
60
+
61
+ class Response < Success
62
+ attribute :results, Array[Coupon]
63
+ attribute :_meta, Hash
64
+
65
+ alias affiliate_programs results
66
+ alias metadata _meta
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,11 @@
1
+ module Admitad
2
+ class Deeplinks < Success
3
+ attribute :deeplinks, Array[String]
4
+
5
+ def self.create(**params)
6
+ params = params.merge(c_id: params[:affiliate_program_id], w_id: params[:ad_space_id])
7
+ attributes = Wrapper.generate_deeplink(params)
8
+ Constants::ERRORS.none? { |error| attributes.key?(error) } ? new(deeplinks: attributes) : Error.new(attributes)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Admitad
2
+ class Regions < Success
3
+ attribute :results, Array
4
+
5
+ alias value results
6
+
7
+ def self.where(**params)
8
+ create(Wrapper.regions(params))
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ module Admitad
2
+ class Result
3
+ include Virtus.model
4
+
5
+ def success?
6
+ is_a? Success
7
+ end
8
+
9
+ def error?
10
+ is_a? Error
11
+ end
12
+
13
+ def self.create(attributes)
14
+ Constants::ERRORS.none? { |error| attributes.key?(error) } ? new(attributes) : Error.new(attributes)
15
+ end
16
+ end
17
+
18
+ class Error < Result
19
+ attribute :error_description, String
20
+ attribute :error_code, Integer
21
+ attribute :error, String
22
+ end
23
+
24
+ class Success < Result; end
25
+ end
@@ -0,0 +1,26 @@
1
+ require 'active_support/time'
2
+
3
+ module Admitad
4
+ class Token < Success
5
+ attribute :id, Integer
6
+ attribute :username, String
7
+ attribute :first_name, String
8
+ attribute :last_name, String
9
+ attribute :language, String
10
+ attribute :access_token, String
11
+ attribute :expires_in, Integer
12
+ attribute :expires_at, Integer
13
+ attribute :token_type, String
14
+ attribute :scope, String
15
+ attribute :refresh_token, String
16
+
17
+ def initialize(attributes)
18
+ attributes[:expires_at] = Time.current.to_i + attributes['expires_in']
19
+ super(attributes)
20
+ end
21
+
22
+ def expired?
23
+ (Time.current + Constants::BUFFER_TIME).to_i > expires_at
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Admitad
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -0,0 +1,121 @@
1
+ module Admitad
2
+ class Wrapper
3
+ include Singleton
4
+ class << self
5
+ delegate :action_statistic, :generate_deeplink, :regions, :coupon_categories,
6
+ :categories, :ad_spaces_where, :find_ad_space_by_id, :coupons, :find_coupon,
7
+ :affiliate_programs_where, :affiliate_programs_for_ad_space,
8
+ :connect_affiliate_program, :disconnect_affiliate_program,
9
+ to: :instance
10
+ end
11
+
12
+ def initialize
13
+ @client = Client.new
14
+ @token = create_token
15
+ assign_token
16
+ end
17
+
18
+ def coupons(**params)
19
+ check_token
20
+ client.coupons(params)
21
+ end
22
+
23
+ def find_coupon(id)
24
+ check_token
25
+ client.coupons(id: id)
26
+ end
27
+
28
+ def coupon_categories(**params)
29
+ check_token
30
+ client.coupons_categories(params)
31
+ end
32
+
33
+ def find_coupon_for_website(id, **params)
34
+ check_token
35
+ client.coupons_website(params.merge(c_id: id))
36
+ end
37
+
38
+ def coupons_for_website(**params)
39
+ check_token
40
+ client.coupons_website(params)
41
+ end
42
+
43
+ def action_statistic(**params)
44
+ check_token
45
+ client.statistics_actions(params)
46
+ end
47
+
48
+ def generate_deeplink(**params)
49
+ check_token
50
+ client.deeplink(params)
51
+ end
52
+
53
+ def regions(**params)
54
+ check_token
55
+ client.websites_regions(params)
56
+ end
57
+
58
+ def categories(**params)
59
+ check_token
60
+ client.categories(params)
61
+ end
62
+
63
+ def ad_spaces_where(**params)
64
+ check_token
65
+ client.websites(params)
66
+ end
67
+
68
+ def find_ad_space_by_id(id, **params)
69
+ check_token
70
+ client.websites(params.merge(id: id))
71
+ end
72
+
73
+ def affiliate_programs_where(**params)
74
+ check_token
75
+ client.advcampaigns(params)
76
+ end
77
+
78
+ def affiliate_programs_for_ad_space(ad_space, **params)
79
+ check_token
80
+ id = ad_space.try(:id) || ad_space
81
+ client.advcampaigns_website(params.merge(w_id: id))
82
+ end
83
+
84
+ def connect_affiliate_program(ad_space, affiliate_program)
85
+ check_token
86
+ w_id = ad_space.try(:id) || ad_space
87
+ c_id = affiliate_program.try(:id) || affiliate_program
88
+ client.advcampaigns_attach(w_id: w_id, c_id: c_id)
89
+ end
90
+
91
+ def disconnect_affiliate_program(ad_space, affiliate_program)
92
+ check_token
93
+ w_id = ad_space.try(:id) || ad_space
94
+ c_id = affiliate_program.try(:id) || affiliate_program
95
+ client.advcampaigns_detach(w_id: w_id, c_id: c_id)
96
+ end
97
+
98
+ private
99
+
100
+ def check_token
101
+ return if token&.success? && !token.expired?
102
+
103
+ @token = token.expired? ? refresh_token : create_token
104
+ assign_token
105
+ end
106
+
107
+ def assign_token
108
+ @client = Client.new(token.try(:access_token))
109
+ end
110
+
111
+ def create_token
112
+ Token.create(client.token(grant_type: :client_credentials))
113
+ end
114
+
115
+ def refresh_token
116
+ Token.create(client.token(grant_type: :refresh_token, refresh_token: token.refresh_token))
117
+ end
118
+
119
+ attr_reader :client, :token
120
+ end
121
+ end
@@ -0,0 +1,4 @@
1
+ ---
2
+ client_id: 123456789
3
+ client_secret: 987654321
4
+ scope: 'advcampaigns_for_website advcampaigns public_data banners websites referrals manage_advcampaigns'
metadata ADDED
@@ -0,0 +1,200 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: admitad
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - alexandr-senyuk
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-09-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
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: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.2'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 4.2.0
93
+ type: :runtime
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '4.2'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 4.2.0
103
+ - !ruby/object:Gem::Dependency
104
+ name: httparty
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 0.16.2
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 0.16.2
117
+ - !ruby/object:Gem::Dependency
118
+ name: virtus
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '1.0'
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: 1.0.5
127
+ type: :runtime
128
+ prerelease: false
129
+ version_requirements: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - "~>"
132
+ - !ruby/object:Gem::Version
133
+ version: '1.0'
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: 1.0.5
137
+ description: |-
138
+ This interface helps you to create applications for Admitad affiliate network.
139
+ You can build up applications to analyze your own statistics and accounting records or
140
+ to put them up for sale in the Admitad App Store.
141
+ email:
142
+ - alexandr.030197@gmail.com
143
+ executables: []
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".rubocop.yml"
150
+ - ".travis.yml"
151
+ - Gemfile
152
+ - Gemfile.lock
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - admitad.gemspec
157
+ - bin/console
158
+ - bin/setup
159
+ - lib/admitad.rb
160
+ - lib/admitad/client.rb
161
+ - lib/admitad/config.rb
162
+ - lib/admitad/constants.rb
163
+ - lib/admitad/models/actions_response.rb
164
+ - lib/admitad/models/ad_space_response.rb
165
+ - lib/admitad/models/affiliate_program_response.rb
166
+ - lib/admitad/models/category.rb
167
+ - lib/admitad/models/coupons_response.rb
168
+ - lib/admitad/models/deeplinks.rb
169
+ - lib/admitad/models/regions.rb
170
+ - lib/admitad/models/result.rb
171
+ - lib/admitad/models/token.rb
172
+ - lib/admitad/version.rb
173
+ - lib/admitad/wrapper.rb
174
+ - secrets.yml.example
175
+ homepage: https://github.com/alexandr-senyuk/admitad-ruby-api
176
+ licenses:
177
+ - MIT
178
+ metadata:
179
+ allowed_push_host: https://rubygems.org
180
+ post_install_message:
181
+ rdoc_options: []
182
+ require_paths:
183
+ - lib
184
+ required_ruby_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ required_rubygems_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ requirements: []
195
+ rubyforge_project:
196
+ rubygems_version: 2.7.6
197
+ signing_key:
198
+ specification_version: 4
199
+ summary: Simple wrapper for admitad api
200
+ test_files: []