Class: Gcloud::Translate::Service
- Inherits:
-
Object
- Object
- Gcloud::Translate::Service
- Defined in:
- lib/gcloud/translate/service.rb
Overview
Represents the service to Translate, exposing the API calls.
Constant Summary collapse
- API =
Alias to the Google Client API module
Google::Apis::TranslateV2
Instance Attribute Summary collapse
-
#credentials ⇒ Object
Returns the value of attribute credentials.
-
#mocked_service ⇒ Object
Returns the value of attribute mocked_service.
Instance Method Summary collapse
-
#detect(text) ⇒ Object
Returns API::ListDetectionsResponse.
-
#initialize(key, retries: nil, timeout: nil) ⇒ Service
constructor
Creates a new Service instance.
- #inspect ⇒ Object
-
#languages(language = nil) ⇒ Object
Returns API::ListLanguagesResponse.
- #service ⇒ Object
-
#translate(text, to: nil, from: nil, format: nil, cid: nil) ⇒ Object
Returns API::ListTranslationsResponse.
Constructor Details
#initialize(key, retries: nil, timeout: nil) ⇒ Service
Creates a new Service instance.
34 35 36 37 38 39 40 41 42 |
# File 'lib/gcloud/translate/service.rb', line 34 def initialize key, retries: nil, timeout: nil @service = API::TranslateService.new @service..application_name = "gcloud-ruby" @service..application_version = Gcloud::VERSION @service..retries = retries || 3 @service..timeout_sec = timeout if timeout @service. = nil @service.key = key end |
Instance Attribute Details
#credentials ⇒ Object
Returns the value of attribute credentials.
30 31 32 |
# File 'lib/gcloud/translate/service.rb', line 30 def credentials @credentials end |
#mocked_service ⇒ Object
Returns the value of attribute mocked_service.
48 49 50 |
# File 'lib/gcloud/translate/service.rb', line 48 def mocked_service @mocked_service end |
Instance Method Details
#detect(text) ⇒ Object
Returns API::ListDetectionsResponse
61 62 63 64 65 |
# File 'lib/gcloud/translate/service.rb', line 61 def detect text service.list_detections Array(text) rescue Google::Apis::Error => e raise Gcloud::Error.from_error(e) end |
#inspect ⇒ Object
75 76 77 |
# File 'lib/gcloud/translate/service.rb', line 75 def inspect "#{self.class}" end |
#languages(language = nil) ⇒ Object
Returns API::ListLanguagesResponse
69 70 71 72 73 |
# File 'lib/gcloud/translate/service.rb', line 69 def languages language = nil service.list_languages target: language rescue Google::Apis::Error => e raise Gcloud::Error.from_error(e) end |
#service ⇒ Object
44 45 46 47 |
# File 'lib/gcloud/translate/service.rb', line 44 def service return mocked_service if mocked_service @service end |
#translate(text, to: nil, from: nil, format: nil, cid: nil) ⇒ Object
Returns API::ListTranslationsResponse
52 53 54 55 56 57 |
# File 'lib/gcloud/translate/service.rb', line 52 def translate text, to: nil, from: nil, format: nil, cid: nil service.list_translations Array(text), to, cid: cid, format: format, source: from rescue Google::Apis::Error => e raise Gcloud::Error.from_error(e) end |