Skip to content

Commit

Permalink
Merge default options
Browse files Browse the repository at this point in the history
  • Loading branch information
chatgris committed Jul 27, 2011
1 parent 0c9a15a commit 6a293d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
18 changes: 8 additions & 10 deletions lib/c3po/translator/bing.rb
Expand Up @@ -8,6 +8,9 @@ class Bing

def initialize(to_be_translated)
@to_be_translated = to_be_translated
@default = {
:appId => C3po::Translator::Configuration.bing_api_key,
}
end

# Build a query for the Bing Translate api.
Expand All @@ -24,12 +27,10 @@ def initialize(to_be_translated)
#
def build_query(from, to)
@base_url = 'http://api.microsofttranslator.com/V2/Http.svc/Translate'
{
:appId => C3po::Translator::Configuration.bing_api_key,
:text => @to_be_translated,
:from => from.to_s,
:to => to.to_s
}
@default.merge({:text => @to_be_translated,
:from => from.to_s,
:to => to.to_s
})
end

# Build a query for detect method of Bing Translate api.
Expand All @@ -43,10 +44,7 @@ def build_query(from, to)
#
def build_detect_query
@base_url = 'http://api.microsofttranslator.com/V2/Http.svc/Detect'
{
:appId => C3po::Translator::Configuration.bing_api_key,
:text => @to_be_translated
}
@default.merge({:text => @to_be_translated})
end

# Parse xml response from Bing webservice.
Expand Down
18 changes: 8 additions & 10 deletions lib/c3po/translator/google.rb
Expand Up @@ -8,6 +8,9 @@ class Google

def initialize(to_be_translated)
@to_be_translated = to_be_translated
@default = {
:key => C3po::Translator::Configuration.google_api_key
}
end

# Build a query for Google Translate api.
Expand All @@ -24,12 +27,10 @@ def initialize(to_be_translated)
#
def build_query(from, to)
@base_url = 'https://www.googleapis.com/language/translate/v2'
{
:key => C3po::Translator::Configuration.google_api_key,
:q => @to_be_translated,
:source => from.to_s,
:target => to.to_s
}
@default.merge({:q => @to_be_translated,
:source => from.to_s,
:target => to.to_s
})
end

# Build a query for detect method of Google Translate api.
Expand All @@ -43,10 +44,7 @@ def build_query(from, to)
#
def build_detect_query
@base_url = 'https://www.googleapis.com/language/translate/v2/detect'
{
:key => C3po::Translator::Configuration.google_api_key,
:q => @to_be_translated
}
@default.merge({:q => @to_be_translated})
end

# Parse json response from Google webservice.
Expand Down

0 comments on commit 6a293d0

Please sign in to comment.