bing_translator 3.2.1 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bing_translator.rb +9 -0
  3. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a57fe1f1af5dd52c3580b892f59093e0e62a2c7c
4
- data.tar.gz: 190fbfef3298826d8cc4634335f04ea6cf2934cf
3
+ metadata.gz: 53e0ddff3b2953227f6e61bbe570910d8ed13648
4
+ data.tar.gz: fb795bf1aa917a82d9e440e092cbff13b6c970aa
5
5
  SHA512:
6
- metadata.gz: a5b6b4352628d12c281e4ef2fe214b4e4aee4afb588dbf0273e0f5b9927bbfa1d185d096b1f1e010cda7b78536026a982ede3b5337c83060f13ec6f02288e270
7
- data.tar.gz: 873159ca94499af4e4ab0927600f988df73616a083116f71136e017dbd694dbb00fb4ff51e86b94ce46cd44ad4665645f149dcdbb31f2d64e5ae0fc4237a855a
6
+ metadata.gz: ca4aec07220956fcdc5245217b47800dbd6aedc65281f38a1aff64136573c3cc822fa6b60ed451e4b34ea84023cf18d8cabee7ffcfb05c869f3dc83cb47d216b
7
+ data.tar.gz: b4c4ce7fa7243ea69e1eda1e295c90a92f7394d627c1699be005794dcaf71ae12df627dd6a00a6fcb312fd04d1a9dc9eec01222cd9b97c17780e532dc37adaf4
@@ -10,6 +10,8 @@ require 'net/https'
10
10
  require 'nokogiri'
11
11
  require 'json'
12
12
 
13
+ class BingTranslatorException < Exception; end
14
+
13
15
  class BingTranslator
14
16
  TRANSLATE_URI = 'http://api.microsofttranslator.com/V2/Http.svc/Translate'
15
17
  DETECT_URI = 'http://api.microsofttranslator.com/V2/Http.svc/Detect'
@@ -97,6 +99,13 @@ private
97
99
  {
98
100
  'Authorization' => "Bearer #{@access_token['access_token']}"
99
101
  })
102
+
103
+ if results.response.code.to_i == 200
104
+ results
105
+ else
106
+ html = Nokogiri::HTML(results.body)
107
+ raise BingTranslatorException, html.xpath("//text()").remove.map(&:to_s).join(' ')
108
+ end
100
109
  end
101
110
 
102
111
  # Private: Get a new access token
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bing_translator
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.1
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricky Elrod
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-20 00:00:00.000000000 Z
11
+ date: 2013-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -70,3 +70,4 @@ signing_key:
70
70
  specification_version: 4
71
71
  summary: Translate using the Bing HTTP API
72
72
  test_files: []
73
+ has_rdoc: