baidu 2.0.1 → 2.0.3
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 +4 -4
- data/.gitignore +1 -1
- data/lib/baidu.rb +1 -0
- data/lib/baidu/rank.rb +1 -2
- data/lib/baidu/translate.rb +36 -0
- data/lib/baidu/version.rb +1 -1
- data/spec/sem_adgroup_spec.rb +1 -1
- data/spec/sem_campaign_spec.rb +0 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/translate_spec.rb +26 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9b8eabdad5f511d630d6b08c547b3e36df32189
|
4
|
+
data.tar.gz: efd30483fe5357b901b647919db740890c07844b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b6fbc268eba762a1414ea0b2cffc6a319e55fd1c8a3e708c226483f4bd060ca118451b22c5466dc3ebd0cca33f3599e2890d4fd8b5131c3e298a2b4c46324c5
|
7
|
+
data.tar.gz: 71c57fae2b36d8f91bad436dc4fa39fcdd8b5ed457f5b9ed4fe08f60285781a92ceb4c8f6c4774a736c1c059ae6183a9092a68cdf28d034490c022f151941e53
|
data/.gitignore
CHANGED
data/lib/baidu.rb
CHANGED
data/lib/baidu/rank.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
module Baidu
|
3
|
+
class Translate
|
4
|
+
include HTTParty
|
5
|
+
# debug_output $stderr
|
6
|
+
base_uri 'openapi.baidu.com'
|
7
|
+
|
8
|
+
def initialize(apikey,from=nil,to=nil)
|
9
|
+
@from_to = %w(zh_en zh_jp en_zh jp_zh)
|
10
|
+
@apikey = apikey
|
11
|
+
unless from.nil? and to.nil?
|
12
|
+
if @from_to.include?"#{from}_#{to}"
|
13
|
+
@from,@to = from,to
|
14
|
+
else
|
15
|
+
warn "invalid options,only allow:#{@from_to}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
def translate(query,from=nil,to=nil)
|
20
|
+
options = {
|
21
|
+
:query =>{
|
22
|
+
:client_id => @apikey,
|
23
|
+
:q=>query,
|
24
|
+
:from=>from||@from,
|
25
|
+
:to=>to||@to
|
26
|
+
}
|
27
|
+
}
|
28
|
+
response = self.class.get('/public/2.0/bmt/translate',options)
|
29
|
+
result = []
|
30
|
+
response['trans_result'].each do |trans|
|
31
|
+
result << trans['dst']
|
32
|
+
end
|
33
|
+
result
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/baidu/version.rb
CHANGED
data/spec/sem_adgroup_spec.rb
CHANGED
@@ -109,7 +109,7 @@ describe Baidu::SEM::AdgroupService do
|
|
109
109
|
response.rquota.should > 0
|
110
110
|
# ap response.body
|
111
111
|
expect{ApiResponse.verify(response.body)}.not_to raise_error
|
112
|
-
ap response.body
|
112
|
+
# ap response.body
|
113
113
|
# it "is not implemented yet" do
|
114
114
|
# pending("this is pending before we have testing-purpose account")
|
115
115
|
# end
|
data/spec/sem_campaign_spec.rb
CHANGED
@@ -35,7 +35,6 @@ describe Baidu::SEM::CampaignService do
|
|
35
35
|
sleep 2
|
36
36
|
options = {:campaignTypes => [campaign_type_update]}
|
37
37
|
response = subject.updateCampaign(options)
|
38
|
-
ap response.body
|
39
38
|
response.status.should == 0
|
40
39
|
response.desc.should == 'success'
|
41
40
|
response.quota.should == 2
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Baidu::Translate do
|
3
|
+
bt = Baidu::Translate.new(BAIDU_TRANSLATE_KEY)
|
4
|
+
it "should translate 'hello' to '您好'" do
|
5
|
+
bt.translate('hello','en','zh').should == ['您好']
|
6
|
+
end
|
7
|
+
it "should translate '您好' into 'Hello'" do
|
8
|
+
bt.translate('hello','zh','en').should == ['Hello']
|
9
|
+
end
|
10
|
+
end
|
11
|
+
describe Baidu::Translate do
|
12
|
+
it "should translate 'hello' to '您好'" do
|
13
|
+
bt = Baidu::Translate.new(BAIDU_TRANSLATE_KEY,'en','zh')
|
14
|
+
bt.translate('hello').should == ['您好']
|
15
|
+
end
|
16
|
+
it "should translate '您好' into 'Hello'" do
|
17
|
+
bt = Baidu::Translate.new(BAIDU_TRANSLATE_KEY,'zh','en')
|
18
|
+
bt.translate('您好').should == ['Hello']
|
19
|
+
end
|
20
|
+
end
|
21
|
+
describe Baidu::Translate do
|
22
|
+
bt = Baidu::Translate.new(BAIDU_TRANSLATE_KEY,'zh','en')
|
23
|
+
it "should cover translating options" do
|
24
|
+
bt.translate('hello','en','zh').should == ['您好']
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: baidu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- seoaqua
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- lib/baidu/sem/new_creative.rb
|
112
112
|
- lib/baidu/sem/report.rb
|
113
113
|
- lib/baidu/sem/search.rb
|
114
|
+
- lib/baidu/translate.rb
|
114
115
|
- lib/baidu/version.rb
|
115
116
|
- lib/ext.rb
|
116
117
|
- spec/map_spec.rb
|
@@ -124,6 +125,7 @@ files:
|
|
124
125
|
- spec/sem_report_spec.rb
|
125
126
|
- spec/sem_search_spec.rb
|
126
127
|
- spec/spec_helper.rb
|
128
|
+
- spec/translate_spec.rb
|
127
129
|
homepage: http://github.com/seoaqua/baidu
|
128
130
|
licenses:
|
129
131
|
- MIT
|
@@ -160,3 +162,4 @@ test_files:
|
|
160
162
|
- spec/sem_report_spec.rb
|
161
163
|
- spec/sem_search_spec.rb
|
162
164
|
- spec/spec_helper.rb
|
165
|
+
- spec/translate_spec.rb
|