toptranslation_api 2.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f4c3de10e646ba06f7bd4c0cfe60d2c789e5996707970fc3915c2bd7b4062c6c
4
+ data.tar.gz: ece7d100b8829473e9b4e71d79fc47e3a8823c0599d7ce69207f9dc1fcd8eeb7
5
+ SHA512:
6
+ metadata.gz: '0928e7f0eaa21782f56f797ce6363ffd0d4a6c1014d46f50aa663ba79bb26d1cbf6dbbb53d9b98108d5174029b6a4c39cdad35bf752207aa0fca335cc9ae3584'
7
+ data.tar.gz: a9c63d299370fc8f1b32c4c8b6bd27f470a4d9e75a3c15aca8f454a723d62ad448688431ae1bca134f091df016943c7152edf3c31bf5f70bbf44e3ef4e087a30
@@ -0,0 +1,23 @@
1
+ module Toptranslation
2
+ class Client
3
+ def initialize(options)
4
+ @connection = Connection.new(options)
5
+ end
6
+
7
+ def orders(options = {})
8
+ @order_list ||= Resource::OrderList.new(@connection, options)
9
+ end
10
+
11
+ def translations(options = {})
12
+ @translation_list ||= Resource::TranslationList.new(@connection, options)
13
+ end
14
+
15
+ def projects(options = {})
16
+ @project_list ||= Resource::ProjectList.new(@connection, options)
17
+ end
18
+
19
+ def locales(options = {})
20
+ @locale_list ||= Resource::LocaleList.new(@connection, options)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,107 @@
1
+ module Toptranslation
2
+ class Connection
3
+ attr_accessor :upload_token, :verbose
4
+
5
+ def initialize(options = {})
6
+ @base_url = options[:base_url] || 'https://api.toptranslation.com'
7
+ @files_url = options[:files_url] || 'https://files.toptranslation.com'
8
+ @access_token = options[:access_token] || sign_in(options)
9
+ @verbose = options[:verbose] || false
10
+ end
11
+
12
+ def get(path, options = {})
13
+ transform_response(request(:get, path, options), options)
14
+ end
15
+
16
+ def post(path, options = {})
17
+ transform_response(request(:post, path, options), options)
18
+ end
19
+
20
+ def patch(path, options = {})
21
+ transform_response(request(:patch, path, options), options)
22
+ end
23
+
24
+ def download(url)
25
+ puts "# downloading #{url}" if @verbose
26
+ raw = RestClient::Request.execute(method: :get, url: url, raw_response: true)
27
+ raw.file
28
+ end
29
+
30
+ def upload(filepath, type)
31
+ response = RestClient.post(
32
+ "#{@files_url}/documents",
33
+ file: File.new(filepath),
34
+ type: type,
35
+ token: upload_token
36
+ )
37
+
38
+ transform_response(response, version: 0)
39
+ end
40
+
41
+ private
42
+
43
+ def version(options)
44
+ options[:version] || 0
45
+ end
46
+
47
+ def request(method, path, options)
48
+ url = "#{@base_url}/v#{version(options)}#{path}"
49
+ puts "# #{method}-request #{url}" if @verbose
50
+ puts "options: #{prepare_request_options(options, method)}" if @verbose
51
+ RestClient.send(method, url, prepare_request_options(options, method))
52
+ rescue RestClient::ExceptionWithResponse => e
53
+ puts e.response if @verbose
54
+ raise e
55
+ end
56
+
57
+ def upload_token
58
+ @upload_token ||= request_upload_token
59
+ end
60
+
61
+ def request_upload_token
62
+ puts '# Requesting upload-token' if @verbose
63
+ token = post('/upload_tokens')['upload_token']
64
+ puts "# Upload-token retrieved: #{token}" if @verbose
65
+ token
66
+ end
67
+
68
+ def sign_in(options)
69
+ sign_in_options = {
70
+ email: options[:email],
71
+ password: options[:password],
72
+ application_id: 'pollux'
73
+ }.merge!(options)
74
+
75
+ access_token = post('/auth/sign_in', sign_in_options)['access_token']
76
+
77
+ puts "# Requested access token #{access_token}" if @verbose
78
+
79
+ access_token
80
+ end
81
+
82
+ def transform_response(response, options)
83
+ puts response if @verbose
84
+ parsed = JSON.parse(response)
85
+ if version(options) == 2
86
+ parsed
87
+ else
88
+ parsed['data']
89
+ end
90
+ end
91
+
92
+ def prepare_request_options(options, method)
93
+ request_options = options.dup
94
+ request_options.delete(:version)
95
+ if %i[post patch].include? method
96
+ request_options.merge(auth_params)
97
+ else
98
+ params = options[:params] || {}
99
+ request_options.merge(params: params.merge(auth_params))
100
+ end
101
+ end
102
+
103
+ def auth_params
104
+ { access_token: @access_token }
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,76 @@
1
+ module Toptranslation::Resource
2
+ class Document
3
+ attr_reader :identifier, :string_count, :has_missing_strings, :translations, :updated_at, :created_at
4
+ attr_accessor :name, :path
5
+
6
+ def initialize(connection, options = {})
7
+ @connection = connection
8
+ @options = options
9
+
10
+ update_from_response(options)
11
+ end
12
+
13
+ def add_translation(filepath, locale_code, options = {})
14
+ upload = Upload.new(@connection).upload(filepath)
15
+
16
+ response = @connection.post("/documents/#{@identifier}/translations", options.merge(
17
+ document_store_id: upload.document_store_id,
18
+ document_token: upload.document_token,
19
+ locale_code: locale_code
20
+ ))
21
+ end
22
+
23
+ def download(locale_code, options = {})
24
+ params = { file_format: options[:file_format], locale_code: locale_code }.compact
25
+ download_url = @connection.get("/documents/#{@identifier}/download", params: params)['download_url']
26
+ @connection.download(download_url, options[:filename])
27
+ end
28
+
29
+ def save
30
+ response = @identifier ? update_remote_document : create_remote_document
31
+ update_and_return_from_response(response)
32
+ end
33
+
34
+ def strings
35
+ StringList.new(@connection, document_identifier: @identifier)
36
+ end
37
+
38
+ private
39
+
40
+ def update_remote_document
41
+ @connection.patch("/documents/#{@identifier}", remote_hash)
42
+ end
43
+
44
+ def create_remote_document
45
+ @connection.post('/documents', remote_hash)
46
+ end
47
+
48
+ def update_and_return_from_response(response)
49
+ if response
50
+ update_from_response(response)
51
+ self
52
+ end
53
+ end
54
+
55
+ def update_from_response(response)
56
+ @identifier = response['identifier'] if response['identifier']
57
+ @name = response['name'] if response['name']
58
+ @path = response['path'] if response['path']
59
+ @string_count = response['string_count'] if response['string_count']
60
+ @has_missing_strings = response['has_missing_strings'] if response['has_missing_strings']
61
+ @updated_at = DateTime.parse(response['updated_at']) if response['updated_at']
62
+ @created_at = DateTime.parse(response['created_at']) if response['created_at']
63
+ if response['translations']
64
+ @translations = response['translations'].inject([]) do |accu, translation|
65
+ accu << Translation.new(@connection, translation)
66
+ end
67
+ end
68
+ end
69
+
70
+ def remote_hash
71
+ hash = {}
72
+ hash[:name] = @name if @name
73
+ hash
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,25 @@
1
+ module Toptranslation::Resource
2
+ class DocumentList
3
+ include Enumerable
4
+
5
+ def initialize(connection, options = {})
6
+ @connection = connection
7
+ @options = options
8
+ end
9
+
10
+ def find(identifier)
11
+ result = @connection.get("/documents/#{identifier}")
12
+ Document.new(@connection, result)
13
+ end
14
+
15
+ def each
16
+ documents.each { |document| yield Document.new(@connection, document) }
17
+ end
18
+
19
+ private
20
+
21
+ def documents
22
+ @connection.get('/documents')
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,18 @@
1
+ module Toptranslation::Resource
2
+ class Locale
3
+ attr_reader :name, :code, :custom_code
4
+
5
+ def initialize(options = {})
6
+ @options = options
7
+ update_from_response(options)
8
+ end
9
+
10
+ private
11
+
12
+ def update_from_response(response)
13
+ @code = response['code'] if response['code']
14
+ @name = response['name'] if response['name']
15
+ @custom_code = response['custom_code'] if response['custom_code']
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,25 @@
1
+ module Toptranslation::Resource
2
+ class LocaleList
3
+ include Enumerable
4
+
5
+ def initialize(connection, options = {})
6
+ @connection = connection
7
+ @options = options
8
+ end
9
+
10
+ def find(code)
11
+ result = locales.select { |l| l['code'] == code }.first
12
+ Locale.new(result) if result
13
+ end
14
+
15
+ def each
16
+ locales.each { |locale| yield Locale.new(locale) }
17
+ end
18
+
19
+ private
20
+
21
+ def locales
22
+ @connection.get('/locales', version: 2)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,113 @@
1
+ module Toptranslation::Resource
2
+ class Order
3
+ attr_reader :identifier, :state, :created_at,
4
+ :requested_at, :ordered_at, :estimated_delivery_date,
5
+ :creator_hash, :progress, :order_number
6
+ attr_accessor :name, :reference, :comment, :coupon_code, :service_level, :desired_delivery_date, :quote_required
7
+
8
+ def initialize(connection, options = {})
9
+ @connection = connection
10
+ @options = options
11
+ @name = @options[:name]
12
+ @reference = @options[:reference]
13
+ @comment = @options[:comment]
14
+ @coupon_code = @options[:coupon_code]
15
+ @service_level = @options[:service_level]
16
+ @desired_delivery_date = @options[:desired_delivery_date]
17
+ @quote_required = @options[:quote_required]
18
+ @delivery_date = nil
19
+ @identifier = nil
20
+
21
+ update_from_response(options)
22
+ end
23
+
24
+ def add_document(document_store_id, document_token, source_locale_code, target_locale_codes)
25
+ response = @connection.post("/orders/#{@identifier}/documents",
26
+ document_store_id: document_store_id,
27
+ document_token: document_token,
28
+ source_locale_code: source_locale_code,
29
+ target_locale_codes: target_locale_codes,
30
+ version: 2)
31
+
32
+ Document.new(@connection, response)
33
+ end
34
+
35
+ def upload_document(filepath, source_locale_code, target_locale_codes)
36
+ upload = Upload.new(@connection).upload(filepath)
37
+
38
+ add_document(upload.document_store_id, upload.document_token, source_locale_code, target_locale_codes)
39
+ end
40
+
41
+ def documents
42
+ @connection.get("/orders/#{@identifier}/documents", version: 2)
43
+ end
44
+
45
+ def quotes
46
+ @quotes ||= @options['quotes'].map { |quote| Quote.new(@connection, quote) }
47
+ end
48
+
49
+ def translations
50
+ TranslationList.new(@connection, order_identifier: @identifier)
51
+ end
52
+
53
+ def creator
54
+ @creator ||= User.new(@connection, @options['creator'])
55
+ end
56
+
57
+ def save
58
+ response = @identifier ? update_remote_order : create_remote_order
59
+ update_and_return_from_response(response)
60
+ end
61
+
62
+ def request
63
+ response = @connection.patch("/orders/#{@identifier}/request", version: 2)
64
+ update_and_return_from_response(response)
65
+ end
66
+
67
+ private
68
+
69
+ def update_remote_order
70
+ @connection.patch("/orders/#{@identifier}", remote_hash.merge(version: 2))
71
+ end
72
+
73
+ def create_remote_order
74
+ @connection.post('/orders', remote_hash.merge(version: 2))
75
+ end
76
+
77
+ def update_and_return_from_response(response)
78
+ if response
79
+ update_from_response(response)
80
+ self
81
+ end
82
+ end
83
+
84
+ def update_from_response(response)
85
+ @identifier = response['identifier'] if response['identifier']
86
+ @state = response['state'] if response['state']
87
+ @created_at = Time.parse(response['created_at']) if response['created_at']
88
+ @ordered_at = Time.parse(response['ordered_at']) if response['ordered_at']
89
+ @estimated_delivery_date = Time.parse(response['estimated_delivery_date']) if response['estimated_delivery_date']
90
+ @name = response['name'] if response['name']
91
+ @reference = response['reference'] if response['reference']
92
+ @comment = response['comment'] if response['comment']
93
+ @progress = response['progress_in_percent'] if response['progress_in_percent']
94
+ @order_number = response['order_number'] if response['order_number']
95
+ @service_level = response['service_level'] if response['service_level']
96
+ @desired_delivery_date = response['desired_delivery_date'] if response['desired_delivery_date']
97
+ end
98
+
99
+ def remote_hash
100
+ hash = {}
101
+ hash[:reference] = @reference if @reference
102
+ hash[:comment] = @comment if @comment
103
+ hash[:coupon_code] = @coupon_code
104
+ hash[:delivery_date] = @delivery_date
105
+ hash[:name] = @name if @name
106
+ hash[:service_level] = @service_level if @service_level
107
+ hash[:desired_delivery_date] = @desired_delivery_date if @desired_delivery_date
108
+ hash[:quote_required] = @quote_required if @quote_required
109
+
110
+ hash
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,29 @@
1
+ module Toptranslation::Resource
2
+ class OrderList
3
+ include Enumerable
4
+
5
+ def initialize(connection, options = {})
6
+ @connection = connection
7
+ @options = options
8
+ end
9
+
10
+ def find(identifier)
11
+ result = @connection.get("/orders/#{identifier}", version: 2)
12
+ Order.new(@connection, result)
13
+ end
14
+
15
+ def create(options = {})
16
+ Order.new(@connection, options)
17
+ end
18
+
19
+ def each
20
+ orders.each { |order| yield Order.new(@connection, order) }
21
+ end
22
+
23
+ private
24
+
25
+ def orders
26
+ @connection.get('/orders', version: 2)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,77 @@
1
+ module Toptranslation::Resource
2
+ class Project
3
+ attr_reader :identifier, :created_at, :locales, :source_locale
4
+ attr_accessor :name
5
+
6
+ def initialize(connection, options = {})
7
+ @connection = connection
8
+ @options = options
9
+
10
+ update_from_response(options)
11
+ end
12
+
13
+ def upload_document(filepath, locale_code, options = {})
14
+ upload = Upload.new(@connection).upload(filepath)
15
+
16
+ attr_hash = {
17
+ document_store_id: upload.document_store_id,
18
+ document_token: upload.document_token,
19
+ locale_code: locale_code
20
+ }
21
+
22
+ attr_hash[:path] = options[:path] if options[:path]
23
+ attr_hash[:name] = options[:name] if options[:name]
24
+
25
+ response = @connection.post("/projects/#{@identifier}/documents", attr_hash)
26
+
27
+ Document.new(@connection, response)
28
+ end
29
+
30
+ def documents
31
+ ProjectDocumentList.new(@connection, project_identifier: @identifier)
32
+ end
33
+
34
+ def strings
35
+ StringList.new(@connection, project_identifier: @identifier)
36
+ end
37
+
38
+ def save
39
+ response = @identifier ? update_remote_project : create_remote_project
40
+ update_and_return_from_response(response)
41
+ end
42
+
43
+ private
44
+
45
+ def update_remote_project
46
+ @connection.patch("/projects/#{@identifier}", remote_hash)
47
+ end
48
+
49
+ def create_remote_project
50
+ @connection.post('/projects', remote_hash)
51
+ end
52
+
53
+ def update_and_return_from_response(response)
54
+ if response
55
+ update_from_response(response)
56
+ self
57
+ end
58
+ end
59
+
60
+ def update_from_response(response)
61
+ @identifier = response['identifier'] if response['identifier']
62
+ @created_at = DateTime.parse(response['created_at']) if response['created_at']
63
+ @locales = response['locales'].inject([]) do |accu, locale_data|
64
+ locale = Locale.new(locale_data)
65
+ @source_locale = locale if locale_data['is_source_locale'] # Set source locale of the project
66
+ accu << locale
67
+ end
68
+ @name = response['name'] if response['name']
69
+ end
70
+
71
+ def remote_hash
72
+ hash = {}
73
+ hash[:name] = @name if @name
74
+ hash
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,20 @@
1
+ module Toptranslation::Resource
2
+ class ProjectDocumentList < DocumentList
3
+ def create(name, path, options = {})
4
+ response = @connection.post("/projects/#{@options[:project_identifier]}/documents", options.merge(name: name, path: path))
5
+ Document.new(@connection, response)
6
+ end
7
+
8
+ def create_batch(documents)
9
+ response = @connection.post("/projects/#{@options[:project_identifier]}/documents/batch", documents: documents)
10
+
11
+ response.map { |document_attr| Document.new(@connection, document_attr) }
12
+ end
13
+
14
+ private
15
+
16
+ def documents
17
+ @connection.get("/projects/#{@options[:project_identifier]}/documents", params: { per_page: 100 })
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,29 @@
1
+ module Toptranslation::Resource
2
+ class ProjectList
3
+ include Enumerable
4
+
5
+ def initialize(connection, options = {})
6
+ @connection = connection
7
+ @options = options
8
+ end
9
+
10
+ def find(identifier)
11
+ result = @connection.get("/projects/#{identifier}")
12
+ Project.new(@connection, result)
13
+ end
14
+
15
+ def create(options = {})
16
+ Project.new(@connection, options)
17
+ end
18
+
19
+ def each
20
+ projects.each { |project| yield Project.new(@connection, project) }
21
+ end
22
+
23
+ private
24
+
25
+ def projects
26
+ @connection.get('/projects')
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,31 @@
1
+ module Toptranslation::Resource
2
+ class Quote
3
+ attr_reader :identifier, :state, :product, :value, :created_at,
4
+ :estimated_delivery_date
5
+
6
+ def initialize(connection, options = {})
7
+ @connection = connection
8
+ @options = options
9
+ update_from_response(options)
10
+ end
11
+
12
+ def accept
13
+ @connection.patch("/quotes/#{identifier}/accept", version: 2)
14
+ end
15
+
16
+ def reject(reason = nil)
17
+ @connection.patch("/quotes/#{identifier}/reject", reason: reason, version: 2)
18
+ end
19
+
20
+ private
21
+
22
+ def update_from_response(response)
23
+ @identifier = response['identifier'] if response['identifier']
24
+ @state = response['state'] if response['state']
25
+ @product = response['product'] if response['product']
26
+ @value = response['value'] if response['value']
27
+ @estimated_delivery_date = Time.parse(response['estimated_delivery_date']) if response['estimated_delivery_date']
28
+ @created_at = Time.parse(response['created_at']) if response['created_at']
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ module Toptranslation::Resource
2
+ class ReferenceDocument
3
+ attr_reader :identifier, :filename, :filesize, :mime_type, :comment, :created_at
4
+
5
+ def initialize(connection, options = {})
6
+ @connection = connection
7
+ @options = options
8
+ update_from_response(options)
9
+ end
10
+
11
+ def download
12
+ @connection.download(download_url)
13
+ end
14
+
15
+ def download_url
16
+ @download_url ||= @connection.get("/reference_documents/#{identifier}/download", version: 2)['download_url']
17
+ end
18
+
19
+ private
20
+
21
+ def update_from_response(response)
22
+ @identifier = response['identifier'] if response['identifier']
23
+ @filename = response['filename'] if response['filename']
24
+ @filesize = response['filesize'] if response['filesize']
25
+ @mime_type = response['mime_type'] if response['mime_type']
26
+ @comment = response['comment'] if response['comment']
27
+ @created_at = Time.parse(response['created_at']) if response['created_at']
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,64 @@
1
+ module Toptranslation::Resource
2
+ class String
3
+ attr_reader :identifier, :updated_at, :created_at
4
+ attr_accessor :value, :state, :project_identifier, :document_identifier, :key, :comment, :context, :array_index, :plural_form, :locale_code
5
+
6
+ def initialize(connection, options = {})
7
+ @connection = connection
8
+ @options = options
9
+
10
+ update_from_response(options)
11
+ end
12
+
13
+ def save
14
+ response = @identifier ? update_remote_string : create_remote_string
15
+ update_and_return_from_response(response)
16
+ end
17
+
18
+ private
19
+
20
+ def update_remote_string
21
+ @connection.patch("/strings/#{@identifier}", remote_hash)
22
+ end
23
+
24
+ def create_remote_string
25
+ @connection.post('/strings', remote_hash)
26
+ end
27
+
28
+ def update_and_return_from_response(response)
29
+ if response
30
+ update_from_response(response)
31
+ self
32
+ end
33
+ end
34
+
35
+ def update_from_response(response)
36
+ @identifier = response['identifier'] if response['identifier']
37
+ @key = response['key'] if response['key']
38
+ @value = response['value'] if response['value']
39
+ @state = response['state'] if response['state']
40
+ @comment = response['comment'] if response['comment']
41
+ @context = response['context'] if response['context']
42
+ @array_index = response['array_index'] if response['array_index']
43
+ @plural_form = response['plural_form'] if response['plural_form']
44
+ @locale_code = response['locale_code'] if response['locale_code']
45
+ @project_identifier = response['project_identifier'] if response['project_identifier']
46
+ @document_identifier = response['document_identifier'] if response['document_identifier']
47
+ @updated_at = DateTime.parse(response['updated_at']) if response['updated_at']
48
+ @created_at = DateTime.parse(response['created_at']) if response['created_at']
49
+ end
50
+
51
+ def remote_hash
52
+ hash = {}
53
+ hash[:key] = @key if @key
54
+ hash[:value] = @value if @value
55
+ hash[:state] = @state if @state
56
+ hash[:comment] = @comment if @comment
57
+ hash[:locale_code] = @locale_code if @locale_code
58
+ hash[:plural_form] = @plural_form if @plural_form
59
+ hash[:project_identifier] = @project_identifier if @project_identifier
60
+ hash[:document_identifier] = @document_identifier if @document_identifier
61
+ hash
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,32 @@
1
+ module Toptranslation::Resource
2
+ class StringList
3
+ include Enumerable
4
+
5
+ def initialize(connection, options = {})
6
+ @connection = connection
7
+ @options = options
8
+ end
9
+
10
+ def find(identifier)
11
+ result = @connection.get("/strings/#{identifier}")
12
+ Document.new(@connection, result)
13
+ end
14
+
15
+ def each
16
+ strings.each { |string| yield String.new(@connection, string) }
17
+ end
18
+
19
+ def create(options = {})
20
+ project_identifier = options['project_identifier'] || @options[:project_identifier]
21
+ document_identifier = options['document_identifier'] || @options[:document_identifier]
22
+
23
+ String.new(@connection, options.merge('project_identifier' => project_identifier, 'document_identifier' => document_identifier))
24
+ end
25
+
26
+ private
27
+
28
+ def strings
29
+ @connection.get('/strings', params: { project_identifier: @options[:project_identifier], document_identifier: @options[:document_identifier] })
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,41 @@
1
+ module Toptranslation::Resource
2
+ class Translation
3
+ attr_reader :identifier, :filename, :filesize, :mime_type, :updated_at, :created_at,
4
+ :progress, :sha1, :locale, :external_checksum, :segments_sha1
5
+
6
+ def initialize(connection, options = {})
7
+ @connection = connection
8
+ @options = options
9
+ update_from_response(options)
10
+ end
11
+
12
+ def reference_documents
13
+ @reference_documents ||= @options['reference_documents'].inject([]) do |accu, reference_document|
14
+ accu << ReferenceDocument.new(@connection, reference_document)
15
+ end
16
+ end
17
+
18
+ def download
19
+ @connection.download(download_url, @filename)
20
+ end
21
+
22
+ private
23
+
24
+ def download_url
25
+ @download_url ||= @connection.get("/translations/#{identifier}/download")['download_url']
26
+ end
27
+
28
+ def update_from_response(response)
29
+ @identifier = response['identifier'] if response['identifier']
30
+ @filename = response['filename'] if response['filename']
31
+ @mime_type = response['mime_type'] if response['mime_type']
32
+ @progress = response['progress_in_percent'] if response['progress_in_percent']
33
+ @sha1 = response['sha1'] if response['sha1']
34
+ @segments_sha1 = response['segments_sha1'] if response['segments_sha1']
35
+ @external_checksum = response['external_checksum'] if response['external_checksum']
36
+ @updated_at = DateTime.parse(response['updated_at']) if response['updated_at']
37
+ @created_at = DateTime.parse(response['created_at']) if response['created_at']
38
+ @locale = Locale.new(response['locale']) if response['locale']
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,25 @@
1
+ module Toptranslation::Resource
2
+ class TranslationList
3
+ include Enumerable
4
+
5
+ def initialize(connection, options = {})
6
+ @connection = connection
7
+ @options = options
8
+ end
9
+
10
+ def find(identifier)
11
+ result = @connection.get("/translations/#{identifier}")
12
+ Translation.new(@connection, result)
13
+ end
14
+
15
+ def each
16
+ translations.each { |translation| yield Translation.new(@connection, translation) }
17
+ end
18
+
19
+ private
20
+
21
+ def translations
22
+ @connection.get("/orders/#{@options[:order_identifier]}/translations") if @options[:order_identifier]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ module Toptranslation::Resource
2
+ class Upload
3
+ attr_reader :document_store_id, :document_token
4
+
5
+ def initialize(connection, options = {})
6
+ @connection = connection
7
+ @options = options
8
+ end
9
+
10
+ def upload(filepath, type = 'document')
11
+ puts "# Uploading: #{filepath}" if @connection.verbose
12
+ response = @connection.upload(filepath, type)
13
+
14
+ @document_store_id = response['identifier']
15
+ @document_token = response['document_token']
16
+
17
+ self
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ module Toptranslation::Resource
2
+ class User
3
+ attr_reader :identifier, :first_name, :last_name, :name
4
+
5
+ def initialize(connection, options = {})
6
+ @connection = connection
7
+ @options = options
8
+
9
+ update_from_response(options)
10
+ end
11
+
12
+ private
13
+
14
+ def update_from_response(response)
15
+ @identifier = response['identifier'] if response['identifier']
16
+ @first_name = response['first_name'] if response['first_name']
17
+ @first_name = response['last_name'] if response['last_name']
18
+ @name = response['name'] if response['name']
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Toptranslation
2
+ VERSION = '2.0.0'.freeze
3
+ end
@@ -0,0 +1,27 @@
1
+ require 'json'
2
+ require 'rest-client'
3
+ require 'toptranslation/client'
4
+ require 'toptranslation/connection'
5
+ require 'toptranslation/resource/document'
6
+ require 'toptranslation/resource/document_list'
7
+ require 'toptranslation/resource/project_document_list'
8
+ require 'toptranslation/resource/locale_list'
9
+ require 'toptranslation/resource/locale'
10
+ require 'toptranslation/resource/order_list'
11
+ require 'toptranslation/resource/order'
12
+ require 'toptranslation/resource/project'
13
+ require 'toptranslation/resource/project_list'
14
+ require 'toptranslation/resource/quote'
15
+ require 'toptranslation/resource/reference_document'
16
+ require 'toptranslation/resource/string_list'
17
+ require 'toptranslation/resource/string'
18
+ require 'toptranslation/resource/translation'
19
+ require 'toptranslation/resource/translation_list'
20
+ require 'toptranslation/resource/upload'
21
+ require 'toptranslation/resource/user'
22
+
23
+ module Toptranslation
24
+ def self.new(options)
25
+ Toptranslation::Client.new(options)
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: toptranslation_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Toptranslation GmbH
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-06-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.56.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.56.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.25.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.25.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.4'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.4'
125
+ description: Allows to create and control translation projects on Toptranslation via
126
+ the Toptranslation API.
127
+ email: tech@toptranslation.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - lib/toptranslation/client.rb
133
+ - lib/toptranslation/connection.rb
134
+ - lib/toptranslation/resource/document.rb
135
+ - lib/toptranslation/resource/document_list.rb
136
+ - lib/toptranslation/resource/locale.rb
137
+ - lib/toptranslation/resource/locale_list.rb
138
+ - lib/toptranslation/resource/order.rb
139
+ - lib/toptranslation/resource/order_list.rb
140
+ - lib/toptranslation/resource/project.rb
141
+ - lib/toptranslation/resource/project_document_list.rb
142
+ - lib/toptranslation/resource/project_list.rb
143
+ - lib/toptranslation/resource/quote.rb
144
+ - lib/toptranslation/resource/reference_document.rb
145
+ - lib/toptranslation/resource/string.rb
146
+ - lib/toptranslation/resource/string_list.rb
147
+ - lib/toptranslation/resource/translation.rb
148
+ - lib/toptranslation/resource/translation_list.rb
149
+ - lib/toptranslation/resource/upload.rb
150
+ - lib/toptranslation/resource/user.rb
151
+ - lib/toptranslation/version.rb
152
+ - lib/toptranslation_api.rb
153
+ homepage: https://github.com/toptranslation/toptranslation_ruby
154
+ licenses:
155
+ - MIT
156
+ metadata: {}
157
+ post_install_message:
158
+ rdoc_options: []
159
+ require_paths:
160
+ - lib
161
+ required_ruby_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ requirements: []
172
+ rubyforge_project:
173
+ rubygems_version: 2.7.6
174
+ signing_key:
175
+ specification_version: 4
176
+ summary: A ruby client for the Toptranslation API
177
+ test_files: []