yandex_api_direct 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +0 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/yandex_api_direct/call.rb +42 -0
- data/lib/yandex_api_direct/configuration.rb +13 -0
- data/lib/yandex_api_direct/methods.rb +29 -0
- data/lib/yandex_api_direct/version.rb +3 -0
- data/lib/yandex_api_direct.rb +52 -0
- data/yandex_api_direct.gemspec +33 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f0b0a4e423abba86b9b523d0588a7d0c7a5a2085
|
4
|
+
data.tar.gz: 9f3f2317a2b4107119673e3b04306710a2c5082b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 41a7ff3d724c2ea3863639e89a5edb5fc11b66de496f3df0d2e3c58ed1bcf6e01c2eff199d192263fd849e47369dd5ee1791d83ba11687cfc8d87dec6833c18f
|
7
|
+
data.tar.gz: aa2312d2a85ebd722d264675ace4d23792e04cdaaef7d0fef537fdbaecfca05a3d5b47a54c94400490198de919fa5a2e5213db9ef20211fb3c7b319969f18860
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Sergey Makarov
|
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
File without changes
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "yandex_api_direct"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module YandexApiDirect
|
2
|
+
module Call
|
3
|
+
def call(method_name, params = {})
|
4
|
+
http(method_name, params) do |response|
|
5
|
+
raise YandexApiDirect::MethodCallError, response.body unless response.is_a?(Net::HTTPSuccess)
|
6
|
+
json = response.body
|
7
|
+
raise YandexApiDirect::MethodCallError, 'Response could not be empty' if json.nil? || json.empty?
|
8
|
+
parsed_json = JSON.parse(json, symbolize_names: true)
|
9
|
+
raise YandexApiDirect::MethodCallError, json if is_error?(parsed_json)
|
10
|
+
raise YandexApiDirect::MethodCallError, 'Response should include key named :result' unless parsed_json.has_key?(:result)
|
11
|
+
parsed_json[:result]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def http(method_name, params = {})
|
16
|
+
uri = URI(method_url(method_name))
|
17
|
+
req = Net::HTTP::Post.new(uri, headers)
|
18
|
+
req.body = params.to_json
|
19
|
+
yield (
|
20
|
+
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true).request(req)
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def method_url(method_name)
|
25
|
+
if method_name.nil? || method_name.empty?
|
26
|
+
raise ArgumentError, 'Method name could not be empty'
|
27
|
+
end
|
28
|
+
"#{base_url}/#{method_name}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def is_error?(parsed_json)
|
32
|
+
parsed_json.has_key?(:error)
|
33
|
+
end
|
34
|
+
|
35
|
+
def headers
|
36
|
+
{
|
37
|
+
'Authorization' => "Bearer #{access_token}",
|
38
|
+
'Content-Type' => 'application/json; charset=utf-8'
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module YandexApiDirect
|
2
|
+
class Configuration
|
3
|
+
BASE_URL_DEFAULT = "https://api.direct.yandex.com/json/v5".freeze
|
4
|
+
|
5
|
+
attr_accessor :app_id
|
6
|
+
attr_accessor :access_token
|
7
|
+
attr_accessor :base_url
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@base_url = YandexApiDirect::Configuration::BASE_URL_DEFAULT
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module YandexApiDirect
|
2
|
+
module Methods
|
3
|
+
def method_missing(method_name, *arguments, &block)
|
4
|
+
Proxy.new(self, method_name)
|
5
|
+
end
|
6
|
+
|
7
|
+
def respond_to?(method_name, include_private = false)
|
8
|
+
true # we should respond to any method using Proxy
|
9
|
+
end
|
10
|
+
|
11
|
+
class Proxy
|
12
|
+
attr_accessor :service
|
13
|
+
attr_accessor :resource
|
14
|
+
|
15
|
+
def initialize(service, resource)
|
16
|
+
@service = service
|
17
|
+
@resource = resource
|
18
|
+
end
|
19
|
+
|
20
|
+
def method_missing(method_name, *arguments, &block)
|
21
|
+
service.call(resource, method: method_name, params: arguments.first)
|
22
|
+
end
|
23
|
+
|
24
|
+
def respond_to?(method_name, include_private = false)
|
25
|
+
true # we should respond to any method using Proxy
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module YandexApiDirect
|
5
|
+
autoload :Configuration, "yandex_api_direct/configuration"
|
6
|
+
autoload :Call, "yandex_api_direct/call"
|
7
|
+
autoload :Methods, "yandex_api_direct/methods"
|
8
|
+
|
9
|
+
class MethodCallError < StandardError; end;
|
10
|
+
|
11
|
+
class DirectService
|
12
|
+
include YandexApiDirect::Call
|
13
|
+
include YandexApiDirect::Methods
|
14
|
+
|
15
|
+
def configuration
|
16
|
+
@configuration || YandexApiDirect.configuration
|
17
|
+
end
|
18
|
+
|
19
|
+
def app_id
|
20
|
+
configuration.app_id unless configuration.nil?
|
21
|
+
end
|
22
|
+
|
23
|
+
def base_url
|
24
|
+
if configuration.nil?
|
25
|
+
YandexApiDirect::Configuration::BASE_URL_DEFAULT
|
26
|
+
else
|
27
|
+
configuration.base_url
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def access_token
|
32
|
+
configuration.access_token unless configuration.nil?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class << self
|
37
|
+
attr_accessor :configuration
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.configure
|
41
|
+
self.configuration ||= self::Configuration.new
|
42
|
+
yield(configuration)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.reset_configuration
|
46
|
+
self.configuration = nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.service
|
50
|
+
self::DirectService.new
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'yandex_api_direct/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "yandex_api_direct"
|
8
|
+
spec.version = YandexApiDirect::VERSION
|
9
|
+
spec.authors = ["Sergey Makarov"]
|
10
|
+
spec.email = ["serega.s.makar@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Thin client for direct.yandex.ru API}
|
13
|
+
spec.homepage = "https://github.com/maxsbelt/yandex_api_direct"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
32
|
+
spec.add_development_dependency "webmock", "~> 1.24"
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yandex_api_direct
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergey Makarov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-07 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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.24'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.24'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- serega.s.makar@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- lib/yandex_api_direct.rb
|
86
|
+
- lib/yandex_api_direct/call.rb
|
87
|
+
- lib/yandex_api_direct/configuration.rb
|
88
|
+
- lib/yandex_api_direct/methods.rb
|
89
|
+
- lib/yandex_api_direct/version.rb
|
90
|
+
- yandex_api_direct.gemspec
|
91
|
+
homepage: https://github.com/maxsbelt/yandex_api_direct
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata:
|
95
|
+
allowed_push_host: https://rubygems.org
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.5.1
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Thin client for direct.yandex.ru API
|
116
|
+
test_files: []
|