yandex_direct 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +11 -0
- data/.travis.yml +5 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +87 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/yandex_direct/authorization_error.rb +7 -0
- data/lib/yandex_direct/blank_data_error.rb +7 -0
- data/lib/yandex_direct/error.rb +5 -0
- data/lib/yandex_direct/not_enough_units_error.rb +7 -0
- data/lib/yandex_direct/v5/ad_groups.rb +25 -0
- data/lib/yandex_direct/v5/ad_images.rb +25 -0
- data/lib/yandex_direct/v5/ads.rb +34 -0
- data/lib/yandex_direct/v5/campaigns.rb +25 -0
- data/lib/yandex_direct/v5/dictionaries.rb +23 -0
- data/lib/yandex_direct/v5/geo_regions_item.rb +11 -0
- data/lib/yandex_direct/v5/keywords.rb +26 -0
- data/lib/yandex_direct/v5/request.rb +24 -0
- data/lib/yandex_direct/v5/sitelinks.rb +25 -0
- data/lib/yandex_direct/v5/v_cards.rb +25 -0
- data/lib/yandex_direct/version.rb +5 -0
- data/lib/yandex_direct.rb +124 -0
- data/yandex_direct.gemspec +29 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dee574dff6487e3ee0a4b8bf331573c95c2ffdf9d169ba83b768eebd5306d9c4
|
4
|
+
data.tar.gz: 8f1398e376e0d4d2659ee5695ea5bd0439ee940eb50c205441c381a7e50a61a3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 817a556108c46e85385e116e38e41ff509b7f44affeb345a4eb0f51b067cd7f65d6ad95e5e3c05825dc3c6d093fc5f3770e6e2c9c78f464e6b7bd75b1265a3ce
|
7
|
+
data.tar.gz: 0752b067ba1cdec46b5ab8dcc7811bcdff3943c263a1fcda3d5de3a1e4267a9cfc42d5e6419d37c80ce285a240b181db56ec49bf07fed5b7fee19c3aa8b8a48b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
6
|
+
|
7
|
+
# Specify your gem's dependencies in yandex_direct.gemspec
|
8
|
+
gemspec
|
9
|
+
|
10
|
+
group :test do
|
11
|
+
gem 'rubocop', '~> 0.54.0', require: false
|
12
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Aleksandr B. Ivanov
|
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,87 @@
|
|
1
|
+
# YandexDirect
|
2
|
+
|
3
|
+
A Ruby interface to the Yandex Direct API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'yandex_direct'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install yandex_direct
|
20
|
+
|
21
|
+
## Configuration
|
22
|
+
|
23
|
+
Yandex Direct API requires you to authenticate via OAuth, so you'll need to register your application with [Yandex](https://oauth.yandex.ru/client/new).
|
24
|
+
|
25
|
+
You can pass configuration options as a block to `YandexDirect::Client.new`.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
client = YandexDirect::Client.new do |config|
|
29
|
+
config.app_id = "YOUR_APP_ID"
|
30
|
+
config.login = "YOUR_LOGIN"
|
31
|
+
config.token = "YOUR_TOKEN"
|
32
|
+
config.test = ("TRUE" | "FALSE")
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
## Usage Examples
|
37
|
+
After configuring a `client`, you can do the following things.
|
38
|
+
|
39
|
+
**Add campaigns**
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
response = client.add_campaigns(Campaigns: [
|
43
|
+
{
|
44
|
+
Name: "gem",
|
45
|
+
StartDate: Date.current.to_s,
|
46
|
+
TextCampaign: {
|
47
|
+
Settings: [{Option: 'EXCLUDE_PAUSED_COMPETING_ADS', Value: 'YES'}],
|
48
|
+
BiddingStrategy: {
|
49
|
+
Search: {BiddingStrategyType: 'HIGHEST_POSITION'},
|
50
|
+
Network: {BiddingStrategyType: 'MAXIMUM_COVERAGE'}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
])
|
55
|
+
```
|
56
|
+
|
57
|
+
**Get specific campaigns**
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
result = client.campaigns(
|
61
|
+
SelectionCriteria: {Ids: [201708011]},
|
62
|
+
FieldNames: %w(Id Name State Status)
|
63
|
+
)
|
64
|
+
```
|
65
|
+
|
66
|
+
**Add ad groups**
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
response = client.add_ad_groups(AdGroups: [
|
70
|
+
Name: 'gem',
|
71
|
+
CampaignId: 201708011,
|
72
|
+
RegionIds: 0
|
73
|
+
])
|
74
|
+
```
|
75
|
+
|
76
|
+
|
77
|
+
## Development
|
78
|
+
|
79
|
+
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.
|
80
|
+
|
81
|
+
## Contributing
|
82
|
+
|
83
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/radanisk/yandex_direct.
|
84
|
+
|
85
|
+
## License
|
86
|
+
|
87
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'yandex_direct'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YandexDirect
|
4
|
+
module V5
|
5
|
+
module AdGroups
|
6
|
+
# Creates an ad group
|
7
|
+
#
|
8
|
+
# @see https://tech.yandex.com/direct/doc/ref-v5/adgroups/add-docpage/
|
9
|
+
def add_ad_groups(params)
|
10
|
+
response = YandexDirect::V5::Request.new(self, @token, 'adgroups', 'add', params).perform
|
11
|
+
@available_units = response[:available_units]
|
12
|
+
response[:result]['AddResults']
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns parameters of groups that match the specified criteria
|
16
|
+
#
|
17
|
+
# @see https://tech.yandex.com/direct/doc/ref-v5/adgroups/get-docpage/
|
18
|
+
def ad_groups(params)
|
19
|
+
response = YandexDirect::V5::Request.new(self, @token, 'adgroups', 'get', params).perform
|
20
|
+
@available_units = response[:available_units]
|
21
|
+
response[:result]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YandexDirect
|
4
|
+
module V5
|
5
|
+
module AdImages
|
6
|
+
# Synchronously uploads images as binary data
|
7
|
+
#
|
8
|
+
# @see https://tech.yandex.ru/direct/doc/ref-v5/adimages/add-docpage/
|
9
|
+
def add_ad_images(params)
|
10
|
+
response = YandexDirect::V5::Request.new(self, @token, 'adimages', 'add', params).perform
|
11
|
+
@available_units = response[:available_units]
|
12
|
+
response[:result]
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns images that meet the specified criteria
|
16
|
+
#
|
17
|
+
# https://tech.yandex.ru/direct/doc/ref-v5/adimages/get-docpage/
|
18
|
+
def ad_images(params)
|
19
|
+
response = YandexDirect::V5::Request.new(self, @token, 'adimages', 'get', params).perform
|
20
|
+
@available_units = response[:available_units]
|
21
|
+
response[:result]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YandexDirect
|
4
|
+
module V5
|
5
|
+
module Ads
|
6
|
+
# Creates an ad
|
7
|
+
#
|
8
|
+
# @see https://tech.yandex.com/direct/doc/ref-v5/ads/add-docpage/
|
9
|
+
def add_ads(params)
|
10
|
+
response = YandexDirect::V5::Request.new(self, @token, 'ads', 'add', params).perform
|
11
|
+
@available_units = response[:available_units]
|
12
|
+
response[:result]
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns parameters of ads that match the specified criteria
|
16
|
+
#
|
17
|
+
# @see https://tech.yandex.com/direct/doc/ref-v5/ads/get-docpage/
|
18
|
+
def ads(params)
|
19
|
+
response = YandexDirect::V5::Request.new(self, @token, 'ads', 'get', params).perform
|
20
|
+
@available_units = response[:available_units]
|
21
|
+
response[:result]
|
22
|
+
end
|
23
|
+
|
24
|
+
# Submits ads for review
|
25
|
+
#
|
26
|
+
# @see https://tech.yandex.com/direct/doc/ref-v5/ads/moderate-docpage/
|
27
|
+
def moderate_ads(params)
|
28
|
+
response = YandexDirect::V5::Request.new(self, @token, 'ads', 'moderate', params).perform
|
29
|
+
@available_units = response[:available_units]
|
30
|
+
response[:result]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YandexDirect
|
4
|
+
module V5
|
5
|
+
module Campaigns
|
6
|
+
# Creates campaigns
|
7
|
+
#
|
8
|
+
# @see https://tech.yandex.com/direct/doc/ref-v5/campaigns/add-docpage/
|
9
|
+
def add_campaigns(params)
|
10
|
+
response = YandexDirect::V5::Request.new(self, @token, 'campaigns', 'add', params).perform
|
11
|
+
@available_units = response[:available_units]
|
12
|
+
response[:result]
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns the parameters of campaigns that match the specified criteria
|
16
|
+
#
|
17
|
+
# @see https://tech.yandex.com/direct/doc/ref-v5/campaigns/get-docpage/
|
18
|
+
def campaigns(params)
|
19
|
+
response = YandexDirect::V5::Request.new(self, @token, 'campaigns', 'get', params).perform
|
20
|
+
@available_units = response[:available_units]
|
21
|
+
response[:result]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yandex_direct/v5/geo_regions_item'
|
4
|
+
|
5
|
+
module YandexDirect
|
6
|
+
module V5
|
7
|
+
module Dictionaries
|
8
|
+
# Returns reference data: regions, time zones, currency exchange rates, metro stations, restrictions on parameter
|
9
|
+
# values, ad exchanges (SSPs), and other information
|
10
|
+
#
|
11
|
+
# @see https://tech.yandex.com/direct/doc/ref-v5/dictionaries/get-docpage/
|
12
|
+
def dictionaries(params)
|
13
|
+
response = YandexDirect::V5::Request.new(self, @token, 'dictionaries', 'get', params).perform
|
14
|
+
if response[:result]['GeoRegions'].any?
|
15
|
+
response[:result]['GeoRegions'].map! do |region_data|
|
16
|
+
GeoRegionsItem.new(region_data)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
response[:result]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GeoRegionsItem
|
4
|
+
attr_reader :geo_region_id, :parent_id, :geo_region_name
|
5
|
+
|
6
|
+
def initialize(attrs)
|
7
|
+
@geo_region_id = attrs['GeoRegionId']
|
8
|
+
@parent_id = attrs['ParentId']
|
9
|
+
@geo_region_name = attrs['GeoRegionName']
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YandexDirect
|
4
|
+
module V5
|
5
|
+
module Keywords
|
6
|
+
# Creates keywords
|
7
|
+
#
|
8
|
+
# @see https://tech.yandex.com/direct/doc/ref-v5/keywords/add-docpage/
|
9
|
+
def add_keywords(params)
|
10
|
+
response = YandexDirect::V5::Request.new(self, @token, 'keywords', 'add', params).perform
|
11
|
+
@available_units = response[:available_units]
|
12
|
+
response[:result]
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns parameters of keywords that match the set criteria: the values of substitution variables, status and
|
16
|
+
# state, productivity, statistics for impressions and clicks, and bids and priorities
|
17
|
+
#
|
18
|
+
# @see https://tech.yandex.com/direct/doc/ref-v5/keywords/get-docpage/
|
19
|
+
def keywords(params)
|
20
|
+
response = YandexDirect::V5::Request.new(self, @token, 'keywords', 'get', params).perform
|
21
|
+
@available_units = response[:available_units]
|
22
|
+
response[:result]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YandexDirect
|
4
|
+
module V5
|
5
|
+
class Request
|
6
|
+
def initialize(client, token, service_name, method, params)
|
7
|
+
@payload = { method: method, params: params }
|
8
|
+
api_url = client.test ? 'https://api-sandbox.direct.yandex.com/json/v5/' : 'https://api.direct.yandex.com/json/v5/'
|
9
|
+
@url = "#{api_url}#{service_name}"
|
10
|
+
@token = token
|
11
|
+
end
|
12
|
+
|
13
|
+
def perform
|
14
|
+
response = HTTP.auth("Bearer #{@token}").headers('Accept-Language': 'ru').post(@url, json: @payload)
|
15
|
+
response_body = response.parse
|
16
|
+
|
17
|
+
raise(YandexDirect::NotEnoughUnitsError) if response_body.key?('error') && response_body['error']['error_code'].to_i == 152
|
18
|
+
raise(YandexDirect::Error, "[#{response_body['error']['error_code']}] #{response_body['error']['error_string']}: #{response_body['error']['error_detail']}") if response_body.key?('error')
|
19
|
+
|
20
|
+
{ result: response_body['result'], available_units: response['Units'].split('/')[1] }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YandexDirect
|
4
|
+
module V5
|
5
|
+
module Sitelinks
|
6
|
+
# Creates sets of sitelinks
|
7
|
+
#
|
8
|
+
# @see https://tech.yandex.com/direct/doc/ref-v5/sitelinks/add-docpage/
|
9
|
+
def add_sitelinks(params)
|
10
|
+
response = YandexDirect::V5::Request.new(self, @token, 'sitelinks', 'add', params).perform
|
11
|
+
@available_units = response[:available_units]
|
12
|
+
response[:result]
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns sets of sitelinks that match the specified criteria
|
16
|
+
#
|
17
|
+
# @see https://tech.yandex.com/direct/doc/ref-v5/sitelinks/get-docpage/
|
18
|
+
def sitelinks(params)
|
19
|
+
response = YandexDirect::V5::Request.new(self, @token, 'sitelinks', 'get', params).perform
|
20
|
+
@available_units = response[:available_units]
|
21
|
+
response[:result]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YandexDirect
|
4
|
+
module V5
|
5
|
+
module VCards
|
6
|
+
# Creates virtual business cards
|
7
|
+
#
|
8
|
+
# @see https://tech.yandex.com/direct/doc/ref-v5/vcards/add-docpage/
|
9
|
+
def add_v_cards(params)
|
10
|
+
response = YandexDirect::V5::Request.new(self, @token, 'vcards', 'add', params).perform
|
11
|
+
@available_units = response[:available_units]
|
12
|
+
response[:result]
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns the vCards that match the specified criteria
|
16
|
+
#
|
17
|
+
# @see https://tech.yandex.com/direct/doc/ref-v5/vcards/get-docpage/
|
18
|
+
def v_cards(params)
|
19
|
+
response = YandexDirect::V5::Request.new(self, @token, 'vcards', 'get', params).perform
|
20
|
+
@available_units = response[:available_units]
|
21
|
+
response[:result]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'http'
|
4
|
+
require 'yandex_direct/authorization_error'
|
5
|
+
require 'yandex_direct/error'
|
6
|
+
require 'yandex_direct/not_enough_units_error'
|
7
|
+
require 'yandex_direct/blank_data_error'
|
8
|
+
require 'yandex_direct/v5/request'
|
9
|
+
require 'yandex_direct/v5/ads'
|
10
|
+
require 'yandex_direct/v5/ad_groups'
|
11
|
+
require 'yandex_direct/v5/ad_images'
|
12
|
+
require 'yandex_direct/v5/campaigns'
|
13
|
+
require 'yandex_direct/v5/dictionaries'
|
14
|
+
require 'yandex_direct/v5/keywords'
|
15
|
+
require 'yandex_direct/v5/sitelinks'
|
16
|
+
require 'yandex_direct/v5/v_cards'
|
17
|
+
require 'yandex_direct/version'
|
18
|
+
|
19
|
+
module YandexDirect
|
20
|
+
class Client
|
21
|
+
include YandexDirect::V5::Ads
|
22
|
+
include YandexDirect::V5::AdGroups
|
23
|
+
include YandexDirect::V5::AdImages
|
24
|
+
include YandexDirect::V5::Campaigns
|
25
|
+
include YandexDirect::V5::Dictionaries
|
26
|
+
include YandexDirect::V5::Keywords
|
27
|
+
include YandexDirect::V5::Sitelinks
|
28
|
+
include YandexDirect::V5::VCards
|
29
|
+
|
30
|
+
attr_accessor :token, :login, :test, :app_id
|
31
|
+
attr_reader :available_units
|
32
|
+
|
33
|
+
def initialize(options = {})
|
34
|
+
options.each do |key, value|
|
35
|
+
instance_variable_set("@#{key}", value)
|
36
|
+
end
|
37
|
+
|
38
|
+
@url = 'https://api.direct.yandex.ru/json-api/v4/'
|
39
|
+
@url_live = 'https://api.direct.yandex.ru/live/v4/json/'
|
40
|
+
|
41
|
+
yield(self) if block_given?
|
42
|
+
end
|
43
|
+
|
44
|
+
def create_new_wordstat_report(param = nil)
|
45
|
+
param ||= { Phrases: ['синтепон'], GeoID: [213] }
|
46
|
+
request('CreateNewWordstatReport', param)['data']
|
47
|
+
end
|
48
|
+
|
49
|
+
def delete_wordstat_report(param)
|
50
|
+
request('DeleteWordstatReport', param)
|
51
|
+
end
|
52
|
+
|
53
|
+
def wordstat_report(param)
|
54
|
+
result = request('GetWordstatReport', param)
|
55
|
+
raise(YandexDirect::BlankDataError, 'Blank data') if result['data'].empty?
|
56
|
+
|
57
|
+
result
|
58
|
+
end
|
59
|
+
|
60
|
+
def wordstat_report_list
|
61
|
+
request('GetWordstatReportList')
|
62
|
+
end
|
63
|
+
|
64
|
+
def update_campaigns_tags(param)
|
65
|
+
request_live('UpdateCampaignsTags', param)
|
66
|
+
end
|
67
|
+
|
68
|
+
def campaigns_tags(param)
|
69
|
+
request_live('GetCampaignsTags', param)
|
70
|
+
end
|
71
|
+
|
72
|
+
def update_banners_tags(param)
|
73
|
+
request_live('UpdateBannersTags', param)
|
74
|
+
end
|
75
|
+
|
76
|
+
def banners_tags(param)
|
77
|
+
request_live('GetBannersTags', param)
|
78
|
+
end
|
79
|
+
|
80
|
+
def regions
|
81
|
+
request('GetRegions')['data'].map do |region_data|
|
82
|
+
YandexDirect::RegionInfo.new(region_data)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def ping_api
|
87
|
+
request('PingAPI')
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def request_v4(url, method, param)
|
93
|
+
result = HTTP.post(url, json: {
|
94
|
+
method: method,
|
95
|
+
token: @token,
|
96
|
+
locale: 'ru',
|
97
|
+
param: param
|
98
|
+
}).parse
|
99
|
+
|
100
|
+
raise(YandexDirect::AuthorizationError, "#{result['error_str']}: #{result['error_detail']}") if result['error_code'] == 53
|
101
|
+
raise(YandexDirect::Error, "[#{result['error_code']}] #{result['error_str']}: #{result['error_detail']}") if result.key?('error_code')
|
102
|
+
|
103
|
+
result
|
104
|
+
end
|
105
|
+
|
106
|
+
def request(method, param = nil)
|
107
|
+
request_v4(@url, method, param)
|
108
|
+
end
|
109
|
+
|
110
|
+
def request_live(method, param = nil)
|
111
|
+
request_v4(@url_live, method, param)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
class RegionInfo
|
116
|
+
attr_reader :region_id, :parent_id, :region_name
|
117
|
+
|
118
|
+
def initialize(attrs)
|
119
|
+
@region_id = attrs['RegionID']
|
120
|
+
@parent_id = attrs['ParentID']
|
121
|
+
@region_name = attrs['RegionName']
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'yandex_direct/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.add_dependency 'http', '~> 2.0'
|
9
|
+
spec.name = 'yandex_direct'
|
10
|
+
spec.version = YandexDirect::VERSION
|
11
|
+
spec.authors = ['Aleksandr B. Ivanov']
|
12
|
+
spec.email = ['radanisk@gmail.com']
|
13
|
+
|
14
|
+
spec.summary = 'A Ruby interface to the Yandex Direct API'
|
15
|
+
spec.description = 'A Ruby interface to the Yandex Direct API.'
|
16
|
+
spec.homepage = 'https://github.com/radanisk/yandex_direct'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
spec.bindir = 'exe'
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yandex_direct
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aleksandr B. Ivanov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: http
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
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
|
+
description: A Ruby interface to the Yandex Direct API.
|
70
|
+
email:
|
71
|
+
- radanisk@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".rubocop.yml"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- lib/yandex_direct.rb
|
87
|
+
- lib/yandex_direct/authorization_error.rb
|
88
|
+
- lib/yandex_direct/blank_data_error.rb
|
89
|
+
- lib/yandex_direct/error.rb
|
90
|
+
- lib/yandex_direct/not_enough_units_error.rb
|
91
|
+
- lib/yandex_direct/v5/ad_groups.rb
|
92
|
+
- lib/yandex_direct/v5/ad_images.rb
|
93
|
+
- lib/yandex_direct/v5/ads.rb
|
94
|
+
- lib/yandex_direct/v5/campaigns.rb
|
95
|
+
- lib/yandex_direct/v5/dictionaries.rb
|
96
|
+
- lib/yandex_direct/v5/geo_regions_item.rb
|
97
|
+
- lib/yandex_direct/v5/keywords.rb
|
98
|
+
- lib/yandex_direct/v5/request.rb
|
99
|
+
- lib/yandex_direct/v5/sitelinks.rb
|
100
|
+
- lib/yandex_direct/v5/v_cards.rb
|
101
|
+
- lib/yandex_direct/version.rb
|
102
|
+
- yandex_direct.gemspec
|
103
|
+
homepage: https://github.com/radanisk/yandex_direct
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.7.3
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: A Ruby interface to the Yandex Direct API
|
127
|
+
test_files: []
|