Class: OneSky::Project

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.

Raises:

  • (ArgumentError)


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_keyObject

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_secretObject

Returns the value of attribute api_secret.



4
5
6
# File 'lib/one_sky/project.rb', line 4

def api_secret
  @api_secret
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/one_sky/project.rb', line 4

def name
  @name
end

Instance Method Details

#detailsObject

Returns details about the project.



13
14
15
# File 'lib/one_sky/project.rb', line 13

def details
  get("/project/details")["project"]
end

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

#infoObject

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, options = {})
  options = {:string => string}.merge(options)
  post("/string/input", hash_to_params(options))
  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, options = {})
  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(options))
  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, options = {})
  response = post("/string/input-po", {:language => language, :file => File.new(file_name, "rb")}.merge(options), {}) 
  true
end

#languagesObject

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(options = {})
  get("/string/output", hash_to_params(options))["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, options = {})
  response = get("/string/output-mo", {:language => language}.merge(options)) 
  File.open(file_name, "w") { |f| f.print response }
  true
end

#typesObject

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