yandex-api 0.0.3 → 0.0.5
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 +2 -0
- data/README.md +58 -12
- data/examples/yandex_direct.yml +18 -0
- data/examples/yandex_translate.yml +12 -0
- data/lib/yandex-api/direct/banner_info.rb +13 -12
- data/lib/yandex-api/direct/base.rb +17 -15
- data/lib/yandex-api/direct/campaign_info.rb +10 -10
- data/lib/yandex-api/direct.rb +26 -22
- data/lib/yandex-api/translate.rb +91 -0
- data/lib/yandex-api/version.rb +1 -1
- data/lib/yandex-api.rb +7 -5
- data/spec/direct_spec.rb +12 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/translate_spec.rb +25 -0
- data/test.rb +0 -0
- data/yandex-api.gemspec +9 -5
- data/yandex.yml +2 -0
- metadata +63 -12
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a507df6506f1d68f303565a994fce28daa38bde6
|
4
|
+
data.tar.gz: 811573b2767650e970b5dcb44f10f454c1ccafb4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eb6dceefb263d50bfb5126be0d288b9a8e928fe1dd46bcdaf3fbf7934decf603b9007bdd2bf2efb2d6bfa18d1e894c4d007f55b03ee4f80c69feaad7f83250f0
|
7
|
+
data.tar.gz: 76aac042480b9f89a53155d2e735a33847158a0520feea52c0978164a22732fc80937be74b003e8ae89ebab5baa7ecd14c596cfc2867ef7d6560622a8ec81fde
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
# Yandex::API
|
2
2
|
|
3
|
+
<a href="http://badge.fury.io/rb/yandex-api"><img src="https://badge.fury.io/rb/yandex-api@2x.png" alt="Gem Version" height="18"></a>
|
4
|
+
|
3
5
|
Позволяет работать с сервисами Яндекс доступными через API
|
4
6
|
|
5
7
|
Доступные модули:
|
6
8
|
* Direct - Автоматизация рекламных кампаний в Яндекс.Директе (http://direct.yandex.ru/)
|
9
|
+
* Translate - Позволяет получить доступ к онлайн-сервису машинного перевода Яндекса (http://translate.yandex.ru/)
|
7
10
|
|
8
11
|
## Установка
|
9
12
|
|
@@ -19,32 +22,34 @@
|
|
19
22
|
|
20
23
|
$ gem install yandex-api
|
21
24
|
|
22
|
-
|
25
|
+
|
26
|
+
## Direct
|
27
|
+
### в Ruby:
|
23
28
|
|
24
29
|
Создать конфигурационный файл yandex_direct.yml
|
25
30
|
|
26
|
-
token:
|
27
|
-
|
28
|
-
|
29
|
-
locale: "ru"
|
31
|
+
token: token
|
32
|
+
login: login
|
33
|
+
locale: ru
|
30
34
|
verbose: true
|
35
|
+
sandbox: true
|
31
36
|
|
32
|
-
|
37
|
+
### в Ruby On Rails:
|
33
38
|
|
34
39
|
Создать конфигурационный файл yandex_direct.yml
|
35
40
|
|
36
41
|
development:
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
+
token: token
|
43
|
+
login: login
|
44
|
+
locale: ru
|
45
|
+
verbose: true
|
46
|
+
sandbox: true
|
42
47
|
|
43
48
|
Добавить в initializers файл yandex_direct.rb
|
44
49
|
|
45
50
|
Yandex::API::Direct.load File.join(Rails.root,"config","yandex_direct.yml"), Rails.env
|
46
51
|
|
47
|
-
|
52
|
+
### Пример работы:
|
48
53
|
|
49
54
|
require 'yandex-api'
|
50
55
|
Yandex::API::Direct.load "yandex_direct.yml"
|
@@ -52,3 +57,44 @@
|
|
52
57
|
campaign = Yandex::API::Direct::CampaignInfo.list.first
|
53
58
|
puts campaign.inspect
|
54
59
|
puts campaign.banners.first.inspect
|
60
|
+
|
61
|
+
## Translate
|
62
|
+
### в Ruby:
|
63
|
+
|
64
|
+
Создать конфигурационный файл yandex_direct.yml
|
65
|
+
|
66
|
+
token: "token"
|
67
|
+
ui: true
|
68
|
+
verbose: true
|
69
|
+
|
70
|
+
### в Ruby On Rails:
|
71
|
+
|
72
|
+
Создать конфигурационный файл yandex_translate.yml
|
73
|
+
|
74
|
+
development:
|
75
|
+
token: "token"
|
76
|
+
ui: "ru"
|
77
|
+
verbose: true
|
78
|
+
|
79
|
+
Добавить в initializers файл yandex_translate.rb
|
80
|
+
|
81
|
+
Yandex::API::Translate.load File.join(Rails.root,"config","yandex_translate.yml"), Rails.env
|
82
|
+
|
83
|
+
|
84
|
+
### Пример работы
|
85
|
+
|
86
|
+
require 'yandex-api'
|
87
|
+
Yandex::API::Translate.load "yandex.yml", "production"
|
88
|
+
|
89
|
+
puts Yandex::API::Translate.languages.inspect
|
90
|
+
puts Yandex::API::Translate.detect('test').inspect
|
91
|
+
puts Yandex::API::Translate.do('Hello GitHub', 'ru').inspect
|
92
|
+
|
93
|
+
|
94
|
+
## Contributing
|
95
|
+
|
96
|
+
1. Fork it ( https://github.com/jpascal/yandex-api/fork )
|
97
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
98
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
99
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
100
|
+
5. Create a new Pull Request
|
@@ -0,0 +1,18 @@
|
|
1
|
+
development:
|
2
|
+
token: token
|
3
|
+
login: login
|
4
|
+
locale: ru
|
5
|
+
verbose: true
|
6
|
+
sandbox: true
|
7
|
+
test:
|
8
|
+
token: token
|
9
|
+
login: login
|
10
|
+
locale: ru
|
11
|
+
verbose: true
|
12
|
+
sandbox: true
|
13
|
+
production:
|
14
|
+
token: token
|
15
|
+
login: login
|
16
|
+
locale: ru
|
17
|
+
verbose: true
|
18
|
+
sandbox: true
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
#
|
2
3
|
# Взаимодействие с API Яндекс.Директа в формате JSON.
|
3
4
|
# http://api.yandex.ru/direct/doc/concepts/JSON.xml
|
@@ -18,7 +19,7 @@ module Yandex::API
|
|
18
19
|
#
|
19
20
|
class BannerPhraseInfo < Base
|
20
21
|
direct_attributes :PhraseID, :Phrase, :IsRubric, :Price, :AutoBudgetPriority, :ContextPrice, :AutoBroker
|
21
|
-
direct_objects
|
22
|
+
direct_objects :UserParams => PhraseUserParams
|
22
23
|
end
|
23
24
|
|
24
25
|
#
|
@@ -41,7 +42,7 @@ module Yandex::API
|
|
41
42
|
class ContactInfo < Base
|
42
43
|
direct_attributes :CompanyName, :ContactPerson, :Country, :CountryCode, :City, :Street, :House, :Build,
|
43
44
|
:Apart, :CityCode, :Phone, :PhoneExt, :IMClient, :IMLogin, :ExtraMessage, :ContactEmail, :WorkTime, :OGRN
|
44
|
-
direct_objects
|
45
|
+
direct_objects :PointOnMap => MapPoint
|
45
46
|
end
|
46
47
|
|
47
48
|
#
|
@@ -49,34 +50,34 @@ module Yandex::API
|
|
49
50
|
#
|
50
51
|
class BannerInfo < Base
|
51
52
|
direct_attributes :BannerID, :CampaignID, :Title, :Text, :Href, :Geo, :MinusKeywords
|
52
|
-
direct_arrays
|
53
|
-
direct_objects
|
53
|
+
direct_arrays :Phrases => BannerPhraseInfo, :Sitelinks => Sitelink
|
54
|
+
direct_objects :ContactInfo => ContactInfo
|
54
55
|
def self.find id
|
55
|
-
result = Direct::request(
|
56
|
+
result = Direct::request('GetBanners', {:BannerIDS => [id]})
|
56
57
|
raise Yandex::NotFound.new("not found banner where id = #{id}") unless result.any?
|
57
58
|
banner = new(result.first)
|
58
59
|
end
|
59
60
|
def save
|
60
|
-
Direct::request(
|
61
|
+
Direct::request('CreateOrUpdateBanners', [self.to_hash]).first
|
61
62
|
end
|
62
63
|
|
63
64
|
def archive
|
64
|
-
Direct::request(
|
65
|
+
Direct::request('ArchiveBanners', {:CampaignID => self.CampaignID, :BannerIDS => [self.BannerID]})
|
65
66
|
end
|
66
67
|
def unarchive
|
67
|
-
Direct::request(
|
68
|
+
Direct::request('UnArchiveCampaign', {:CampaignID => self.CampaignID, :BannerIDS => [self.BannerID]})
|
68
69
|
end
|
69
70
|
def moderate
|
70
|
-
Direct::request(
|
71
|
+
Direct::request('ModerateBanners', {:CampaignID => self.CampaignID, :BannerIDS => [self.BannerID]})
|
71
72
|
end
|
72
73
|
def resume
|
73
|
-
Direct::request(
|
74
|
+
Direct::request('ResumeBanners', {:CampaignID => self.CampaignID, :BannerIDS => [self.BannerID]})
|
74
75
|
end
|
75
76
|
def stop
|
76
|
-
Direct::request(
|
77
|
+
Direct::request('StopBanners', {:CampaignID => self.CampaignID, :BannerIDS => [self.BannerID]})
|
77
78
|
end
|
78
79
|
def delete
|
79
|
-
Direct::request(
|
80
|
+
Direct::request('DeleteBanners', {:CampaignID => self.CampaignID, :BannerIDS => [self.BannerID]})
|
80
81
|
end
|
81
82
|
end
|
82
83
|
end
|
@@ -6,25 +6,25 @@ module Yandex::API::Direct
|
|
6
6
|
args.each do |arg|
|
7
7
|
@attributes << arg
|
8
8
|
self.class_eval("def #{arg};@#{arg};end")
|
9
|
-
self.class_eval("def #{arg}=(val);@#{arg}=val;end")
|
9
|
+
self.class_eval("def #{arg}=(val);@#{arg}=val;end")
|
10
10
|
end
|
11
11
|
end
|
12
12
|
def self.objects ; @objects || [] ; end
|
13
|
-
def self.direct_objects
|
13
|
+
def self.direct_objects options
|
14
14
|
@objects = []
|
15
|
-
|
16
|
-
@objects << [
|
17
|
-
self.class_eval("def #{
|
18
|
-
self.class_eval("def #{
|
15
|
+
options.each do |name,type|
|
16
|
+
@objects << [name,type]
|
17
|
+
self.class_eval("def #{name};@#{name};end")
|
18
|
+
self.class_eval("def #{name}=(val);@#{name}=val;end")
|
19
19
|
end
|
20
20
|
end
|
21
21
|
def self.arrays ; @arrays || [] ; end
|
22
|
-
def self.direct_arrays
|
22
|
+
def self.direct_arrays options
|
23
23
|
@arrays = []
|
24
|
-
|
25
|
-
@arrays << [
|
26
|
-
self.class_eval("def #{
|
27
|
-
self.class_eval("def #{
|
24
|
+
options.each do |name,type|
|
25
|
+
@arrays << [name,type]
|
26
|
+
self.class_eval("def #{name};@#{name};end")
|
27
|
+
self.class_eval("def #{name}=(val);@#{name}=val;end")
|
28
28
|
end
|
29
29
|
end
|
30
30
|
def to_hash
|
@@ -32,7 +32,7 @@ module Yandex::API::Direct
|
|
32
32
|
# build hash of attributes
|
33
33
|
self.class.attributes.each do |attribute|
|
34
34
|
value = send(attribute)
|
35
|
-
next unless value.
|
35
|
+
next unless not value.nil?
|
36
36
|
result[attribute] = value
|
37
37
|
end
|
38
38
|
# build hash of arrays
|
@@ -45,10 +45,12 @@ module Yandex::API::Direct
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
# build hash of objects
|
48
|
-
self.class.objects.each do |
|
49
|
-
|
48
|
+
self.class.objects.each do |name,_|
|
49
|
+
object = send(name)
|
50
|
+
next if object.nil?
|
51
|
+
value_hash = send(name).to_hash || {}
|
50
52
|
next if value_hash.empty?
|
51
|
-
result[
|
53
|
+
result[name] = value_hash
|
52
54
|
end
|
53
55
|
result
|
54
56
|
end
|
@@ -48,41 +48,41 @@ module Yandex::API
|
|
48
48
|
direct_attributes :Login, :CampaignID, :Name, :FIO, :StartDate, :StatusBehavior, :StatusContextStop, :ContextLimit, :ContextLimitSum, :ContextPricePercent,
|
49
49
|
:AutoOptimization, :StatusMetricaControl, :DisabledDomains, :DisabledIps, :StatusOpenStat, :ConsiderTimeTarget, :MinusKeywords, :AddRelevantPhrases,
|
50
50
|
:RelevantPhrasesBudgetLimit
|
51
|
-
direct_objects
|
51
|
+
direct_objects :Strategy => CampaignStrategy, :SmsNotification => SmsNotification, :EmailNotification => EmailNotification, :TimeTarget => TimeTarget
|
52
52
|
|
53
53
|
def banners
|
54
54
|
banners = []
|
55
|
-
Direct::request(
|
55
|
+
Direct::request('GetBanners', {:CampaignIDS => [self.CampaignID]}).each do |banner|
|
56
56
|
banners << BannerInfo.new(banner)
|
57
57
|
end
|
58
58
|
banners
|
59
59
|
end
|
60
60
|
def save
|
61
|
-
Direct::request(
|
61
|
+
Direct::request('CreateOrUpdateCampaign', self.to_hash)
|
62
62
|
end
|
63
63
|
def archive
|
64
|
-
Direct::request(
|
64
|
+
Direct::request('ArchiveCampaign', {:CampaignID => self.CampaignID})
|
65
65
|
end
|
66
66
|
def unarchive
|
67
|
-
Direct::request(
|
67
|
+
Direct::request('UnArchiveCampaign', {:CampaignID => self.CampaignID})
|
68
68
|
end
|
69
69
|
def resume
|
70
|
-
Direct::request(
|
70
|
+
Direct::request('ResumeCampaign', {:CampaignID => self.CampaignID})
|
71
71
|
end
|
72
72
|
def stop
|
73
|
-
Direct::request(
|
73
|
+
Direct::request('StopCampaign', {:CampaignID => self.CampaignID})
|
74
74
|
end
|
75
75
|
def delete
|
76
|
-
Direct::request(
|
76
|
+
Direct::request('DeleteCampaign', {:CampaignID => self.CampaignID})
|
77
77
|
end
|
78
78
|
def self.find id
|
79
|
-
result = Direct::request(
|
79
|
+
result = Direct::request('GetCampaignParams', {:CampaignID => id})
|
80
80
|
raise Yandex::NotFound.new("not found campaign where CampaignID = #{id}") if result.empty?
|
81
81
|
new(result)
|
82
82
|
end
|
83
83
|
def self.list
|
84
84
|
campaigs = []
|
85
|
-
Direct::request(
|
85
|
+
Direct::request('GetCampaignsList').each do |campaig|
|
86
86
|
campaigs << new(campaig)
|
87
87
|
end
|
88
88
|
campaigs
|
data/lib/yandex-api/direct.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'net/http'
|
2
|
+
require 'net/https'
|
2
3
|
require 'json'
|
3
4
|
require 'yaml'
|
4
5
|
require 'uri'
|
@@ -6,13 +7,14 @@ require 'uri'
|
|
6
7
|
module Yandex
|
7
8
|
module API
|
8
9
|
module Direct
|
9
|
-
URL_API =
|
10
|
-
|
10
|
+
URL_API = 'https://api.direct.yandex.ru/v4/json/'
|
11
|
+
URL_API_SANDBOX = 'https://api-sandbox.direct.yandex.ru/v4/json/'
|
12
|
+
|
11
13
|
def self.configuration
|
12
|
-
if defined? @
|
13
|
-
raise RuntimeError.new("not configured Yandex.Direct for #{@
|
14
|
+
if defined? @environment
|
15
|
+
raise RuntimeError.new("not configured Yandex.Direct for #{@environment} enviroment") unless @configuration
|
14
16
|
else
|
15
|
-
raise RuntimeError.new(
|
17
|
+
raise RuntimeError.new('not configured Yandex.Direct') unless @configuration
|
16
18
|
end
|
17
19
|
@configuration
|
18
20
|
end
|
@@ -26,28 +28,30 @@ module Yandex
|
|
26
28
|
end
|
27
29
|
|
28
30
|
def self.load file, env = nil
|
29
|
-
@
|
31
|
+
@environment = env.to_s if env
|
30
32
|
config = YAML.load_file(file)
|
31
|
-
@configuration = defined?(@
|
33
|
+
@configuration = defined?(@environment) ? config[@environment] : config
|
34
|
+
@configuration['sandbox'] ||= false
|
32
35
|
end
|
33
36
|
|
34
37
|
def self.request method, params = {}
|
35
38
|
|
36
39
|
body = {
|
37
|
-
:locale => configuration[
|
38
|
-
:
|
39
|
-
:application_id => configuration["application_id"],
|
40
|
-
:token => configuration["application_token"],
|
40
|
+
:locale => configuration['locale'],
|
41
|
+
:token => configuration['token'],
|
41
42
|
:method => method
|
42
43
|
}
|
43
|
-
|
44
|
-
body.merge!({:param => params}) unless params.empty?
|
45
|
-
url = URI.parse(URL_API)
|
46
44
|
|
47
|
-
if
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
if body[:method] == 'GetCampaignsList'
|
46
|
+
body.merge!({:param => [configuration['login']]})
|
47
|
+
else
|
48
|
+
body.merge!({:param => params})
|
49
|
+
end
|
50
|
+
|
51
|
+
url = URI((configuration['sandbox'] ? URL_API_SANDBOX : URL_API))
|
52
|
+
|
53
|
+
if configuration['verbose']
|
54
|
+
puts "\t\033[32mYandex.Direct:\033[0m #{method}(#{body[:param]})"
|
51
55
|
end
|
52
56
|
|
53
57
|
http = Net::HTTP.new(url.host, url.port)
|
@@ -59,13 +63,13 @@ module Yandex
|
|
59
63
|
|
60
64
|
json = Direct.parse_json(response.body)
|
61
65
|
|
62
|
-
if json.has_key?(
|
63
|
-
code = json[
|
64
|
-
error = json[
|
66
|
+
if json.has_key?('error_code') and json.has_key?('error_str')
|
67
|
+
code = json['error_code'].to_i
|
68
|
+
error = json['error_detail'].length > 0 ? json['error_detail'] : json['error_str']
|
65
69
|
raise RuntimeError.new "#{code} - #{error}"
|
66
70
|
end
|
67
71
|
|
68
|
-
return json[
|
72
|
+
return json['data']
|
69
73
|
end
|
70
74
|
end
|
71
75
|
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'net/https'
|
3
|
+
require 'json'
|
4
|
+
require 'yaml'
|
5
|
+
require 'uri'
|
6
|
+
require 'cgi'
|
7
|
+
|
8
|
+
module Yandex
|
9
|
+
module API
|
10
|
+
module Translate
|
11
|
+
URL_API = 'https://translate.yandex.net/'
|
12
|
+
|
13
|
+
def self.configuration
|
14
|
+
if defined? @environment
|
15
|
+
raise RuntimeError.new("not configured Yandex.Translate for #{@environment} enviroment") unless @configuration
|
16
|
+
else
|
17
|
+
raise RuntimeError.new('not configured Yandex.Translate') unless @configuration
|
18
|
+
end
|
19
|
+
@configuration
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.load file, env = nil
|
23
|
+
@environment = env.to_s if env
|
24
|
+
config = YAML.load_file(file)
|
25
|
+
@configuration = defined?(@environment) ? config[@environment] : config
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.parse_json json
|
29
|
+
begin
|
30
|
+
return JSON.parse(json)
|
31
|
+
rescue => e
|
32
|
+
raise RuntimeError.new "#{e.message} in response"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.connection
|
37
|
+
return @connection if defined? @connection
|
38
|
+
uri = URI.parse(URL_API)
|
39
|
+
@connection = Net::HTTP.new(uri.host, uri.port)
|
40
|
+
if uri.scheme == "https"
|
41
|
+
@connection.use_ssl = true
|
42
|
+
@connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
43
|
+
end
|
44
|
+
return @connection
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.request path, params = {}
|
48
|
+
|
49
|
+
if configuration['verbose']
|
50
|
+
puts "\t\033[32mYandex.Translate:\033[0m #{params}"
|
51
|
+
end
|
52
|
+
|
53
|
+
query = (
|
54
|
+
params.merge!({
|
55
|
+
:key => configuration['token'],
|
56
|
+
:ui => configuration['ui']
|
57
|
+
})
|
58
|
+
).collect {|key,value| "#{key.to_s}=#{CGI.escape(value.to_s)}" }.join("&")
|
59
|
+
|
60
|
+
response = connection.send(:get,[File.join('/api/v1.5/tr.json',path.to_s),query].join("?"))
|
61
|
+
|
62
|
+
json = Direct.parse_json(response.body)
|
63
|
+
|
64
|
+
if json.has_key?('code') and json.has_key?('message')
|
65
|
+
raise RuntimeError.new "#{json['code']} - #{json['message']}"
|
66
|
+
end
|
67
|
+
return json
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.languages
|
71
|
+
request(:getLangs)
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.detect(text)
|
75
|
+
result = request(:detect, :text => text)
|
76
|
+
if result.include? 'lang'
|
77
|
+
return result['lang']
|
78
|
+
else
|
79
|
+
raise RuntimeError.new "#{json['code']} - Can't detect language"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.do(text, lang, options = {})
|
84
|
+
request(:translate, options.merge({
|
85
|
+
:text => text,
|
86
|
+
:lang => lang
|
87
|
+
}))
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/lib/yandex-api/version.rb
CHANGED
data/lib/yandex-api.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require 'yandex-api/version'
|
2
|
+
require 'yandex-api/direct'
|
3
|
+
require 'yandex-api/direct/base'
|
4
|
+
require 'yandex-api/direct/banner_info'
|
5
|
+
require 'yandex-api/direct/campaign_info'
|
6
|
+
|
7
|
+
require 'yandex-api/translate'
|
6
8
|
|
7
9
|
module Yandex
|
8
10
|
module API
|
data/spec/direct_spec.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Yandex::API::Direct do
|
4
|
+
before { Yandex::API::Direct.load File.join(File.dirname(__FILE__),'yandex_direct.yml'), :test }
|
5
|
+
it 'config' do
|
6
|
+
expect(Yandex::API::Direct.configuration).not_to be_nil
|
7
|
+
end
|
8
|
+
it 'campaigns' do
|
9
|
+
campaigns = Yandex::API::Direct::CampaignInfo.list
|
10
|
+
expect(campaigns).not_to be_nil
|
11
|
+
end
|
12
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Yandex::API::Translate do
|
4
|
+
before { Yandex::API::Translate.load File.join(File.dirname(__FILE__),'yandex_translate.yml'), :test }
|
5
|
+
it 'config' do
|
6
|
+
expect(Yandex::API::Translate.configuration).not_to be_nil
|
7
|
+
end
|
8
|
+
it 'languages' do
|
9
|
+
languages = Yandex::API::Translate.languages
|
10
|
+
expect(languages).to have_key('dirs')
|
11
|
+
expect(languages['dirs']).to include('ru-en')
|
12
|
+
end
|
13
|
+
it 'detect' do
|
14
|
+
expect(Yandex::API::Translate.detect('Ruby')).to eql('en')
|
15
|
+
expect(Yandex::API::Translate.detect('Руби')).to eql('ru')
|
16
|
+
end
|
17
|
+
it 'translate' do
|
18
|
+
result = Yandex::API::Translate.do('Рубин', :en)
|
19
|
+
expect(result).to have_key('code')
|
20
|
+
expect(result).to have_key('lang')
|
21
|
+
expect(result).to have_key('text')
|
22
|
+
expect(result['lang']).to eql('ru-en')
|
23
|
+
expect(result['text']).to include('Ruby')
|
24
|
+
end
|
25
|
+
end
|
data/test.rb
ADDED
File without changes
|
data/yandex-api.gemspec
CHANGED
@@ -2,16 +2,20 @@
|
|
2
2
|
require File.expand_path('../lib/yandex-api/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = [
|
6
|
-
gem.email = [
|
5
|
+
gem.authors = ['Evgeniy Shurmin']
|
6
|
+
gem.email = ['eshurmin@gmail.com']
|
7
7
|
gem.description = %q{Yandex.API integration}
|
8
8
|
gem.summary = %q{Yandex.API integration}
|
9
|
-
gem.homepage =
|
9
|
+
gem.homepage = 'https://github.com/jpascal/yandex-api'
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\)
|
12
12
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
13
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
-
gem.name =
|
15
|
-
gem.require_paths = [
|
14
|
+
gem.name = 'yandex-api'
|
15
|
+
gem.require_paths = ['lib']
|
16
16
|
gem.version = Yandex::API::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency 'bundler', '~> 1.7'
|
19
|
+
gem.add_development_dependency 'rake', '~> 10.0'
|
20
|
+
gem.add_development_dependency 'rspec'
|
17
21
|
end
|
data/yandex.yml
ADDED
metadata
CHANGED
@@ -1,16 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yandex-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Evgeniy Shurmin
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
11
|
+
date: 2015-01-20 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
14
55
|
description: Yandex.API integration
|
15
56
|
email:
|
16
57
|
- eshurmin@gmail.com
|
@@ -18,40 +59,50 @@ executables: []
|
|
18
59
|
extensions: []
|
19
60
|
extra_rdoc_files: []
|
20
61
|
files:
|
21
|
-
- .gitignore
|
62
|
+
- ".gitignore"
|
22
63
|
- Gemfile
|
23
64
|
- LICENSE
|
24
65
|
- README.md
|
25
66
|
- Rakefile
|
67
|
+
- examples/yandex_direct.yml
|
68
|
+
- examples/yandex_translate.yml
|
26
69
|
- lib/yandex-api.rb
|
27
70
|
- lib/yandex-api/direct.rb
|
28
71
|
- lib/yandex-api/direct/banner_info.rb
|
29
72
|
- lib/yandex-api/direct/base.rb
|
30
73
|
- lib/yandex-api/direct/campaign_info.rb
|
74
|
+
- lib/yandex-api/translate.rb
|
31
75
|
- lib/yandex-api/version.rb
|
76
|
+
- spec/direct_spec.rb
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
- spec/translate_spec.rb
|
79
|
+
- test.rb
|
32
80
|
- yandex-api.gemspec
|
81
|
+
- yandex.yml
|
33
82
|
homepage: https://github.com/jpascal/yandex-api
|
34
83
|
licenses: []
|
84
|
+
metadata: {}
|
35
85
|
post_install_message:
|
36
86
|
rdoc_options: []
|
37
87
|
require_paths:
|
38
88
|
- lib
|
39
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
-
none: false
|
41
90
|
requirements:
|
42
|
-
- -
|
91
|
+
- - ">="
|
43
92
|
- !ruby/object:Gem::Version
|
44
93
|
version: '0'
|
45
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
-
none: false
|
47
95
|
requirements:
|
48
|
-
- -
|
96
|
+
- - ">="
|
49
97
|
- !ruby/object:Gem::Version
|
50
98
|
version: '0'
|
51
99
|
requirements: []
|
52
100
|
rubyforge_project:
|
53
|
-
rubygems_version:
|
101
|
+
rubygems_version: 2.4.5
|
54
102
|
signing_key:
|
55
|
-
specification_version:
|
103
|
+
specification_version: 4
|
56
104
|
summary: Yandex.API integration
|
57
|
-
test_files:
|
105
|
+
test_files:
|
106
|
+
- spec/direct_spec.rb
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
- spec/translate_spec.rb
|