bing_translator 3.3.0 → 3.4.0
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/lib/bing_translator.rb +4 -3
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 9cc06c8225da2733b070e4802c2a9a5008fb6877
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: fe975ae7a7f5721d8aeb3578fb62dd3079fbd470
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 26b891fa711b5b55f7be124572f2d7f895a951c73665265a6586934d4e4755753a54afc017ead0531b9e6fb9a65778a1e25f0a9b52b661242df1105ee2cdaec4
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 2abfc115215243aa5ada27835af92db327417a5d0c029bc4575bc16e9f336ab236dd9cda40700a72692acf764fac389deb7137a1caa396cdad05b3ab6f0e5d13
         
     | 
    
        data/lib/bing_translator.rb
    CHANGED
    
    | 
         @@ -11,6 +11,7 @@ require 'nokogiri' 
     | 
|
| 
       11 
11 
     | 
    
         
             
            require 'json'
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
            class BingTranslatorException < Exception; end
         
     | 
| 
      
 14 
     | 
    
         
            +
            class BingTranslatorAuthenticationException < Exception; end
         
     | 
| 
       14 
15 
     | 
    
         | 
| 
       15 
16 
     | 
    
         
             
            class BingTranslator
         
     | 
| 
       16 
17 
     | 
    
         
             
              TRANSLATE_URI = 'http://api.microsofttranslator.com/V2/Http.svc/Translate'
         
     | 
| 
         @@ -44,7 +45,7 @@ class BingTranslator 
     | 
|
| 
       44 
45 
     | 
    
         
             
                params[:from] = from unless from.empty?
         
     | 
| 
       45 
46 
     | 
    
         
             
                result = result @translate_uri, params
         
     | 
| 
       46 
47 
     | 
    
         | 
| 
       47 
     | 
    
         
            -
                Nokogiri.parse(result.body). 
     | 
| 
      
 48 
     | 
    
         
            +
                Nokogiri.parse(result.body).at_xpath("//xmlns:string").content
         
     | 
| 
       48 
49 
     | 
    
         
             
              end
         
     | 
| 
       49 
50 
     | 
    
         | 
| 
       50 
51 
     | 
    
         
             
              def detect(text)
         
     | 
| 
         @@ -55,7 +56,7 @@ class BingTranslator 
     | 
|
| 
       55 
56 
     | 
    
         
             
                }
         
     | 
| 
       56 
57 
     | 
    
         
             
                result = result @detect_uri, params
         
     | 
| 
       57 
58 
     | 
    
         | 
| 
       58 
     | 
    
         
            -
                Nokogiri.parse(result.body). 
     | 
| 
      
 59 
     | 
    
         
            +
                Nokogiri.parse(result.body).at_xpath("//xmlns:string").content.to_sym
         
     | 
| 
       59 
60 
     | 
    
         
             
              end
         
     | 
| 
       60 
61 
     | 
    
         | 
| 
       61 
62 
     | 
    
         
             
              # format:   'audio/wav' [default] or 'audio/mp3'
         
     | 
| 
         @@ -134,7 +135,7 @@ private 
     | 
|
| 
       134 
135 
     | 
    
         | 
| 
       135 
136 
     | 
    
         
             
                response = http.post(@access_token_uri.path, prepare_param_string(params))
         
     | 
| 
       136 
137 
     | 
    
         
             
                @access_token = JSON.parse(response.body)
         
     | 
| 
       137 
     | 
    
         
            -
                raise  
     | 
| 
      
 138 
     | 
    
         
            +
                raise BingTranslatorAuthenticationException, @access_token['error'] if @access_token["error"]
         
     | 
| 
       138 
139 
     | 
    
         
             
                @access_token['expires_at'] = Time.now + @access_token['expires_in'].to_i
         
     | 
| 
       139 
140 
     | 
    
         
             
                @access_token
         
     | 
| 
       140 
141 
     | 
    
         
             
              end
         
     |