ya-api-direct 0.2.6 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +2 -2
- data/README.md +2 -2
- data/lib/ya/api/direct/client.rb +4 -4
- data/lib/ya/api/direct/constants.rb +52 -7
- data/lib/ya/api/direct/exceptions.rb +33 -0
- data/lib/ya/api/direct/gateway.rb +19 -4
- data/lib/ya/api/direct/url_helper.rb +7 -8
- data/lib/ya/api/direct/version.rb +1 -1
- data/lib/ya/api/direct.rb +1 -1
- data/ya-api-direct.gemspec +4 -3
- metadata +13 -14
- data/lib/ya/api/direct/exception.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c3834e0a678f9eb91e7523dbca830f99d72660940079dfcc9340082d64ab2ec7
|
4
|
+
data.tar.gz: bf72e62469f98178a4a1ee62fe1c27849d8f23826db06c07354b87aaec6c9b47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbd2d4b2b37ef73cf0b8269de00dd00a91b289948dea5285ca43172a26e5a3570664aa78b907f985c75962e617f6c5e08dd6812492ad261506e49e53151f9e45
|
7
|
+
data.tar.gz: c56f376feb05d6b7ccdc3d5d54e78e46773ba8defa047484a6a82b860bcfd7d184672c46a34b636527b13854087ec20da0f239de0956f31c2024b8ce7bf422d6
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -36,14 +36,14 @@ request = {
|
|
36
36
|
|
37
37
|
options = { token: Token }
|
38
38
|
@direct = Ya::API::Direct::Client.new(options)
|
39
|
-
json = direct.campaigns.get request
|
39
|
+
json = @direct.campaigns.get request
|
40
40
|
```
|
41
41
|
|
42
42
|
Call methods from versions 4 and 4 Live:
|
43
43
|
|
44
44
|
```ruby
|
45
45
|
@direct = Ya::API::Direct::Client.new({ token: Token })
|
46
|
-
json = direct.v4.GetCampaignsList
|
46
|
+
json = @direct.v4.GetCampaignsList
|
47
47
|
```
|
48
48
|
|
49
49
|
All names of controllers and methods are equal to ones from Direct API help. 4 vs 4 Live is autodetected.
|
data/lib/ya/api/direct/client.rb
CHANGED
@@ -2,7 +2,7 @@ require "ya/api/direct/constants"
|
|
2
2
|
require "ya/api/direct/gateway"
|
3
3
|
require "ya/api/direct/direct_service_v4"
|
4
4
|
require "ya/api/direct/direct_service_v5"
|
5
|
-
require "ya/api/direct/
|
5
|
+
require "ya/api/direct/exceptions"
|
6
6
|
|
7
7
|
require 'time'
|
8
8
|
|
@@ -14,7 +14,7 @@ module Ya::API::Direct
|
|
14
14
|
class Client
|
15
15
|
attr_reader :cache_timestamp, :units_data, :gateway,
|
16
16
|
:v4, :v5
|
17
|
-
|
17
|
+
|
18
18
|
# Initializes a new Client object
|
19
19
|
#
|
20
20
|
# @param config [Hash]
|
@@ -75,7 +75,7 @@ module Ya::API::Direct
|
|
75
75
|
end
|
76
76
|
|
77
77
|
private
|
78
|
-
|
78
|
+
|
79
79
|
def init_v4
|
80
80
|
@v4 = DirectServiceV4.new self, (API_V4 + API_V4_LIVE)
|
81
81
|
end
|
@@ -90,4 +90,4 @@ module Ya::API::Direct
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
93
|
-
end
|
93
|
+
end
|
@@ -3,38 +3,83 @@ module Ya
|
|
3
3
|
module Direct
|
4
4
|
API_V5 = {
|
5
5
|
"AdGroups" => [
|
6
|
-
|
6
|
+
"add", "update", "delete", "get"
|
7
|
+
],
|
8
|
+
"AgencyClients" => [
|
9
|
+
"add", "update", "get"
|
7
10
|
],
|
8
11
|
"Ads" => [
|
9
12
|
"add", "update", "delete", "suspend", "resume", "archive", "unarchive", "moderate", "get"
|
10
13
|
],
|
14
|
+
"AdExtensions" => [
|
15
|
+
"add", "delete", "get"
|
16
|
+
],
|
17
|
+
"AdImages" => [
|
18
|
+
"add", "delete", "get"
|
19
|
+
],
|
20
|
+
"AudienceTargets" => [
|
21
|
+
"add", "delete", "suspend", "resume", "get", "setBids"
|
22
|
+
],
|
11
23
|
"Bids" => [
|
12
24
|
"set", "setAuto", "get"
|
13
25
|
],
|
14
26
|
"BidModifiers" => [
|
15
|
-
|
16
|
-
|
27
|
+
"add", "delete", "get", "set", "toggle"
|
28
|
+
],
|
29
|
+
"Businesses" => [
|
30
|
+
"get"
|
31
|
+
],
|
17
32
|
"Campaigns" => [
|
18
33
|
"add", "update", "delete", "suspend", "resume", "archive", "unarchive", "get"
|
19
|
-
|
34
|
+
],
|
20
35
|
"Changes" => [
|
21
36
|
"checkDictionaries", "checkCampaigns", "check"
|
22
|
-
|
37
|
+
],
|
38
|
+
"Clients" => [
|
39
|
+
"get", "update"
|
40
|
+
],
|
41
|
+
"Creatives" => [
|
42
|
+
"get"
|
43
|
+
],
|
23
44
|
"Dictionaries" => [
|
24
|
-
|
45
|
+
"get"
|
46
|
+
],
|
47
|
+
"DynamicFeedAdTargets" => [
|
48
|
+
"add", "delete", "suspend", "resume", "get", "setBids"
|
25
49
|
],
|
26
50
|
"DynamicTextAdTargets" => [
|
27
51
|
"add", "delete", "suspend", "resume", "get", "setBids"
|
28
52
|
],
|
53
|
+
"Feeds" => [
|
54
|
+
"add", "delete", "get", "update"
|
55
|
+
],
|
29
56
|
"Keywords" => [
|
30
57
|
"add", "update", "delete", "suspend", "resume", "get"
|
31
58
|
],
|
59
|
+
"KeywordBids" => [
|
60
|
+
"set", "setAuto", "get"
|
61
|
+
],
|
32
62
|
"KeywordsResearch" => [
|
33
|
-
"hasSearchVolume"
|
63
|
+
"hasSearchVolume", "deduplicate"
|
64
|
+
],
|
65
|
+
"Leads" => [
|
66
|
+
"get"
|
67
|
+
],
|
68
|
+
"NegativeKeywordSharedSets" => [
|
69
|
+
"add", "update", "delete", "get"
|
70
|
+
],
|
71
|
+
"RetargetingLists" => [
|
72
|
+
"add", "update", "delete", "get"
|
34
73
|
],
|
35
74
|
"Sitelinks" => [
|
36
75
|
"add", "get", "delete"
|
37
76
|
],
|
77
|
+
"SmartAdTargets" => [
|
78
|
+
"add", "update", "setBids", "delete", "suspend", "resume", "get"
|
79
|
+
],
|
80
|
+
"TurboPages" => [
|
81
|
+
"get"
|
82
|
+
],
|
38
83
|
"VCards" => [
|
39
84
|
"add", "get", "delete"
|
40
85
|
],
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "ya/api/direct/constants"
|
2
|
+
|
3
|
+
module Ya::API::Direct
|
4
|
+
class Exception < StandardError
|
5
|
+
attr_reader :error
|
6
|
+
|
7
|
+
def initialize( error )
|
8
|
+
@error = error
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
[ @error['error_code'], @error['error_string'], @error['error_detail'], @error['request_id'] ].join(' : ')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class RequestError < StandardError
|
17
|
+
attr_reader :method, :version, :request, :response
|
18
|
+
|
19
|
+
def initialize( method: , version: , request: , response: )
|
20
|
+
@method = method
|
21
|
+
@version = version
|
22
|
+
@request = request
|
23
|
+
@response = response
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_s
|
27
|
+
if response.body && ['text/json', 'application/json'].include?( response["Content-Type"] ) && error = JSON.parse( response.body )['error']
|
28
|
+
err_msg = error.values_at('error_code', 'error_string', 'error_detail', 'request_id').reject(&:blank?).join(' : ')
|
29
|
+
end
|
30
|
+
[ ['HTTP ', response.code].join, err_msg ].compact.join(': ')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -4,10 +4,11 @@ require "json"
|
|
4
4
|
|
5
5
|
require "ya/api/direct/constants"
|
6
6
|
require "ya/api/direct/url_helper"
|
7
|
+
require "ya/api/direct/exceptions"
|
7
8
|
|
8
9
|
module Ya::API::Direct
|
9
10
|
class Gateway
|
10
|
-
attr_reader :config
|
11
|
+
attr_reader :config, :response
|
11
12
|
def initialize(config)
|
12
13
|
@config = config
|
13
14
|
end
|
@@ -23,11 +24,25 @@ module Ya::API::Direct
|
|
23
24
|
http = Net::HTTP.new(uri.host, uri.port)
|
24
25
|
http.use_ssl = true
|
25
26
|
http.verify_mode = @config[:ssl] ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
|
26
|
-
|
27
|
+
|
28
|
+
begin
|
29
|
+
response = http.request(request)
|
30
|
+
if (response.kind_of? Net::HTTPCreated) || (response.kind_of? Net::HTTPAccepted)
|
31
|
+
sleep response['retryIn'].to_i
|
32
|
+
end
|
33
|
+
end while(response.kind_of? Net::HTTPCreated) || (response.kind_of? Net::HTTPAccepted)
|
34
|
+
|
35
|
+
@response = response
|
36
|
+
|
27
37
|
if response.kind_of? Net::HTTPSuccess
|
28
38
|
UrlHelper.parse_data response, ver
|
29
39
|
else
|
30
|
-
raise
|
40
|
+
raise RequestError.new(
|
41
|
+
method: method,
|
42
|
+
version: ver,
|
43
|
+
request: request,
|
44
|
+
response: response
|
45
|
+
)
|
31
46
|
end
|
32
47
|
end
|
33
48
|
|
@@ -57,4 +72,4 @@ module Ya::API::Direct
|
|
57
72
|
body
|
58
73
|
end
|
59
74
|
end
|
60
|
-
end
|
75
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "json"
|
2
2
|
|
3
|
-
require "ya/api/direct/
|
3
|
+
require "ya/api/direct/exceptions"
|
4
4
|
|
5
5
|
|
6
6
|
module Ya::API::Direct
|
@@ -10,7 +10,7 @@ module Ya::API::Direct
|
|
10
10
|
# @author Rikki Mongoose
|
11
11
|
class UrlHelper
|
12
12
|
# Generate Yandex Direct API url for a call
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# @param mode [Symbol] Direct API mode, `:sandbox` or `:production`
|
15
15
|
# @param mode [Symbol] Direct API version, `:v5` or `:v4` or `:v4live`
|
16
16
|
# @param mode [Symbol] Direct API service to use
|
@@ -50,7 +50,7 @@ module Ya::API::Direct
|
|
50
50
|
end
|
51
51
|
|
52
52
|
# Extract Yandex Direct API units values from responce HTTP header
|
53
|
-
#
|
53
|
+
#
|
54
54
|
# @param responce_header [Hash] Yandex Direct API response header
|
55
55
|
# @return [Hash] Units data, extracted from header
|
56
56
|
def self.extract_response_units(response_header)
|
@@ -66,7 +66,7 @@ module Ya::API::Direct
|
|
66
66
|
private
|
67
67
|
|
68
68
|
def self.parse_data(response, ver)
|
69
|
-
if response["Content-Type"]
|
69
|
+
if response["Content-Type"].start_with?("application/json")
|
70
70
|
response_body = JSON.parse(response.body)
|
71
71
|
validate_response! response_body
|
72
72
|
result = { data: response_body }
|
@@ -81,15 +81,14 @@ module Ya::API::Direct
|
|
81
81
|
|
82
82
|
def self.validate_response!(response_body)
|
83
83
|
if response_body.has_key? 'error'
|
84
|
-
|
85
|
-
raise Exception.new(response_error['error_detail'], response_error['error_string'], response_error['error_code'])
|
84
|
+
raise Exception.new( response_body['error'] )
|
86
85
|
end
|
87
86
|
end
|
88
87
|
|
89
88
|
def self.from_tsv_to_json(response_body)
|
90
89
|
report_name = response_body.slice!(/^(.+?)\n/)
|
91
90
|
keys = response_body.slice!(/^(.+?)\n/).split("\t")
|
92
|
-
rows = response_body.match(/rows:(.+?)\n/)[1].to_i
|
91
|
+
rows = response_body.match(/rows:(.+?)\n/)[1].to_i
|
93
92
|
values = []
|
94
93
|
rows.times do |row|
|
95
94
|
hash_values = {}
|
@@ -101,4 +100,4 @@ module Ya::API::Direct
|
|
101
100
|
values
|
102
101
|
end
|
103
102
|
end
|
104
|
-
end
|
103
|
+
end
|
data/lib/ya/api/direct.rb
CHANGED
data/ya-api-direct.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'ya/api/direct/version'
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = 'ya-api-direct'
|
8
8
|
s.version = Ya::Api::Direct::VERSION
|
9
|
-
s.date = '
|
9
|
+
s.date = '2021-12-12'
|
10
10
|
s.summary = "Yandex Direct API v5, v4 and v4 Live"
|
11
11
|
s.description = "Ruby implementation for Yandex Direct API of versions 5, 4 and 4 Live"
|
12
12
|
s.authors = "Rikki Mongoose"
|
@@ -18,8 +18,9 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.bindir = "exe"
|
19
19
|
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
|
+
s.required_ruby_version = ">= 2.5.0"
|
21
22
|
|
22
|
-
s.add_development_dependency "bundler", "
|
23
|
-
s.add_development_dependency "rake", "
|
23
|
+
s.add_development_dependency "bundler", ">= 2.2.33"
|
24
|
+
s.add_development_dependency "rake", ">= 12.3.3"
|
24
25
|
s.add_development_dependency "minitest", "~> 5.0"
|
25
26
|
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ya-api-direct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rikki Mongoose
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.2.33
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.2.33
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,7 +74,7 @@ files:
|
|
74
74
|
- lib/ya/api/direct/direct_service_base.rb
|
75
75
|
- lib/ya/api/direct/direct_service_v4.rb
|
76
76
|
- lib/ya/api/direct/direct_service_v5.rb
|
77
|
-
- lib/ya/api/direct/
|
77
|
+
- lib/ya/api/direct/exceptions.rb
|
78
78
|
- lib/ya/api/direct/gateway.rb
|
79
79
|
- lib/ya/api/direct/url_helper.rb
|
80
80
|
- lib/ya/api/direct/version.rb
|
@@ -91,15 +91,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
91
|
requirements:
|
92
92
|
- - ">="
|
93
93
|
- !ruby/object:Gem::Version
|
94
|
-
version:
|
94
|
+
version: 2.5.0
|
95
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
96
|
requirements:
|
97
97
|
- - ">="
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '0'
|
100
100
|
requirements: []
|
101
|
-
|
102
|
-
rubygems_version: 2.5.1
|
101
|
+
rubygems_version: 3.1.2
|
103
102
|
signing_key:
|
104
103
|
specification_version: 4
|
105
104
|
summary: Yandex Direct API v5, v4 and v4 Live
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require "ya/api/direct/constants"
|
2
|
-
|
3
|
-
module Ya::API::Direct
|
4
|
-
class Exception < StandardError
|
5
|
-
attr_reader :error_detail, :error_code, :error_str
|
6
|
-
|
7
|
-
def initialize(error_detail, error_str, error_code)
|
8
|
-
@error_detail = error_detail
|
9
|
-
@error_str = error_str
|
10
|
-
@error_code = error_code
|
11
|
-
end
|
12
|
-
|
13
|
-
def to_s
|
14
|
-
"#{@error_str} : #{@error_detail} : #{@error_code}"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|