bing_translator 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/bing_translator.rb +10 -12
  2. metadata +4 -4
@@ -1,28 +1,26 @@
1
1
  #!/usr/bin/env ruby
2
+ # (c) 2011-present. Ricky Elrod <ricky@elrod.me>
3
+ # Released under the MIT license.
2
4
  require 'rubygems'
3
5
  require 'cgi'
4
6
  require 'uri'
5
7
  require 'net/http'
6
8
  require 'nokogiri'
7
- require 'pp'
8
9
 
9
10
  class BingTranslator
10
11
  TRANSLATE_URI = 'http://api.microsofttranslator.com/V2/Http.svc/Translate'
11
12
 
12
- def initialize(params = {})
13
- if params[:api_key].nil?
14
- raise "Must pass :api_key when initializing BingTranslator"
15
- end
16
- @api_key = params[:api_key]
13
+ def initialize(api_key)
14
+ @api_key = api_key
17
15
  end
18
16
 
19
- def translate(params = {})
20
- if params[:to].nil? or params[:from].nil? or params[:text].nil?
21
- raise "Must provide :to, :from, and :text."
17
+ def translate(text, params = {})
18
+ if params[:to].nil? or params[:from].nil?
19
+ raise "Must provide :to and :from."
22
20
  else
23
- to = CGI.escape params[:to]
24
- from = CGI.escape params[:from]
25
- text = CGI.escape params[:text]
21
+ to = CGI.escape params[:to].to_s
22
+ from = CGI.escape params[:from].to_s
23
+ text = CGI.escape text.to_s
26
24
  uri = URI.parse(TRANSLATE_URI)
27
25
  params = {
28
26
  'to' => to,
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bing_translator
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ricky Elrod
@@ -60,7 +60,7 @@ rubyforge_project:
60
60
  rubygems_version: 1.8.11
61
61
  signing_key:
62
62
  specification_version: 3
63
- summary: Translate using the Bing HTTP API
63
+ summary: Remove the need for some un-necessary, always-there keys.
64
64
  test_files: []
65
65
 
66
66
  has_rdoc: