yandex-direct-api 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.
- checksums.yaml +7 -0
- data/Rakefile +2 -0
- data/lib/services/campaign.rb +20 -0
- data/lib/yandex_direct_api.rb +68 -0
- metadata +46 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 072883fae96244529f902af53a53dcfb66d2dcce
|
|
4
|
+
data.tar.gz: e8c862e4e3438b30525b7819ff6a36e927f53842
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 500f25dfe8db787220c3f89dcad7c4930c4cff7ec28a1ce46cd655849bde3c35f788200b372c54d99dacce6255646a0822667c1f55cacea9526b35ff37508188
|
|
7
|
+
data.tar.gz: c4355cf4d434acadfcda23c70b0152ee720dfa2e654b9d8e2e4c7cc11e5bc542663f254a65538150afca7544d13bf3cb71bc999c95d21e3386fcce88ac3de849
|
data/Rakefile
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module YandexDirect
|
|
2
|
+
class Campaign
|
|
3
|
+
SERVICE = 'campaigns'
|
|
4
|
+
attr_accessor :name, :start_date, :time_zone, :id
|
|
5
|
+
|
|
6
|
+
def initialize(params)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.list
|
|
10
|
+
YandexDirect.request(SERVICE, 'get', {
|
|
11
|
+
"SelectionCriteria": {
|
|
12
|
+
"Types": ["TEXT_CAMPAIGN"],
|
|
13
|
+
"States": ["OFF", "ON"],
|
|
14
|
+
"Statuses": ["ACCEPTED", "DRAFT", "MODERATION"]
|
|
15
|
+
},
|
|
16
|
+
"FieldNames": ['Id', 'Name', 'State', 'Status']
|
|
17
|
+
})
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'net/https'
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'yaml'
|
|
5
|
+
require 'uri'
|
|
6
|
+
|
|
7
|
+
module YandexDirect
|
|
8
|
+
class RuntimeError < RuntimeError
|
|
9
|
+
end
|
|
10
|
+
class NotFound < RuntimeError
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.url
|
|
14
|
+
configuration['sandbox'] ? 'https://api.direct.yandex.com/json/v5/' : 'https://api-sandbox.direct.yandex.com/json/v5/'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.configuration
|
|
18
|
+
if defined? @environment
|
|
19
|
+
raise RuntimeError.new("Configure yandex-direct-api for #{@environment} environment.") unless @configuration
|
|
20
|
+
else
|
|
21
|
+
raise RuntimeError.new('Configure yandex-direct-api for current environment.') unless @configuration
|
|
22
|
+
end
|
|
23
|
+
@configuration
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.parse_json json
|
|
27
|
+
begin
|
|
28
|
+
return JSON.parse(json)
|
|
29
|
+
rescue => e
|
|
30
|
+
raise RuntimeError.new "#{e.message} in response."
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.load file, env = nil
|
|
35
|
+
@environment = env.to_s if env
|
|
36
|
+
config = YAML.load_file(file)
|
|
37
|
+
@configuration = defined?(@environment) ? config[@environment] : config
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.request(service, method, params = {})
|
|
41
|
+
uri = URI(url + service)
|
|
42
|
+
body = {
|
|
43
|
+
locale: configuration['locale'],
|
|
44
|
+
token: configuration['token'],
|
|
45
|
+
method: method.
|
|
46
|
+
param: params
|
|
47
|
+
}
|
|
48
|
+
if configuration['verbose']
|
|
49
|
+
puts "\t\033[32mYandex.Direct:\033[0m #{method}(#{body[:param]})"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
53
|
+
http.use_ssl = true
|
|
54
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
55
|
+
response = http.post(uri.path, JSON.generate(body))
|
|
56
|
+
|
|
57
|
+
raise Yandex::API::RuntimeError.new("#{response.code} - #{response.message}") unless response.code.to_i == 200
|
|
58
|
+
|
|
59
|
+
json = parse_json(response.body)
|
|
60
|
+
|
|
61
|
+
if json.has_key?('error_code') and json.has_key?('error_str')
|
|
62
|
+
code = json['error_code'].to_i
|
|
63
|
+
error = json['error_detail'].length > 0 ? json['error_detail'] : json['error_str']
|
|
64
|
+
raise RuntimeError.new "#{code} - #{error}"
|
|
65
|
+
end
|
|
66
|
+
return json['data']
|
|
67
|
+
end
|
|
68
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: yandex-direct-api
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- AliceO
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-07-19 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Gem for interaction with Yandex Direct API version 5
|
|
14
|
+
email: aliceo.jjm@gmail.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- Rakefile
|
|
20
|
+
- lib/services/campaign.rb
|
|
21
|
+
- lib/yandex_direct_api.rb
|
|
22
|
+
homepage: https://github.com/aliceojjm/yandex-direct-api
|
|
23
|
+
licenses: []
|
|
24
|
+
metadata: {}
|
|
25
|
+
post_install_message:
|
|
26
|
+
rdoc_options: []
|
|
27
|
+
require_paths:
|
|
28
|
+
- lib
|
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
requirements: []
|
|
40
|
+
rubyforge_project:
|
|
41
|
+
rubygems_version: 2.4.8
|
|
42
|
+
signing_key:
|
|
43
|
+
specification_version: 4
|
|
44
|
+
summary: Gem for interaction with Yandex Direct API version 5
|
|
45
|
+
test_files: []
|
|
46
|
+
has_rdoc:
|