Class: OneSky::Project
- Inherits:
-
Object
- Object
- OneSky::Project
- Defined in:
- lib/one_sky/project.rb
Overview
This is the main class used to interact with the OneSky API and maps to a project on their web site.
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_secret ⇒ Object
Returns the value of attribute api_secret.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#details ⇒ Object
Returns details about the project.
-
#get_sso_link(unique_id) ⇒ Object
Returns the SSO URL for the given unique_id.
-
#info ⇒ Object
Returns info about your account.
-
#initialize(api_key, api_secret, name) ⇒ Project
constructor
Provide the name of the project you created on the OneSky website.
-
#input(string, options = {}) ⇒ Object
Submits a string for translation.
-
#input_bulk(hashes, options = {}) ⇒ Object
Submits a bulk translation request.
-
#input_po(language, file_name, options = {}) ⇒ Object
(also: #upload_po)
Uploads a PO file for the given language.
-
#languages ⇒ Object
Returns an array of available languages.
-
#output(options = {}) ⇒ Object
Gets the strings with available translations.
-
#output_mo(language, file_name, options = {}) ⇒ Object
(also: #download_mo)
Downloads the compiled MO file for the given language and saves it as file_name.
-
#types ⇒ Object
Returns available types to be specified when creating a new the project.
Constructor Details
#initialize(api_key, api_secret, name) ⇒ Project
Provide the name of the project you created on the OneSky website. Also, the API key and secret shown there.
7 8 9 10 |
# File 'lib/one_sky/project.rb', line 7 def initialize(api_key, api_secret, name) raise ArgumentError, "api_key, api_secret, and name cannot be nil." unless [api_key, api_secret, name].all? @api_key, @api_secret, @name = api_key, api_secret, name end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
4 5 6 |
# File 'lib/one_sky/project.rb', line 4 def api_key @api_key end |
#api_secret ⇒ Object
Returns the value of attribute api_secret.
4 5 6 |
# File 'lib/one_sky/project.rb', line 4 def api_secret @api_secret end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/one_sky/project.rb', line 4 def name @name end |
Instance Method Details
#details ⇒ Object
Returns details about the project.
13 14 15 |
# File 'lib/one_sky/project.rb', line 13 def details get("/project/details")["project"] end |
#get_sso_link(unique_id) ⇒ Object
Returns the SSO URL for the given unique_id
33 34 35 |
# File 'lib/one_sky/project.rb', line 33 def get_sso_link(unique_id) get("/sso/get-link", {:"unique-id" => unique_id})["url"] end |
#info ⇒ Object
Returns info about your account.
28 29 30 |
# File 'lib/one_sky/project.rb', line 28 def info get("/info")["application"] end |
#input(string, options = {}) ⇒ Object
Submits a string for translation. Takes an optional hash of parameters, too:
-
:string_key
-
:context
-
:page
42 43 44 45 46 |
# File 'lib/one_sky/project.rb', line 42 def input(string, = {}) = {:string => string}.merge() post("/string/input", hash_to_params()) true end |
#input_bulk(hashes, options = {}) ⇒ Object
Submits a bulk translation request. Parameters:
-
hashes - An array of hashes with mandatory key :string and optional keys (:string_key, :context)
-
An optional hash with keys:
-
:page
-
53 54 55 56 57 58 59 60 |
# File 'lib/one_sky/project.rb', line 53 def input_bulk(hashes, = {}) arrs = hashes.inject([[],[],[]]) do |o,e| o[0] << e[:string]; o[1] << e[:string_key]; o[2] << e[:context]; o end post("/string/input-bulk", {:strings => arrs[0], :"string-keys" => arrs[1], :contexts => arrs[2]}.merge()) true end |
#input_po(language, file_name, options = {}) ⇒ Object Also known as: upload_po
Uploads a PO file for the given language. See #languages for a list of supported language codes. Takes an optional hash of parameters:
-
:page
66 67 68 69 |
# File 'lib/one_sky/project.rb', line 66 def input_po(language, file_name, = {}) response = post("/string/input-po", {:language => language, :file => File.new(file_name, "rb")}.merge(), {}) true end |
#languages ⇒ Object
Returns an array of available languages.
23 24 25 |
# File 'lib/one_sky/project.rb', line 23 def languages get("/project/languages")["languages"] end |
#output(options = {}) ⇒ Object
Gets the strings with available translations. Takes these optional parameters, too:
-
:language
-
:page
-
:md5
– ToDo: Probably need to expose MD5 response values for caching implementations. ++
81 82 83 |
# File 'lib/one_sky/project.rb', line 81 def output( = {}) get("/string/output", hash_to_params())["translation"] end |
#output_mo(language, file_name, options = {}) ⇒ Object Also known as: download_mo
Downloads the compiled MO file for the given language and saves it as file_name. See #languages for a list of supported language codes. Takes an optional hash of parameters:
-
:page
89 90 91 92 93 |
# File 'lib/one_sky/project.rb', line 89 def output_mo(language, file_name, = {}) response = get("/string/output-mo", {:language => language}.merge()) File.open(file_name, "w") { |f| f.print response } true end |
#types ⇒ Object
Returns available types to be specified when creating a new the project.
18 19 20 |
# File 'lib/one_sky/project.rb', line 18 def types get("/project/types")["types"] end |