easy_translate 0.3.2 → 0.3.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.
@@ -1,4 +1,5 @@
1
1
  require 'json'
2
+ require 'cgi'
2
3
  require File.dirname(__FILE__) + '/request'
3
4
 
4
5
  module EasyTranslate
@@ -9,7 +10,7 @@ module EasyTranslate
9
10
  # @param [String, Array] texts - A single string or set of strings to detect for
10
11
  # @param [Hash] options - Extra options to pass along with the request
11
12
  # @return [String, Array] The resultant language or languages
12
- def detect(texts, options = nil, http_options={})
13
+ def detect(texts, options = {}, http_options = {})
13
14
  request = DetectionRequest.new(texts, options, http_options)
14
15
  # Turn the response into an array of detections
15
16
  raw = request.perform_raw
@@ -51,7 +52,7 @@ module EasyTranslate
51
52
  # The body for the request
52
53
  # @return [String] the body for the request, URL escaped
53
54
  def body
54
- @texts.map { |t| "q=#{URI.escape(t)}" }.join '&'
55
+ @texts.map { |t| "q=#{CGI::escape(t)}" }.join '&'
55
56
  end
56
57
 
57
58
  # Whether or not this was a request for multiple texts
@@ -71,7 +72,7 @@ module EasyTranslate
71
72
  else
72
73
  @multi = true
73
74
  @texts = texts
74
- end
75
+ end
75
76
  end
76
77
 
77
78
  end
@@ -1,8 +1,8 @@
1
1
  module EasyTranslate
2
2
 
3
- LANGUAGES = {
3
+ LANGUAGES = {
4
4
  'af' => 'afrikaans',
5
- 'sq' => 'albanian',
5
+ 'sq' => 'albanian',
6
6
  'ar' => 'arabic',
7
7
  'be' => 'belarusian',
8
8
  'bg' => 'bulgarian',
@@ -7,7 +7,7 @@ module EasyTranslate
7
7
  class Request
8
8
  attr_accessor :http_options
9
9
 
10
- def initialize(options={}, http_options={})
10
+ def initialize(options = {}, http_options = {})
11
11
  @options = options
12
12
  @http_options = http_options
13
13
  end
@@ -1,4 +1,5 @@
1
1
  require 'json'
2
+ require 'cgi'
2
3
  require File.dirname(__FILE__) + '/request'
3
4
 
4
5
  module EasyTranslate
@@ -11,9 +12,9 @@ module EasyTranslate
11
12
  # @option options [String, Symbol] :target - The target language (required)
12
13
  # @option options [Boolean] :html - Whether or not the supplied string is HTML (optional)
13
14
  # @return [String, Array] Translated text or texts
14
- def translate(texts, options = {}, http_options={})
15
+ def translate(texts, options = {}, http_options = {})
15
16
  request = TranslationRequest.new(texts, options, http_options)
16
- # Turn the response into an array of translations
17
+ # Turn the response into an array of translations
17
18
  raw = request.perform_raw
18
19
  translations = JSON.parse(raw)['data']['translations'].map do |res|
19
20
  res['translatedText']
@@ -24,11 +25,11 @@ module EasyTranslate
24
25
 
25
26
  # A convenience class for wrapping a translation request
26
27
  class TranslationRequest < EasyTranslate::Request
27
-
28
+
28
29
  # Set the texts and options
29
30
  # @param [String, Array] texts - the text (or texts) to translate
30
31
  # @param [Hash] options - Options to override or pass along with the request
31
- def initialize(texts, options, http_options={})
32
+ def initialize(texts, options, http_options = {})
32
33
  self.texts = texts
33
34
  self.html = options.delete(:html)
34
35
  @source = options.delete(:from)
@@ -64,7 +65,7 @@ module EasyTranslate
64
65
  # The body for the request
65
66
  # @return [String] the body for the request, URL escaped
66
67
  def body
67
- @texts.map { |t| "q=#{URI.escape(t)}" }.join '&'
68
+ @texts.map { |t| "q=#{CGI::escape(t)}" }.join '&'
68
69
  end
69
70
 
70
71
  # Whether or not this was a request for multiple texts
@@ -20,9 +20,9 @@ module EasyTranslate
20
20
  class TranslationTargetRequest < EasyTranslate::Request
21
21
 
22
22
  def initialize(target = nil, options = nil)
23
+ super(options)
23
24
  @target = target
24
- if options
25
- @options = options
25
+ if @options
26
26
  if replacement_api_key = @options.delete(:api_key)
27
27
  @options[:key] = replacement_api_key
28
28
  end
@@ -1,5 +1,5 @@
1
1
  module EasyTranslate
2
2
 
3
- VERSION = '0.3.2'
3
+ VERSION = '0.3.3'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_translate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-09 00:00:00.000000000 Z
12
+ date: 2013-04-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  requirements: []
81
81
  rubyforge_project:
82
- rubygems_version: 1.8.24
82
+ rubygems_version: 1.8.25
83
83
  signing_key:
84
84
  specification_version: 3
85
85
  summary: Google Translate API Wrapper for Ruby