Class: Locca::Onesky

Inherits:
Object
  • Object
show all
Defined in:
lib/locca/sync/onesky.rb

Instance Method Summary collapse

Constructor Details

#initialize(project_id, public_key, secret_key) ⇒ Onesky

Returns a new instance of 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_paramsObject



45
46
47
48
# File 'lib/locca/sync/onesky.rb', line 45

def authorization_params
    timestamp = Time.now.to_i.to_s
    {:"api_key" => @public_key, :timestamp => timestamp, :"dev_hash" => Digest::MD5.hexdigest(timestamp + @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)
    options = {:content_type => "application/json; charset=UTF-8", :accept => "application/json"}
    params = authorization_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(options))
    when :post
        RestClient.post(path, params.merge(options))
    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