baidu 2.0.1 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8cf13976ee932f067da1a85dd0c307f22688113
4
- data.tar.gz: 49ce29b70af6c244cc3fdf535e4696ffd6e3278f
3
+ metadata.gz: c9b8eabdad5f511d630d6b08c547b3e36df32189
4
+ data.tar.gz: efd30483fe5357b901b647919db740890c07844b
5
5
  SHA512:
6
- metadata.gz: c719746a1f33233383dc775fd5a184ce28750e63860d0ab4ffe0333baafc7f7aee7dc69e5101abda24b3ee6f39deb47a7dbe1ebbc223ca7a740179a3d70185a6
7
- data.tar.gz: 0a0bf51820b48b9cf890cb0ced4470f4f2caf464a983fb8cd068c0cc024bb575a6f698b40b4a3f366f76ff27ed2c077dea071c75e53ec0797c84757df03b4f1c
6
+ metadata.gz: 6b6fbc268eba762a1414ea0b2cffc6a319e55fd1c8a3e708c226483f4bd060ca118451b22c5466dc3ebd0cca33f3599e2890d4fd8b5131c3e298a2b4c46324c5
7
+ data.tar.gz: 71c57fae2b36d8f91bad436dc4fa39fcdd8b5ed457f5b9ed4fe08f60285781a92ceb4c8f6c4774a736c1c059ae6183a9092a68cdf28d034490c022f151941e53
data/.gitignore CHANGED
@@ -14,4 +14,4 @@ rdoc
14
14
  spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
- tmp
17
+ tmp
@@ -53,6 +53,7 @@ class Savon
53
53
  end
54
54
  require "baidu/version"
55
55
  require "baidu/map"
56
+ require "baidu/translate"
56
57
  require "baidu/sem"
57
58
  require "baidu/rank"
58
59
  require "baidu/auth"
@@ -1,5 +1,4 @@
1
1
  module Baidu
2
2
  module Rank
3
-
4
3
  end
5
- end
4
+ end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Baidu
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.3"
3
3
  end
@@ -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
@@ -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
@@ -2,6 +2,7 @@ require 'baidu'
2
2
  require 'time'
3
3
  #请根据自己实际情况填写
4
4
  BAIDU_MAP_KEY = '' #百度地图TOKEN
5
+ BAIDU_TRANSLATE_KEY = '' #百度翻译APIKEY
5
6
  $searchWord = '' #根据Word查已投放关键词
6
7
  $searchAdgroupName = '' #根据Adgroup查已投放的单元
7
8
  $searchCampaignName = '' #根据Campaign查已投放的计划
@@ -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.1
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