Class: Locca::Onesky
- Inherits:
-
Object
- Object
- Locca::Onesky
- Defined in:
- lib/locca/sync/onesky.rb
Instance Method Summary collapse
- #authorization_params ⇒ Object
- #fetch_response(http_verb, path, params) ⇒ Object
- #fetch_translations(lang, file_name) ⇒ Object
-
#initialize(project_id, public_key, secret_key) ⇒ Onesky
constructor
A new instance of Onesky.
- #upload_file(file_path, file_format, prune_missing_strings = false) ⇒ Object
Constructor Details
#initialize(project_id, public_key, secret_key) ⇒ Onesky
31 32 33 34 35 |
# File 'lib/locca/sync/onesky.rb', line 31 def initialize(project_id, public_key, secret_key) @project_id = project_id @public_key = public_key @secret_key = secret_key end |
Instance Method Details
#authorization_params ⇒ Object
45 46 47 48 |
# File 'lib/locca/sync/onesky.rb', line 45 def = Time.now.to_i.to_s {:"api_key" => @public_key, :timestamp => , :"dev_hash" => Digest::MD5.hexdigest( + @secret_key)} end |
#fetch_response(http_verb, path, params) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/locca/sync/onesky.rb', line 50 def fetch_response(http_verb, path, params) = {:content_type => "application/json; charset=UTF-8", :accept => "application/json"} params = .merge(params) path = "https://platform.api.onesky.io/1/projects/#{@project_id}/#{path}" response = case http_verb when :get RestClient.get(path, {:params => params}.merge()) when :post RestClient.post(path, params.merge()) else raise "bad http verb" end return response end |
#fetch_translations(lang, file_name) ⇒ Object
41 42 43 |
# File 'lib/locca/sync/onesky.rb', line 41 def fetch_translations(lang, file_name) return fetch_response(:get, "translations", {'locale' => lang, 'source_file_name' => file_name}) end |
#upload_file(file_path, file_format, prune_missing_strings = false) ⇒ Object
37 38 39 |
# File 'lib/locca/sync/onesky.rb', line 37 def upload_file(file_path, file_format, prune_missing_strings = false) fetch_response(:post, "files", {'file' => File.new(file_path), 'file_format' => file_format, 'is_keeping_all_strings' => !prune_missing_strings}) end |