onesky-ruby 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +67 -0
  7. data/Rakefile +1 -0
  8. data/lib/onesky/client.rb +36 -0
  9. data/lib/onesky/errors.rb +30 -0
  10. data/lib/onesky/helpers/request.rb +82 -0
  11. data/lib/onesky/project.rb +38 -0
  12. data/lib/onesky/resources/locale.rb +9 -0
  13. data/lib/onesky/resources/project/base.rb +23 -0
  14. data/lib/onesky/resources/project/file_mgt.rb +25 -0
  15. data/lib/onesky/resources/project/import_task.rb +15 -0
  16. data/lib/onesky/resources/project/order.rb +19 -0
  17. data/lib/onesky/resources/project/quotation.rb +11 -0
  18. data/lib/onesky/resources/project/translation.rb +23 -0
  19. data/lib/onesky/resources/project.rb +17 -0
  20. data/lib/onesky/resources/project_group.rb +25 -0
  21. data/lib/onesky/resources/project_type.rb +9 -0
  22. data/lib/onesky/restclient.rb +38 -0
  23. data/lib/onesky/version.rb +3 -0
  24. data/lib/onesky.rb +4 -0
  25. data/onesky-ruby.gemspec +27 -0
  26. data/spec/fixture/en.yml +3 -0
  27. data/spec/onesky/client_spec.rb +13 -0
  28. data/spec/onesky/helpers/request_spec.rb +51 -0
  29. data/spec/onesky/resources/locale_spec.rb +18 -0
  30. data/spec/onesky/resources/project/base_spec.rb +49 -0
  31. data/spec/onesky/resources/project/file_spec.rb +47 -0
  32. data/spec/onesky/resources/project/import_task_spec.rb +31 -0
  33. data/spec/onesky/resources/project/order_spec.rb +45 -0
  34. data/spec/onesky/resources/project/quotation_spec.rb +23 -0
  35. data/spec/onesky/resources/project/translation_spec.rb +59 -0
  36. data/spec/onesky/resources/project_group_spec.rb +63 -0
  37. data/spec/onesky/resources/project_spec.rb +41 -0
  38. data/spec/onesky/resources/project_type_spec.rb +18 -0
  39. data/spec/spec_helper.rb +18 -0
  40. metadata +167 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 07702d69f7f7c3651594e79cf6dbd6e3bdf35205
4
+ data.tar.gz: f4bfd6c6a08a1b2ad6747d317bd676bd175989e7
5
+ SHA512:
6
+ metadata.gz: 6f995fba3cc6aa9486a467474ed9b041fb4132a1222c3a787699ed0da7a718aa74e6bb1d8a3aa4869036a8cfbc0c47579dcdb9327a11351cdb7f4abcab1bdffa
7
+ data.tar.gz: 182b75526c85377c628084bf88920d605aff30af196e90fd1514b89c5835e531a6f5f4f4bb18f41022933b34e0d7e1162a3ca8180eaed6b42f1e41f8ed9b296b
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in onesky-ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Victor Lam
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # OneSky - Ruby client
2
+
3
+ Ruby client for [OneSky](http://www.oneskyapp.com) [Platform API](/onesky/api-documentation-platform)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'onesky-ruby'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install onesky-ruby
18
+
19
+ ## Usage
20
+
21
+ ```Ruby
22
+ require 'onesky'
23
+
24
+ # Create client
25
+ client = Onesky::Client.new('<api_key>', '<api_secret>')
26
+
27
+ # list available locales
28
+ resp = JSON.parse(client.list_locale)
29
+ p resp['data']
30
+
31
+ # list project groups
32
+ resp = JSON.parse(client.list_project_group)
33
+ p resp['data']
34
+
35
+ # show project group details
36
+ project_group_id = 1
37
+ resp = JSON.parse(client.show_project_group project_group_id)
38
+ p resp['data']
39
+
40
+ # list projects
41
+ resp = JSON.parse(client.list_project project_group_id)
42
+ p resp['data']
43
+
44
+ ### Work with Project
45
+
46
+ # show project details
47
+ project_id = 3
48
+ project = client.porject(project_id)
49
+ resp = JSON.parse(project.show)
50
+ p resp['data']
51
+
52
+ # upload file
53
+ resp = project.upload_file(file: 'path/to/string/file', file_format: 'RUBY_YAML')
54
+ resp.code # => 201
55
+
56
+ # download translation
57
+ resp = project.export_translation(source_file_name: 'en.yml', locale: 'ja')
58
+ File.open('path/to/target/file', 'w') { |file| file.write(resp)}
59
+ ```
60
+
61
+ ## Contributing
62
+
63
+ 1. Fork it ( http://github.com/<my-github-username>/onesky-ruby/fork )
64
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
65
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
66
+ 4. Push to the branch (`git push origin my-new-feature`)
67
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,36 @@
1
+ require 'digest'
2
+
3
+ require 'onesky/resources/locale'
4
+ require 'onesky/resources/project_type'
5
+ require 'onesky/resources/project_group'
6
+ require 'onesky/resources/project'
7
+ require 'onesky/helpers/request'
8
+ require 'onesky/project'
9
+
10
+ module Onesky
11
+ class Client
12
+ include Resources::Locale
13
+ include Resources::ProjectType
14
+ include Resources::ProjectGroup
15
+ include Resources::Project
16
+ include Helpers::Request
17
+
18
+ attr_accessor :api_key, :api_secret, :project_id
19
+
20
+ def initialize(key, secret)
21
+ @api_key = key
22
+ @api_secret = secret
23
+ end
24
+
25
+ def auth_hash
26
+ now = Time.now.to_i
27
+
28
+ {
29
+ api_key: @api_key,
30
+ timestamp: now,
31
+ dev_hash: Digest::MD5.hexdigest(now.to_s + @api_secret)
32
+ }
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,30 @@
1
+ module Onesky
2
+ module Errors
3
+
4
+ class OneskyError < StandardError
5
+ attr_accessor :response
6
+ def initialize(resp)
7
+ @response = resp
8
+ end
9
+ end
10
+
11
+ # Raise error of 400 Bad Request
12
+ class BadRequestError < OneskyError; end
13
+
14
+ # Raise error of 401 Unauthorized
15
+ class UnauthorizedError < OneskyError; end
16
+
17
+ # Raise error of 403 Forbidden
18
+ class ForbiddenError < OneskyError; end
19
+
20
+ # Raise error of 404 Not Found
21
+ class NotFoundError < OneskyError; end
22
+
23
+ # Raise error of 405 Method Not Allowed
24
+ class MethodNotAllowedError < OneskyError; end
25
+
26
+ # Raise error of 500 Internal Server Error
27
+ class InternalServerError < OneskyError; end
28
+
29
+ end
30
+ end
@@ -0,0 +1,82 @@
1
+ require 'rest-client'
2
+
3
+ module Helpers
4
+ module Request
5
+
6
+ ENDPOINT = 'https://platform.api.onesky.io'
7
+ VERSION = 1
8
+
9
+ protected
10
+
11
+ def get(path, params = {})
12
+ uri = uri_prefix + path
13
+ RestClient.get(uri, params: auth_hash.merge(params)) do |resp, req, result|
14
+ handle_error(resp)
15
+ end
16
+ end
17
+
18
+ def post(path, body_hash)
19
+ uri = uri_prefix + path
20
+ RestClient.post(uri, body_hash.to_json, content_type: :json, params: auth_hash) do |resp, req, result|
21
+ handle_error(resp)
22
+ end
23
+ end
24
+
25
+ def post_multipart(path, body_hash)
26
+ uri = uri_prefix + path
27
+ RestClient.post(uri, body_hash.merge({multipart: true}), params: auth_hash) do |resp, req, result|
28
+ handle_error(resp)
29
+ end
30
+ end
31
+
32
+ def put(path, body_hash)
33
+ uri = uri_prefix + path
34
+ RestClient.put(uri, body_hash.to_json, content_type: :json, params: auth_hash) do |resp, req, result|
35
+ handle_error(resp)
36
+ end
37
+ end
38
+
39
+ def delete(path, params = {})
40
+ uri = uri_prefix + path
41
+ RestClient.delete(uri, params: auth_hash.merge(params)) do |resp, req, result|
42
+ handle_error(resp)
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def uri_prefix
49
+ "#{ENDPOINT}/#{VERSION}"
50
+ end
51
+
52
+ def handle_error(response)
53
+ return response if response.code.to_i < 400 # return if not error
54
+
55
+ case response.code.to_i
56
+ when 400
57
+ raise Onesky::Errors::BadRequestError.new(response), "400 Bad Request - #{extract_message(response)}"
58
+ when 401
59
+ raise Onesky::Errors::UnauthorizedError.new(response), "401 Unauthorized - #{extract_message(response)}"
60
+ when 403
61
+ raise Onesky::Errors::ForbiddenError.new(response), "403 Forbidden - #{extract_message(response)}"
62
+ when 404
63
+ raise Onesky::Errors::NotFoundError.new(response), "404 Not Found - #{extract_message(response)}"
64
+ when 405
65
+ raise Onesky::Errors::MethodNotAllowedError.new(response), "405 Method Not Allowed - #{extract_message(response)}"
66
+ when 500
67
+ raise Onesky::Errors::InternalServerError.new(response), "500 Internal Server Error - Please contact OneSky at support@oneskyapp.com"
68
+ else
69
+ raise Onesky::Errors::OneskyError.new(response), "#{response.code} Error"
70
+ end
71
+ end
72
+
73
+ def extract_message(response)
74
+ response_body = JSON.parse(response)
75
+ if response_body.has_key?('meta') && response_body['meta'].has_key?('message')
76
+ return response_body['meta']['message']
77
+ end
78
+ ''
79
+ end
80
+
81
+ end
82
+ end
@@ -0,0 +1,38 @@
1
+ require 'onesky/resources/project/base'
2
+ require 'onesky/resources/project/file_mgt'
3
+ require 'onesky/resources/project/translation'
4
+ require 'onesky/resources/project/import_task'
5
+ require 'onesky/resources/project/quotation'
6
+ require 'onesky/resources/project/order'
7
+ require 'onesky/helpers/request'
8
+
9
+ module Onesky
10
+ class Project
11
+
12
+ include Resources::Project::Base
13
+ include Resources::Project::FileMgt
14
+ include Resources::Project::Translation
15
+ include Resources::Project::ImportTask
16
+ include Resources::Project::Quotation
17
+ include Resources::Project::Order
18
+ include Helpers::Request
19
+
20
+ attr_accessor :client, :project_id
21
+
22
+ def initialize(client, id)
23
+ @client = client
24
+ @project_id = id
25
+ end
26
+
27
+ private
28
+
29
+ def project_path
30
+ "/projects/#{@project_id}"
31
+ end
32
+
33
+ def auth_hash
34
+ @client.auth_hash
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,9 @@
1
+ module Resources
2
+ module Locale
3
+
4
+ def list_locale
5
+ get('/locales')
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ module Resources
2
+ module Project
3
+ module Base
4
+
5
+ def show
6
+ get(project_path)
7
+ end
8
+
9
+ def update(params)
10
+ put(project_path, params)
11
+ end
12
+
13
+ def remove
14
+ delete(project_path)
15
+ end
16
+
17
+ def list_language
18
+ get("#{project_path}/languages")
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,25 @@
1
+ module Resources
2
+ module Project
3
+ module FileMgt
4
+
5
+ def list_file
6
+ get("#{project_path}/files")
7
+ end
8
+
9
+ def upload_file(params)
10
+ file = params[:file]
11
+ if file.is_a?(String)
12
+ raise IOError, 'File does not exist' unless File.exists?(file)
13
+ params[:file] = File.new(file, 'rt')
14
+ end
15
+
16
+ post_multipart("#{project_path}/files", params)
17
+ end
18
+
19
+ def delete_file(params)
20
+ delete("#{project_path}/files", params)
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ module Resources
2
+ module Project
3
+ module ImportTask
4
+
5
+ def list_import_task(params = {})
6
+ get("#{project_path}/import-tasks", params)
7
+ end
8
+
9
+ def show_import_task(import_task_id)
10
+ get("#{project_path}/import-tasks/#{import_task_id}")
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ module Resources
2
+ module Project
3
+ module Order
4
+
5
+ def list_order(params = {})
6
+ get("#{project_path}/orders", params)
7
+ end
8
+
9
+ def show_order(order_id)
10
+ get("#{project_path}/orders/#{order_id}")
11
+ end
12
+
13
+ def create_order(params)
14
+ post("#{project_path}/orders", params)
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ module Resources
2
+ module Project
3
+ module Quotation
4
+
5
+ def show_quotation(params = {})
6
+ get("#{project_path}/quotations", params)
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ module Resources
2
+ module Project
3
+ module Translation
4
+
5
+ def export_translation(params)
6
+ get("#{project_path}/translations", params)
7
+ end
8
+
9
+ def export_multilingual(params)
10
+ get("#{project_path}/translations/multilingual", params)
11
+ end
12
+
13
+ def export_app_description(params)
14
+ get("#{project_path}/translations/app-descriptions", params)
15
+ end
16
+
17
+ def get_translation_status(params)
18
+ get("#{project_path}/translations/status", params)
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ module Resources
2
+ module Project
3
+
4
+ def list_project(project_group_id)
5
+ get("/project-groups/#{project_group_id}/projects")
6
+ end
7
+
8
+ def create_project(project_group_id, params)
9
+ post("/project-groups/#{project_group_id}/projects", params)
10
+ end
11
+
12
+ def project(project_id)
13
+ Onesky::Project.new(self, project_id)
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ module Resources
2
+ module ProjectGroup
3
+
4
+ def list_project_group
5
+ get('/project-groups')
6
+ end
7
+
8
+ def show_project_group(project_group_id)
9
+ get("/project-groups/#{project_group_id}")
10
+ end
11
+
12
+ def create_project_group(params)
13
+ post('/project-groups', params)
14
+ end
15
+
16
+ def delete_project_group(project_group_id)
17
+ delete("/project-groups/#{project_group_id}")
18
+ end
19
+
20
+ def list_project_group_languages(project_group_id)
21
+ get("/project-groups/#{project_group_id}/languages")
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ module Resources
2
+ module ProjectType
3
+
4
+ def list_project_type
5
+ get('/project-types')
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,38 @@
1
+ # Monkey patching RestClient::Request.process_url_params
2
+ # To support array in URL params
3
+ # RestClient.get('http://www.example.com', params: {weekday: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri']})
4
+ # => GET http://www.example.com?weekday[]=Mon&weekday[]=Tue&weekday[]=Wed&weekday[]=Thu&weekday[]=Fri
5
+
6
+ module RestClient
7
+ class Request
8
+
9
+ def process_url_params url, headers
10
+ url_params = {}
11
+ headers.delete_if do |key, value|
12
+ if 'params' == key.to_s.downcase && value.is_a?(Hash)
13
+ url_params.merge! value
14
+ true
15
+ else
16
+ false
17
+ end
18
+ end
19
+ unless url_params.empty?
20
+ query_string = url_params.collect { |k, v| build_url_params(k, v) }.join('&')
21
+ url + "?#{query_string}"
22
+ else
23
+ url
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def build_url_params key, value
30
+ if value.is_a?(Array)
31
+ value.map { |v| "#{key.to_s}[]=#{CGI::escape(v.to_s)}" }.join('&')
32
+ else
33
+ "#{key.to_s}=#{CGI::escape(value.to_s)}"
34
+ end
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Onesky
2
+ VERSION = "0.0.1"
3
+ end
data/lib/onesky.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'onesky/version'
2
+ require 'onesky/client'
3
+ require 'onesky/errors'
4
+ require 'onesky/restclient'
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'onesky/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "onesky-ruby"
8
+ spec.version = Onesky::VERSION
9
+ spec.authors = ["Victor Lam"]
10
+ spec.email = ["victorebox@yahoo.com.hk"]
11
+ spec.summary = "To interact with OneSky Platform API"
12
+ spec.description = "Ruby wrapper for OneSky API"
13
+ spec.homepage = "http://github.com/onesky/onesky-ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'rest-client', '~> 1.7'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake", "~> 10.3"
25
+ spec.add_development_dependency "rspec", "~> 3.1"
26
+ spec.add_development_dependency "webmock", "~> 1.19"
27
+ end
@@ -0,0 +1,3 @@
1
+ en:
2
+ title: "Sample string file"
3
+ description: "This is a sample file for testing purpose"
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Onesky::Client do
4
+
5
+ let(:client) {Onesky::Client.new('api_key', 'api_secret')}
6
+
7
+ it 'should able to set api_key, api_secret' do
8
+ expect(client.api_key).to eq 'api_key'
9
+ expect(client.api_secret).to eq 'api_secret'
10
+ expect(client.auth_hash).to be_an_instance_of(Hash)
11
+ end
12
+
13
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Helpers::Request' do
4
+
5
+ let(:api_key) {''}
6
+ let(:api_secret) {''}
7
+ let(:client) {Onesky::Client.new(api_key, api_secret)}
8
+ let(:project_id) {1}
9
+ let(:project) {client.project(project_id)}
10
+
11
+ describe '#get' do
12
+ it 'should raise error for error response code' do
13
+ stub_request(:get, full_path_with_auth_hash("/locales", api_key, api_secret))
14
+ .to_return(status: 400, body: {meta: {code: 400, message: 'error message'}}.to_json)
15
+ expect {client.list_locale}.to raise_error(Onesky::Errors::BadRequestError, '400 Bad Request - error message')
16
+ end
17
+ end
18
+
19
+ describe '#post' do
20
+ it 'should return response on error' do
21
+ stub_request(:post, full_path_with_auth_hash("/project-groups", api_key, api_secret))
22
+ .to_return(status: 400, body: {meta: {code: 400, message: 'error message'}}.to_json)
23
+ expect {client.create_project_group({name: 'TEST'})}.to raise_error(Onesky::Errors::BadRequestError, '400 Bad Request - error message')
24
+ end
25
+ end
26
+
27
+ describe '#post_multipart' do
28
+ it 'should return response on error' do
29
+ stub_request(:post, full_path_with_auth_hash("/projects/#{project_id}/files", api_key, api_secret))
30
+ .to_return(status: 400, body: {meta: {code: 400, message: 'error message'}}.to_json)
31
+ expect {project.upload_file({file: 'spec/fixture/en.yml', file_format: 'RUBY_YAML'})}.to raise_error(Onesky::Errors::BadRequestError, '400 Bad Request - error message')
32
+ end
33
+ end
34
+
35
+ describe '#put' do
36
+ it 'should return response on error' do
37
+ stub_request(:put, full_path_with_auth_hash("/projects/#{project_id}", api_key, api_secret))
38
+ .to_return(status: 400, body: {meta: {code: 400, message: 'error message'}}.to_json)
39
+ expect {project.update({name: 'NEW NAME'})}.to raise_error(Onesky::Errors::BadRequestError, '400 Bad Request - error message')
40
+ end
41
+ end
42
+
43
+ describe '#delete' do
44
+ it 'should return response on error' do
45
+ stub_request(:delete, full_path_with_auth_hash("/projects/#{project_id}", api_key, api_secret))
46
+ .to_return(status: 400, body: {meta: {code: 400, message: 'error message'}}.to_json)
47
+ expect {project.remove}.to raise_error(Onesky::Errors::BadRequestError, '400 Bad Request - error message')
48
+ end
49
+ end
50
+
51
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Locale' do
4
+
5
+ let(:api_key) {'api_key'}
6
+ let(:api_secret) {'api_secret'}
7
+ let(:client) {Onesky::Client.new(api_key, api_secret)}
8
+
9
+ describe 'list_locale' do
10
+ it 'should list all available locales' do
11
+ stub_request(:get, full_path_with_auth_hash('/locales', api_key, api_secret))
12
+ .to_return(body: {})
13
+ response = client.list_locale
14
+ expect(response).to be_an_instance_of(Hash)
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Project::Base' do
4
+
5
+ let(:api_key) {'api_key'}
6
+ let(:api_secret) {'api_secret'}
7
+ let(:client) {Onesky::Client.new(api_key, api_secret)}
8
+ let(:project_id) {1}
9
+ let(:project) {client.project(project_id)}
10
+
11
+ describe 'show' do
12
+ it 'should show project information' do
13
+ stub_request(:get, full_path_with_auth_hash("/projects/#{project_id}", api_key, api_secret))
14
+ .to_return(body: {})
15
+ response = project.show
16
+ expect(response).to be_an_instance_of(Hash)
17
+ end
18
+ end
19
+
20
+ describe 'update' do
21
+ let(:params) {{name: 'New name', description: 'New project description'}}
22
+
23
+ it 'should update project information' do
24
+ stub_request(:put, full_path_with_auth_hash("/projects/#{project_id}", api_key, api_secret))
25
+ .to_return(status: 200)
26
+ response = project.update(params)
27
+ expect(response.code).to eq(200)
28
+ end
29
+ end
30
+
31
+ describe 'remove' do
32
+ it 'should delete a project' do
33
+ stub_request(:delete, full_path_with_auth_hash("/projects/#{project_id}", api_key, api_secret))
34
+ .to_return(status: 200)
35
+ response = project.remove
36
+ expect(response.code).to eq(200)
37
+ end
38
+ end
39
+
40
+ describe 'list_language' do
41
+ it 'should list languages of project' do
42
+ stub_request(:get, full_path_with_auth_hash("/projects/#{project_id}/languages", api_key, api_secret))
43
+ .to_return(body: {})
44
+ response = project.list_language
45
+ expect(response).to be_an_instance_of(Hash)
46
+ end
47
+ end
48
+
49
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Project::File' do
4
+
5
+ let(:api_key) {'api_key'}
6
+ let(:api_secret) {'api_secret'}
7
+ let(:client) {Onesky::Client.new(api_key, api_secret)}
8
+ let(:project_id) {1}
9
+ let(:project) {client.project(project_id)}
10
+
11
+ describe 'list_file' do
12
+ it 'should list files in project' do
13
+ stub_request(:get, full_path_with_auth_hash("/projects/#{project_id}/files", api_key, api_secret))
14
+ .to_return(body: {})
15
+ response = project.list_file
16
+ expect(response).to be_an_instance_of(Hash)
17
+ end
18
+ end
19
+
20
+ describe 'upload_file' do
21
+ let(:params) {{file: 'spec/fixture/en.yml', file_format: 'RUBY_YAML'}}
22
+
23
+ it 'should upload file to project' do
24
+ stub_request(:post, full_path_with_auth_hash("/projects/#{project_id}/files", api_key, api_secret))
25
+ .to_return(body: {})
26
+ response = project.upload_file(params)
27
+ expect(response).to be_an_instance_of(Hash)
28
+ end
29
+
30
+ it 'should raise error when file does not exist' do
31
+ expect {project.upload_file(file: 'spec/fixture/no_file.yml')}.to raise_error(IOError, 'File does not exist')
32
+ end
33
+ end
34
+
35
+ describe 'delete_file' do
36
+ let(:params) {{file_name: 'en.yml'}}
37
+ let(:params_as_query_string) {'&file_name=en.yml'}
38
+
39
+ it 'should delete file from project' do
40
+ stub_request(:delete, full_path_with_auth_hash("/projects/#{project_id}/files", api_key, api_secret) + params_as_query_string)
41
+ .to_return(body: {})
42
+ response = project.delete_file(params)
43
+ expect(response).to be_an_instance_of(Hash)
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Project::ImportTask' do
4
+
5
+ let(:api_key) {'api_key'}
6
+ let(:api_secret) {'api_secret'}
7
+ let(:client) {Onesky::Client.new(api_key, api_secret)}
8
+ let(:project_id) {1}
9
+ let(:project) {client.project(project_id)}
10
+
11
+ describe 'list_import_task' do
12
+ it 'should list import tasks of the project' do
13
+ stub_request(:get, full_path_with_auth_hash("/projects/#{project_id}/import-tasks", api_key, api_secret))
14
+ .to_return(body: {})
15
+ response = project.list_import_task
16
+ expect(response).to be_an_instance_of(Hash)
17
+ end
18
+ end
19
+
20
+ describe 'show_import_task' do
21
+ let(:import_task_id) {1}
22
+
23
+ it 'should show an import task details' do
24
+ stub_request(:get, full_path_with_auth_hash("/projects/#{project_id}/import-tasks/#{import_task_id}", api_key, api_secret))
25
+ .to_return(body: {})
26
+ response = project.show_import_task(import_task_id)
27
+ expect(response).to be_an_instance_of(Hash)
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Project::Order' do
4
+
5
+ let(:api_key) {'api_key'}
6
+ let(:api_secret) {'api_secret'}
7
+ let(:client) {Onesky::Client.new(api_key, api_secret)}
8
+ let(:project_id) {1}
9
+ let(:project) {client.project(project_id)}
10
+
11
+ describe 'list_order' do
12
+ it 'should list orders in project' do
13
+ stub_request(:get, full_path_with_auth_hash("/projects/#{project_id}/orders", api_key, api_secret))
14
+ .to_return(status: 200, body: {})
15
+ response = project.list_order
16
+ expect(response).to be_an_instance_of(Hash)
17
+ end
18
+ end
19
+
20
+ describe 'show_order' do
21
+ let(:order_id) {1}
22
+
23
+ it 'should show an order details' do
24
+ stub_request(:get, full_path_with_auth_hash("/projects/#{project_id}/orders/#{order_id}", api_key, api_secret))
25
+ .to_return(status: 200, body: {})
26
+ response = project.show_order(order_id)
27
+ expect(response).to be_an_instance_of(Hash)
28
+ end
29
+ end
30
+
31
+ describe 'create_order' do
32
+ let(:files) {['en.yml', 'en2.yml']}
33
+ let(:to_locale) {'ja'}
34
+ let(:params) {{files: files, to_locale: to_locale}}
35
+
36
+ it 'should create an order' do
37
+ stub_request(:post, full_path_with_auth_hash("/projects/#{project_id}/orders", api_key, api_secret))
38
+ .with(body: params.to_json, headers: {'Content_Type' => 'application/json'})
39
+ .to_return(status: 200, body: {})
40
+ response = project.create_order(params)
41
+ expect(response).to be_an_instance_of(Hash)
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Project::Quotation' do
4
+
5
+ let(:api_key) {'api_key'}
6
+ let(:api_secret) {'api_secret'}
7
+ let(:client) {Onesky::Client.new(api_key, api_secret)}
8
+ let(:project_id) {1}
9
+ let(:project) {client.project(project_id)}
10
+
11
+ describe 'show_quotation' do
12
+ let(:params) {{files: ['en.yml', 'en2.yml'], to_locale: 'ja'}}
13
+ let(:params_as_query_string) {'&files[]=en.yml&files[]=en2.yml&to_locale=ja'}
14
+
15
+ it 'should show quotation details' do
16
+ stub_request(:get, full_path_with_auth_hash("/projects/#{project_id}/quotations", api_key, api_secret) + params_as_query_string)
17
+ .to_return(status: 200)
18
+ response = project.show_quotation(params)
19
+ expect(response.code).to eq(200)
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Project::Translation' do
4
+
5
+ let(:api_key) {'api_key'}
6
+ let(:api_secret) {'api_secret'}
7
+ let(:client) {Onesky::Client.new(api_key, api_secret)}
8
+ let(:project_id) {1}
9
+ let(:project) {client.project(project_id)}
10
+
11
+ describe 'export_translation' do
12
+ let(:params) {{source_file_name: 'en.yml', locale: 'ja'}}
13
+ let(:params_as_query_string) {'&source_file_name=en.yml&locale=ja'}
14
+
15
+ it 'should export translation' do
16
+ stub_request(:get, full_path_with_auth_hash("/projects/#{project_id}/translations", api_key, api_secret) + params_as_query_string)
17
+ .to_return(status: 200, body: 'file content')
18
+ response = project.export_translation(params)
19
+ expect(response.code).to eq(200)
20
+ end
21
+ end
22
+
23
+ describe 'export_multilingual' do
24
+ let(:params) {{source_file_name: 'en.yml'}}
25
+ let(:params_as_query_string) {'&source_file_name=en.yml'}
26
+
27
+ it 'should export multilingual' do
28
+ stub_request(:get, full_path_with_auth_hash("/projects/#{project_id}/translations/multilingual", api_key, api_secret) + params_as_query_string)
29
+ .to_return(status: 200, body: 'file content')
30
+ response = project.export_multilingual(params)
31
+ expect(response.code).to eq(200)
32
+ end
33
+ end
34
+
35
+ describe 'export_app_description' do
36
+ let(:params) {{locale: 'ja'}}
37
+ let(:params_as_query_string) {'&locale=ja'}
38
+
39
+ it 'should export app description' do
40
+ stub_request(:get, full_path_with_auth_hash("/projects/#{project_id}/translations/app-descriptions", api_key, api_secret) + params_as_query_string)
41
+ .to_return(status: 200, body: 'file content')
42
+ response = project.export_app_description(params)
43
+ expect(response.code).to eq(200)
44
+ end
45
+ end
46
+
47
+ describe 'get_translation_status' do
48
+ let(:params) {{file_name: 'en.yml', locale: 'ja'}}
49
+ let(:params_as_query_string) {'&file_name=en.yml&locale=ja'}
50
+
51
+ it 'should show translation status' do
52
+ stub_request(:get, full_path_with_auth_hash("/projects/#{project_id}/translations/status", api_key, api_secret) + params_as_query_string)
53
+ .to_return(body: {})
54
+ response = project.get_translation_status(params)
55
+ expect(response).to be_an_instance_of(Hash)
56
+ end
57
+ end
58
+
59
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Project Group' do
4
+
5
+ let(:api_key) {'api_key'}
6
+ let(:api_secret) {'api_secret'}
7
+ let(:client) {Onesky::Client.new(api_key, api_secret)}
8
+
9
+ describe 'list_project_group' do
10
+ it 'should list all available project group' do
11
+ stub_request(:get, full_path_with_auth_hash('/project-groups', api_key, api_secret))
12
+ .to_return(body: {})
13
+ response = client.list_project_group
14
+ expect(response).to be_an_instance_of(Hash)
15
+ end
16
+ end
17
+
18
+ describe 'show_project_group' do
19
+ let(:project_group_id) {1}
20
+
21
+ it 'should show a project group information' do
22
+ stub_request(:get, full_path_with_auth_hash("/project-groups/#{project_group_id}", api_key, api_secret))
23
+ .to_return(body: {})
24
+ response = client.show_project_group(project_group_id)
25
+ expect(response).to be_an_instance_of(Hash)
26
+ end
27
+ end
28
+
29
+ describe 'create_project_group' do
30
+ let(:params) {{name: 'New Project Group'}}
31
+
32
+ it 'should create a project group' do
33
+ stub_request(:post, full_path_with_auth_hash('/project-groups', api_key, api_secret))
34
+ .with(body: params.to_json, headers: {'Content_Type' => 'application/json'})
35
+ .to_return(body: {})
36
+ response = client.create_project_group(params)
37
+ expect(response).to be_an_instance_of(Hash)
38
+ end
39
+ end
40
+
41
+ describe 'delete_project_group' do
42
+ let(:project_group_id) {1}
43
+
44
+ it 'should delete a project group' do
45
+ stub_request(:delete, full_path_with_auth_hash("/project-groups/#{project_group_id}", api_key, api_secret))
46
+ .to_return(body: {})
47
+ response = client.delete_project_group(project_group_id)
48
+ expect(response).to be_an_instance_of(Hash)
49
+ end
50
+ end
51
+
52
+ describe 'list_project_group_languages' do
53
+ let(:project_group_id) {1}
54
+
55
+ it 'should list languages activated of a project group' do
56
+ stub_request(:get, full_path_with_auth_hash("/project-groups/#{project_group_id}/languages", api_key, api_secret))
57
+ .to_return(body: {})
58
+ response = client.list_project_group_languages(project_group_id)
59
+ expect(response).to be_an_instance_of(Hash)
60
+ end
61
+ end
62
+
63
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Project' do
4
+
5
+ let(:api_key) {'api_key'}
6
+ let(:api_secret) {'api_secret'}
7
+ let(:client) {Onesky::Client.new(api_key, api_secret)}
8
+
9
+ describe 'list_project' do
10
+ let(:project_group_id) {1}
11
+
12
+ it 'should list all projects of a project group' do
13
+ stub_request(:get, full_path_with_auth_hash("/project-groups/#{project_group_id}/projects", api_key, api_secret))
14
+ .to_return(body: {})
15
+ response = client.list_project(project_group_id)
16
+ expect(response).to be_an_instance_of(Hash)
17
+ end
18
+ end
19
+
20
+ describe 'create_project' do
21
+ let(:project_group_id) {1}
22
+ let(:params) {{project_type: 'website'}}
23
+
24
+ it 'should list all projects of a project group' do
25
+ stub_request(:post, full_path_with_auth_hash("/project-groups/#{project_group_id}/projects", api_key, api_secret))
26
+ .with(body: params.to_json, headers: {'Content_Type' => 'application/json'})
27
+ .to_return(body: {})
28
+ response = client.create_project(project_group_id, params)
29
+ expect(response).to be_an_instance_of(Hash)
30
+ end
31
+ end
32
+
33
+ describe 'project' do
34
+ let(:project_id) {1}
35
+
36
+ it 'get project object' do
37
+ expect(client.project(project_id)).to be_an_instance_of(Onesky::Project)
38
+ end
39
+ end
40
+
41
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Project Type' do
4
+
5
+ let(:api_key) {'api_key'}
6
+ let(:api_secret) {'api_secret'}
7
+ let(:client) {Onesky::Client.new(api_key, api_secret)}
8
+
9
+ describe 'list_project_type' do
10
+ it 'should list all available project type' do
11
+ stub_request(:get, full_path_with_auth_hash('/project-types', api_key, api_secret))
12
+ .to_return(body: {})
13
+ response = client.list_project_type
14
+ expect(response).to be_an_instance_of(Hash)
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,18 @@
1
+ require 'digest'
2
+ require 'onesky'
3
+ require 'webmock/rspec'
4
+ WebMock.disable_net_connect!(allow_localhost: true)
5
+
6
+ def auth_query_string(api_key, api_secret)
7
+ now = Time.now.to_i
8
+ output = '?'
9
+ output += "api_key=#{api_key}"
10
+ output += "&timestamp=#{now.to_s}"
11
+ output += "&dev_hash=#{Digest::MD5.hexdigest(now.to_s + api_secret)}"
12
+
13
+ output
14
+ end
15
+
16
+ def full_path_with_auth_hash(path, api_key, api_secret)
17
+ "#{Helpers::Request::ENDPOINT}/#{Helpers::Request::VERSION}#{path}#{auth_query_string(api_key, api_secret)}"
18
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: onesky-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Victor Lam
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.19'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.19'
83
+ description: Ruby wrapper for OneSky API
84
+ email:
85
+ - victorebox@yahoo.com.hk
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/onesky.rb
97
+ - lib/onesky/client.rb
98
+ - lib/onesky/errors.rb
99
+ - lib/onesky/helpers/request.rb
100
+ - lib/onesky/project.rb
101
+ - lib/onesky/resources/locale.rb
102
+ - lib/onesky/resources/project.rb
103
+ - lib/onesky/resources/project/base.rb
104
+ - lib/onesky/resources/project/file_mgt.rb
105
+ - lib/onesky/resources/project/import_task.rb
106
+ - lib/onesky/resources/project/order.rb
107
+ - lib/onesky/resources/project/quotation.rb
108
+ - lib/onesky/resources/project/translation.rb
109
+ - lib/onesky/resources/project_group.rb
110
+ - lib/onesky/resources/project_type.rb
111
+ - lib/onesky/restclient.rb
112
+ - lib/onesky/version.rb
113
+ - onesky-ruby.gemspec
114
+ - spec/fixture/en.yml
115
+ - spec/onesky/client_spec.rb
116
+ - spec/onesky/helpers/request_spec.rb
117
+ - spec/onesky/resources/locale_spec.rb
118
+ - spec/onesky/resources/project/base_spec.rb
119
+ - spec/onesky/resources/project/file_spec.rb
120
+ - spec/onesky/resources/project/import_task_spec.rb
121
+ - spec/onesky/resources/project/order_spec.rb
122
+ - spec/onesky/resources/project/quotation_spec.rb
123
+ - spec/onesky/resources/project/translation_spec.rb
124
+ - spec/onesky/resources/project_group_spec.rb
125
+ - spec/onesky/resources/project_spec.rb
126
+ - spec/onesky/resources/project_type_spec.rb
127
+ - spec/spec_helper.rb
128
+ homepage: http://github.com/onesky/onesky-ruby
129
+ licenses:
130
+ - MIT
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.2.2
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: To interact with OneSky Platform API
152
+ test_files:
153
+ - spec/fixture/en.yml
154
+ - spec/onesky/client_spec.rb
155
+ - spec/onesky/helpers/request_spec.rb
156
+ - spec/onesky/resources/locale_spec.rb
157
+ - spec/onesky/resources/project/base_spec.rb
158
+ - spec/onesky/resources/project/file_spec.rb
159
+ - spec/onesky/resources/project/import_task_spec.rb
160
+ - spec/onesky/resources/project/order_spec.rb
161
+ - spec/onesky/resources/project/quotation_spec.rb
162
+ - spec/onesky/resources/project/translation_spec.rb
163
+ - spec/onesky/resources/project_group_spec.rb
164
+ - spec/onesky/resources/project_spec.rb
165
+ - spec/onesky/resources/project_type_spec.rb
166
+ - spec/spec_helper.rb
167
+ has_rdoc: