smartling 0.5.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +3 -1
- data/lib/smartling/fileapi.rb +8 -0
- data/lib/smartling/uri.rb +4 -5
- data/lib/smartling/version.rb +4 -5
- data/samples/data.yaml +29 -0
- data/samples/file_api.rb +46 -33
- data/tests/api_test.rb +8 -5
- data/tests/srv_fileapi_test.rb +11 -0
- data/tests/uri_test.rb +9 -4
- metadata +30 -36
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZTQ1MWMzYzU0ZDBjMGM1MDkyMDNmZTQyYjFkNjBmYTI0MjAyNzhiMA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YzBhMmI5ZGVkNzdhM2YwYzYyOGQzNjI2NmJlZmQ4Mzg2Y2ExZTg0Ng==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OTliMzE2ZGU1ZWMwYWMxOGIzNzQxMmVlNzgwZDEyYTdhMjUxZmU4ZTIxMTAw
|
10
|
+
NzU0MGQ4ODMwYzY1ZTlkOWQ0MTRkODIwNTY4NDQxOTU0ZmEwYjE0Nzk4YmYy
|
11
|
+
NWIxNTU3ODc3ZTFmZTg3MWY4MzYxMzc3OGQ1OGZmODI0YTIyNmM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MDlkN2U5MDcwYWY4NWU4NmFhNzNhOGVmM2NhYWU2MWVjYmM3NjBhNTA0MWVk
|
14
|
+
YmZlZTJiNDRhNjRjNjhjYTllNDgzMjJiMTUyZjE3YTMzMzdmYWQyZWQzNjgz
|
15
|
+
ZDgzNTc2ODFiYWFlNGRkMDg4NDEyZDZjZTAwNjhjOTc3NTQ1ZTI=
|
data/README.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
[![rubygems](https://img.shields.io/gem/v/smartling.svg)](https://rubygems.org/gems/smartling)
|
2
|
+
[![build status](https://travis-ci.org/Smartling/api-sdk-ruby.svg)](https://travis-ci.org/Smartling/api-sdk-ruby)
|
3
|
+
|
1
4
|
[Smartling Translation API](http://docs.smartling.com)
|
2
5
|
=================
|
3
6
|
|
@@ -59,4 +62,3 @@ distributed under the License is distributed on an "AS IS" BASIS,
|
|
59
62
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
60
63
|
See the License for the specific language governing permissions and
|
61
64
|
limitations under the License.
|
62
|
-
|
data/lib/smartling/fileapi.rb
CHANGED
@@ -23,6 +23,7 @@ module Smartling
|
|
23
23
|
FILE_UPLOAD = 'file/upload'
|
24
24
|
FILE_RENAME = 'file/rename'
|
25
25
|
FILE_DELETE = 'file/delete'
|
26
|
+
FILE_IMPORT = 'file/import'
|
26
27
|
end
|
27
28
|
|
28
29
|
class File < Api
|
@@ -63,6 +64,13 @@ module Smartling
|
|
63
64
|
uri = uri(Services::FILE_DELETE, keys, params).require(:fileUri)
|
64
65
|
return api_delete(uri.to_s)
|
65
66
|
end
|
67
|
+
|
68
|
+
def import(file, name, type, state, params = nil)
|
69
|
+
keys = { :fileUri => name, :fileType => type, :translationState => state}
|
70
|
+
uri = uri(Services::FILE_IMPORT, keys, params).require(:fileUri, :fileType, :locale, :translationState)
|
71
|
+
file = ::File.open(file, 'rb') if file.is_a?(String)
|
72
|
+
return post(uri.to_s, :file => file)
|
73
|
+
end
|
66
74
|
end
|
67
75
|
|
68
76
|
end
|
data/lib/smartling/uri.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# Copyright 2012 Smartling, Inc.
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
5
5
|
# You may obtain a copy of the License at
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
8
|
+
#
|
9
9
|
# Unless required by applicable law or agreed to in writing, software
|
10
10
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -62,7 +62,7 @@ module Smartling
|
|
62
62
|
|
63
63
|
def format_value(v)
|
64
64
|
v.is_a?(Time) ? format_time(v) :
|
65
|
-
|
65
|
+
CGI.escape(v.to_s).gsub('+', '%20')
|
66
66
|
end
|
67
67
|
|
68
68
|
def format_time(t)
|
@@ -71,4 +71,3 @@ module Smartling
|
|
71
71
|
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
data/lib/smartling/version.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# Copyright 2012 Smartling, Inc.
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
5
5
|
# You may obtain a copy of the License at
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
8
|
+
#
|
9
9
|
# Unless required by applicable law or agreed to in writing, software
|
10
10
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -14,6 +14,5 @@
|
|
14
14
|
|
15
15
|
module Smartling
|
16
16
|
# This follows Semantic Versioning http://semver.org/
|
17
|
-
VERSION = '0.
|
17
|
+
VERSION = '1.0.0'
|
18
18
|
end
|
19
|
-
|
data/samples/data.yaml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
---
|
2
|
+
invoice: 34843
|
3
|
+
date : 2001-01-23
|
4
|
+
bill-to: &id001
|
5
|
+
given : Chris
|
6
|
+
family : Dumars
|
7
|
+
address:
|
8
|
+
lines: |
|
9
|
+
458 Walkman Dr.
|
10
|
+
Suite #292
|
11
|
+
city : Royal Oak
|
12
|
+
state : MI
|
13
|
+
postal : 48046
|
14
|
+
# ship-to: *id001
|
15
|
+
product:
|
16
|
+
- sku : BL394D
|
17
|
+
quantity : 4
|
18
|
+
description : Basketball
|
19
|
+
price : 450.00
|
20
|
+
- sku : BL4438H
|
21
|
+
quantity : 1
|
22
|
+
description : Super Hoop
|
23
|
+
price : 2392.00
|
24
|
+
tax : 251.42
|
25
|
+
total: 4443.52
|
26
|
+
comments: >
|
27
|
+
Late afternoon is best.
|
28
|
+
Backup contact is Nancy
|
29
|
+
Billsmer @ 338-4338.
|
data/samples/file_api.rb
CHANGED
@@ -16,84 +16,97 @@
|
|
16
16
|
require 'rubygems'
|
17
17
|
require 'smartling'
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
def print_msg(msg)
|
20
|
+
puts
|
21
|
+
puts msg
|
22
|
+
end
|
21
23
|
|
22
|
-
|
24
|
+
API_KEY = 'YOUR_API_KEY' # change this value to use "Smartling API key" found on the Project Settings -> API page in dashboard
|
25
|
+
PROJECT_ID = 'YOUR_PROJECT_ID' # change this value to use "Project Id" found on the Project Settings -> API page in dashboard
|
23
26
|
|
27
|
+
print_msg "Smartling Ruby client #{Smartling::VERSION}"
|
24
28
|
|
25
|
-
# Initialize client to
|
29
|
+
# Initialize client to use File API on Sandbox
|
26
30
|
sl = Smartling::File.sandbox(:apiKey => API_KEY, :projectId => PROJECT_ID)
|
27
31
|
|
28
|
-
# Initialize client
|
32
|
+
# Initialize client to use File API on Production
|
29
33
|
#sl = Smartling::File.new(:apiKey => API_KEY, :projectId => PROJECT_ID)
|
30
34
|
|
31
|
-
#
|
32
|
-
|
35
|
+
# Basic usage
|
36
|
+
|
37
|
+
file = 'data.yaml' # your data file
|
38
|
+
file_uri = 'my_files/data.yaml' # unique identifier given to the uploaded file
|
39
|
+
file_type = 'YAML' # file type
|
40
|
+
|
41
|
+
print_msg "Uploading file '#{file}' using file URI '#{file_uri}' and file type '#{file_type}'..."
|
42
|
+
res = sl.upload(file, file_uri, file_type)
|
33
43
|
p res
|
34
44
|
|
35
|
-
|
36
|
-
res = sl.list
|
45
|
+
print_msg 'Listing all project files...'
|
46
|
+
res = sl.list
|
37
47
|
p res
|
38
48
|
|
39
|
-
|
40
|
-
|
49
|
+
lang = 'es-ES' # any language that exists in your project
|
50
|
+
state = 'PUBLISHED' # state at which imported strings are imported as
|
41
51
|
|
42
|
-
|
43
|
-
res = sl.status(
|
52
|
+
print_msg "Getting status for file URI '#{file_uri}' and language '#{lang}'..."
|
53
|
+
res = sl.status(file_uri, :locale => lang)
|
44
54
|
p res
|
45
55
|
|
46
|
-
#
|
47
|
-
|
56
|
+
print_msg "Importing translation file '#{file}' using file URI '#{file_uri}' and file type '#{file_type}' and language '#{lang}' as '#{state}'..."
|
57
|
+
res = sl.import(file, file_uri, file_type, state, :locale => lang)
|
58
|
+
|
59
|
+
print_msg "Downloading translations for file URI '#{file_uri}' and language '#{lang}'..."
|
60
|
+
data = sl.download(file_uri, :locale => lang)
|
48
61
|
puts data
|
49
62
|
|
50
|
-
#
|
51
|
-
newname = 'path/newname.yaml'
|
52
|
-
sl.rename(name, newname)
|
63
|
+
new_file_uri = 'my_files/new_data.yaml' # new uri to uniquely identify the previously uploaded file
|
53
64
|
|
54
|
-
#
|
55
|
-
sl.
|
65
|
+
print_msg "Renaming file from '#{file_uri}' to '#{new_file_uri}'..."
|
66
|
+
sl.rename(file_uri, new_file_uri)
|
67
|
+
|
68
|
+
print_msg "Deleting file '#{new_file_uri}'..."
|
69
|
+
sl.delete(new_file_uri)
|
56
70
|
|
57
71
|
# Extended parameters
|
58
72
|
|
59
|
-
|
60
|
-
res = sl.upload(
|
73
|
+
print_msg 'Uploading file with callback URL provided...'
|
74
|
+
res = sl.upload(file, 'name.yaml', 'YAML', :callbackUrl => 'http://yourdomain.com/someservice')
|
61
75
|
p res
|
62
76
|
|
63
|
-
|
64
|
-
res = sl.upload(
|
77
|
+
print_msg 'Uploading file with approved flag provided...'
|
78
|
+
res = sl.upload(file, 'name.yaml', 'YAML', :approved => true)
|
65
79
|
p res
|
66
80
|
|
67
|
-
|
81
|
+
print_msg 'Listing files using URI mask filter...'
|
68
82
|
res = sl.list(:uriMask => '%.yaml')
|
69
83
|
p res
|
70
84
|
|
71
|
-
|
85
|
+
print_msg 'Listing files using file type filter...'
|
72
86
|
res = sl.list(:fileTypes => ['yaml', 'ios'])
|
73
87
|
p res
|
74
88
|
|
75
|
-
|
89
|
+
print_msg 'Listing files ordered by attributes...'
|
76
90
|
res = sl.list(:orderBy => ['fileUri', 'wordCount_desc'])
|
77
91
|
p res
|
78
92
|
|
79
|
-
|
93
|
+
print_msg 'Listing paginated files...'
|
80
94
|
page, size = 2, 10
|
81
95
|
res = sl.list(:offset => (page - 1) * size, :limit => size)
|
82
96
|
p res
|
83
97
|
|
84
|
-
|
98
|
+
print_msg 'Listing files uploaded after a certain date...'
|
85
99
|
res = sl.list(:lastUploadedAfter => Time.utc(2012, 04, 05))
|
86
100
|
p res
|
87
101
|
|
88
|
-
|
102
|
+
print_msg 'Listing files uploaded between a date range...'
|
89
103
|
res = sl.list(:lastUploadedAfter => Time.utc(2012, 04, 01), :lastUploadedBefore => Time.utc(2012, 05, 01))
|
90
104
|
p res
|
91
105
|
|
92
|
-
|
106
|
+
print_msg 'Listing files using translation status...'
|
93
107
|
res = sl.list(:conditions => ['haveAllTranslated', 'haveAtLeastOneUnapproved'])
|
94
108
|
p res
|
95
109
|
|
96
|
-
|
110
|
+
print_msg 'Listing files while combining multiple parameters...'
|
97
111
|
res = sl.list(:fileTypes => 'yaml', :orderBy => 'fileUri', :offset => 20, :limit => 10)
|
98
112
|
p res
|
99
|
-
|
data/tests/api_test.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
# Copyright 2012 Smartling, Inc.
|
3
|
-
#
|
3
|
+
#
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
5
|
# you may not use this file except in compliance with the License.
|
6
6
|
# You may obtain a copy of the License at
|
7
|
-
#
|
7
|
+
#
|
8
8
|
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# Unless required by applicable law or agreed to in writing, software
|
11
11
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
12
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -21,7 +21,11 @@ module SmartlingTests
|
|
21
21
|
|
22
22
|
def stub_response(code, body)
|
23
23
|
status = Net::HTTPResponse.new('', code, '')
|
24
|
-
RestClient::Response.create
|
24
|
+
if RestClient::Response.method(:create).arity > 3
|
25
|
+
RestClient::Response.create(body, status, {}, nil)
|
26
|
+
else
|
27
|
+
RestClient::Response.create(body, status, {})
|
28
|
+
end
|
25
29
|
end
|
26
30
|
|
27
31
|
def test_endpoints
|
@@ -80,4 +84,3 @@ module SmartlingTests
|
|
80
84
|
|
81
85
|
end
|
82
86
|
end
|
83
|
-
|
data/tests/srv_fileapi_test.rb
CHANGED
@@ -60,6 +60,17 @@ we have: cookies
|
|
60
60
|
@log.debug res.inspect
|
61
61
|
end
|
62
62
|
|
63
|
+
def test_2_1_upload
|
64
|
+
@log.debug '<- FileAPI:upload'
|
65
|
+
sl = Smartling::File.new(@config)
|
66
|
+
|
67
|
+
res = nil
|
68
|
+
assert_nothing_raised do
|
69
|
+
res = sl.upload(yaml_file.path, TEST_FILE_YAML, 'YAML')
|
70
|
+
end
|
71
|
+
@log.debug res.inspect
|
72
|
+
end
|
73
|
+
|
63
74
|
def test_3_status
|
64
75
|
@log.debug '<- FileAPI:status'
|
65
76
|
sl = Smartling::File.new(@config)
|
data/tests/uri_test.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
# Copyright 2012 Smartling, Inc.
|
3
|
-
#
|
3
|
+
#
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
5
|
# you may not use this file except in compliance with the License.
|
6
6
|
# You may obtain a copy of the License at
|
7
|
-
#
|
7
|
+
#
|
8
8
|
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# Unless required by applicable law or agreed to in writing, software
|
11
11
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
12
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -87,6 +87,11 @@ module SmartlingTests
|
|
87
87
|
assert_equal('http://hello.wo/', uri.to_s)
|
88
88
|
end
|
89
89
|
|
90
|
+
def test_encode
|
91
|
+
uri = Smartling::Uri.new('http://hello.wo/')
|
92
|
+
uri.params = {:foo => ['hello & world!']}
|
93
|
+
assert_equal('http://hello.wo/?foo=hello%20%26%20world%21', uri.to_s)
|
94
|
+
end
|
95
|
+
|
90
96
|
end
|
91
97
|
end
|
92
|
-
|
metadata
CHANGED
@@ -1,48 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smartling
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Pavel Ivashkov
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-07-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: multi_json
|
16
|
-
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
17
16
|
requirements:
|
18
|
-
- -
|
17
|
+
- - ~>
|
19
18
|
- !ruby/object:Gem::Version
|
20
19
|
version: '1.0'
|
21
|
-
|
22
|
-
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
|
-
none: false
|
28
|
-
prerelease: false
|
29
|
-
type: :runtime
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rest-client
|
32
|
-
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
33
30
|
requirements:
|
34
|
-
- -
|
31
|
+
- - ~>
|
35
32
|
- !ruby/object:Gem::Version
|
36
33
|
version: '1.6'
|
37
|
-
|
38
|
-
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
37
|
requirements:
|
40
|
-
- -
|
38
|
+
- - ~>
|
41
39
|
- !ruby/object:Gem::Version
|
42
40
|
version: '1.6'
|
43
|
-
none: false
|
44
|
-
prerelease: false
|
45
|
-
type: :runtime
|
46
41
|
description: A Ruby library to utilize Smartling services
|
47
42
|
email:
|
48
43
|
- hi@smartling.com
|
@@ -50,13 +45,14 @@ executables: []
|
|
50
45
|
extensions: []
|
51
46
|
extra_rdoc_files: []
|
52
47
|
files:
|
53
|
-
- README.md
|
54
48
|
- LICENSE
|
49
|
+
- README.md
|
55
50
|
- lib/smartling.rb
|
56
51
|
- lib/smartling/api.rb
|
57
52
|
- lib/smartling/fileapi.rb
|
58
53
|
- lib/smartling/uri.rb
|
59
54
|
- lib/smartling/version.rb
|
55
|
+
- samples/data.yaml
|
60
56
|
- samples/file_api.rb
|
61
57
|
- tests/api_test.rb
|
62
58
|
- tests/config.sample
|
@@ -66,32 +62,30 @@ files:
|
|
66
62
|
homepage: https://docs.smartling.com
|
67
63
|
licenses:
|
68
64
|
- LICENSE
|
69
|
-
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
70
67
|
rdoc_options: []
|
71
68
|
require_paths:
|
72
69
|
- lib
|
73
70
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
71
|
requirements:
|
75
|
-
- -
|
72
|
+
- - ! '>='
|
76
73
|
- !ruby/object:Gem::Version
|
77
74
|
version: 1.8.6
|
78
|
-
none: false
|
79
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
76
|
requirements:
|
81
|
-
- -
|
77
|
+
- - ! '>='
|
82
78
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
84
|
-
MA==
|
85
|
-
none: false
|
79
|
+
version: '0'
|
86
80
|
requirements: []
|
87
|
-
rubyforge_project:
|
88
|
-
rubygems_version:
|
89
|
-
signing_key:
|
90
|
-
specification_version:
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.4.5
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
91
85
|
summary: Smartling SDK
|
92
86
|
test_files:
|
93
|
-
- tests/api_test.rb
|
94
|
-
- tests/config.sample
|
95
|
-
- tests/srv_fileapi_test.rb
|
96
|
-
- tests/test_helper.rb
|
97
87
|
- tests/uri_test.rb
|
88
|
+
- tests/test_helper.rb
|
89
|
+
- tests/srv_fileapi_test.rb
|
90
|
+
- tests/config.sample
|
91
|
+
- tests/api_test.rb
|