smartling 1.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NTU2OWEzZjAwZTc4ZTUzN2EzZWZkNTNjY2M5NzJlZWJhMGRiMWFhZg==
5
- data.tar.gz: !binary |-
6
- NDdmYzYwMDZmZjIyMTI1MWY4MjJkN2VkOThiODFjYjdjZTVhMmFjZQ==
2
+ SHA1:
3
+ metadata.gz: 8eef838728d1e03aa7d98db81a5ea35742cea69d
4
+ data.tar.gz: 14e8bb96b9d86a81ae3dcc56c95d2f9f161fbf8b
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZmVhYjk2NjllZTBiMTRiYmRlMDczYTQ5OTE2MjM1NmZiZGIxNDQ1YzZhMjIy
10
- NTgwOWFiNDI2OGNhNGExZjg1NzJmMjM2YzAxYjUyMTk4ZTU3MzNjNjcwNWRm
11
- MWVlOTE4MGEyZGMwZDc1OGEwNGZjZTBjM2Q1ZmIyZDc2ZjZhZDE=
12
- data.tar.gz: !binary |-
13
- OGIzODdjYmMzZTZjNTAyYjkxOGNmOGRjNDIyMThjNWRkMTA5OTYzZGJjMTIz
14
- OTZmYjg3ZjMxNDg0ZGI3NjFmNjg0NTZkOTNjZDA1ZmE2MzliYTJhODBhMTE1
15
- Y2VjYzZiMjljYmZhNDNkZDM1OWRlYWJmMmFlYjA2M2JiMTAzZjQ=
6
+ metadata.gz: cfeaaeb1640b4c0710fbd7cb36032614802802f510ba971ef6546eb017dbb2d70d3ff053240ab844ed17b7193b287e68268ca4a65a3c0c597223b7a01f72af3c
7
+ data.tar.gz: 8d334b6681522832884c12328648afc9e262a8ae2ccdf67b2328b804bb6056b3829c841cd8078978b659b15438f14493e8e54dcc8804bc82c289596064e44e5e
data/README.md CHANGED
@@ -44,12 +44,13 @@ Authors
44
44
  -------
45
45
 
46
46
  * [Pavel Ivashkov](https://github.com/paiv)
47
+ * [Emilien Huet](https://github.com/emilienh)
47
48
 
48
49
 
49
50
  Copyright and license
50
51
  ---------------------
51
52
 
52
- Copyright 2012 Smartling, Inc.
53
+ Copyright 2012 - 2016 Smartling, Inc.
53
54
 
54
55
  Licensed under the Apache License, Version 2.0 (the "License");
55
56
  you may not use this file except in compliance with the License.
data/lib/smartling.rb CHANGED
@@ -14,4 +14,5 @@
14
14
 
15
15
  require 'smartling/version'
16
16
  require 'smartling/fileapi'
17
+ require 'smartling/projectapi'
17
18
 
data/lib/smartling/api.rb CHANGED
@@ -19,18 +19,16 @@ require 'smartling/uri'
19
19
  module Smartling
20
20
 
21
21
  module Endpoints
22
- V1 = 'https://api.smartling.com/v1/'
23
- SANDBOX_V1 = 'https://sandbox-api.smartling.com/v1/'
24
- CURRENT = V1
25
- SANDBOX = SANDBOX_V1
22
+ CURRENT = 'https://api.smartling.com/'
23
+ SANDBOX = 'https://api.stg.smartling.net/'
26
24
  end
27
25
 
28
26
  class Api
29
- attr_accessor :apiKey, :projectId, :baseUrl
27
+ attr_accessor :baseUrl, :prefix
30
28
 
31
29
  def initialize(args = {})
32
- @apiKey = args[:apiKey]
33
- @projectId = args[:projectId]
30
+ @userId = args[:userId]
31
+ @userSecret = args[:userSecret]
34
32
  @baseUrl = args[:baseUrl] || Endpoints::CURRENT
35
33
  end
36
34
 
@@ -40,25 +38,33 @@ module Smartling
40
38
 
41
39
  def uri(path, params1 = nil, params2 = nil)
42
40
  uri = Uri.new(@baseUrl, path)
43
- params = { :apiKey => @apiKey, :projectId => @projectId }
41
+ params = {}
44
42
  params.merge!(params1) if params1
45
43
  params.merge!(params2) if params2
46
44
  uri.params = params
47
- uri.require(:apiKey, :projectId)
48
45
  return uri
49
46
  end
50
47
 
51
48
  def check_response(res)
52
49
  return if res.code == 200
53
- raise format_api_error(res.body)
50
+ format_api_error(res.body)
51
+ raise 'API_ERROR'
54
52
  end
55
53
 
56
54
  def process(res)
57
55
  check_response(res)
58
56
  body = MultiJson.decode(res.body)
59
- body = body['response']
60
- raise format_api_error(res.body) unless body && body['code'] == 'SUCCESS'
61
- return body['data']
57
+ if body['response']
58
+ body = body['response']
59
+ if body['code'] == 'SUCCESS'
60
+ return body['data']
61
+ else
62
+ format_api_error(res.body)
63
+ raise 'API_ERROR'
64
+ end
65
+ end
66
+ raise 'API_ERROR'
67
+ return nil
62
68
  end
63
69
 
64
70
  def format_api_error(res)
@@ -66,34 +72,50 @@ module Smartling
66
72
  body = MultiJson.decode(res.body)
67
73
  rescue
68
74
  end
69
- body = body['response'] if body
70
- code = body['code'] if body
71
- msg = body['messages'] if body
72
- msg = msg.join(' -- ') if msg.is_a?(Array)
73
- return "API error: #{code} #{msg}" if code
74
- return res.description
75
+
76
+ if body && body['response']
77
+ body = body['response']
78
+ STDERR.puts "\e[31m#{body['code']}\e[0m"
79
+ if body['errors']
80
+ body['errors'].each do |e|
81
+ STDERR.puts "\e[31m#{e['message']}\e[0m"
82
+ end
83
+ end
84
+ end
75
85
  end
76
86
 
77
- def get(uri)
78
- RestClient.get(uri) {|res, _, _|
79
- process(res)
87
+ def call(uri, method, auth, upload, download, params = nil)
88
+ headers = {}
89
+ headers[:Authorization] = token_header() if auth
90
+ headers[:content_type] = :json unless upload
91
+ headers[:accept] = :json unless download
92
+ RestClient::Request.execute(:method => method,
93
+ :url => uri.to_s,
94
+ :payload => params,
95
+ :headers => headers) {|res, _, _|
96
+ if download
97
+ check_response(res)
98
+ res.body
99
+ else
100
+ process(res)
101
+ end
80
102
  }
81
103
  end
104
+
105
+ def get(uri)
106
+ call(uri, :get, true, false, false)
107
+ end
82
108
  def get_raw(uri)
83
- RestClient.get(uri) {|res, _, _|
84
- check_response(res)
85
- res.body
86
- }
109
+ call(uri, :get, true, false, true)
87
110
  end
88
111
  def post(uri, params = nil)
89
- RestClient.post(uri, params) {|res, _, _|
90
- process(res)
91
- }
112
+ call(uri, :post, true, false, false, params.to_json)
92
113
  end
93
- def delete(uri)
94
- RestClient.delete(uri) {|res, _, _|
95
- process(res)
96
- }
114
+ def post_file(uri, params = nil)
115
+ call(uri, :post, true, true, false, params)
116
+ end
117
+ def post_file_raw(uri, params = nil)
118
+ call(uri, :post, true, true, true, params)
97
119
  end
98
120
 
99
121
  def log=(v)
@@ -102,6 +124,52 @@ module Smartling
102
124
  def proxy=(v)
103
125
  RestClient.proxy = v
104
126
  end
127
+
128
+ # auth
129
+
130
+ def token_header()
131
+ t = token()
132
+ raise 'AUTH_ERROR' if t.nil?
133
+ return "Bearer #{t}"
134
+ end
135
+
136
+ def process_auth(response)
137
+ now = Time.new.to_i
138
+ @token = response['accessToken']
139
+ @token_expiration = now + response['expiresIn'].to_i
140
+ @refresh = response['refreshToken']
141
+ @refresh_expiration = now + response['refreshExpiresIn'].to_i
142
+ end
143
+
144
+ # Authenticate - /auth-api/v2/authenticate (POST)
145
+ def token()
146
+ # Check if current token is still valid
147
+ if @token
148
+ now = Time.new.to_i
149
+ if @token_expiration > now
150
+ return @token
151
+ elsif @refresh && @refresh_expiration > now
152
+ return refresh()
153
+ end
154
+ end
155
+
156
+ # Otherwise call authenticate endpoint
157
+ uri = uri('auth-api/v2/authenticate', {}, {})
158
+ RestClient.post(uri.to_s, {:userIdentifier => @userId, :userSecret => @userSecret}.to_json, {:content_type => :json, :accept => :json}) {|res, _, _|
159
+ process_auth(process(res))
160
+ return @token
161
+ }
162
+ end
163
+
164
+ # Refresh Authentication - /auth-api/v2/authenticate/refresh (POST)
165
+ def refresh()
166
+ uri = uri('auth-api/v2/authenticate/refresh', {}, {})
167
+ RestClient.post(uri.to_s, {:refreshToken => @refreshToken}.to_json, {:content_type => :json, :accept => :json}) {|res, _, _|
168
+ process_auth(process(res))
169
+ return @token
170
+ }
171
+ end
172
+
105
173
  end
106
174
 
107
175
  end
@@ -16,60 +16,123 @@ require 'smartling/api'
16
16
 
17
17
  module Smartling
18
18
 
19
- module Services
20
- FILE_LIST = 'file/list'
21
- FILE_STATUS = 'file/status'
22
- FILE_GET = 'file/get'
23
- FILE_UPLOAD = 'file/upload'
24
- FILE_RENAME = 'file/rename'
25
- FILE_DELETE = 'file/delete'
26
- FILE_IMPORT = 'file/import'
27
- end
28
-
29
19
  class File < Api
30
- alias :api_delete :delete
31
20
 
21
+ def initialize(args = {})
22
+ super(args)
23
+ @projectId = args[:projectId]
24
+ end
25
+
26
+ # List Files - /files-api/v2/projects/{projectId}/files/list (GET)
32
27
  def list(params = nil)
33
- uri = uri(Services::FILE_LIST, params)
34
- return get(uri.to_s)
28
+ uri = uri("files-api/v2/projects/#{@projectId}/files/list", params)
29
+ return get(uri)
30
+ end
31
+
32
+ # List File Types - /files-api/v2/projects/{projectId}/file-types (GET)
33
+ def list_types(params = nil)
34
+ uri = uri("files-api/v2/projects/#{@projectId}/file-types", params)
35
+ return get(uri)
36
+ end
37
+
38
+ # Status - All Locales - /files-api/v2/projects/{projectId}/file/status (GET)
39
+ def status_all(name)
40
+ keys = { :fileUri => name }
41
+ uri = uri("files-api/v2/projects/#{@projectId}/file/status", keys, {}).require(:fileUri)
42
+ return get(uri)
35
43
  end
36
44
 
37
- def status(name, params)
45
+ # Status - Single Locale / Extended Response - /files-api/v2/projects/{projectId}/locales/{localeId}/file/status (GET)
46
+ def status(name, locale)
38
47
  keys = { :fileUri => name }
39
- uri = uri(Services::FILE_STATUS, keys, params).require(:fileUri, :locale)
40
- return get(uri.to_s)
48
+ uri = uri("files-api/v2/projects/#{@projectId}/locales/#{locale}/file/status", keys, {}).require(:fileUri)
49
+ return get(uri)
41
50
  end
42
51
 
52
+ # Download Original File - /files-api/v2/projects/{projectId}/file (GET)
43
53
  def download(name, params = nil)
44
54
  keys = { :fileUri => name }
45
- uri = uri(Services::FILE_GET, keys, params).require(:fileUri)
46
- return get_raw(uri.to_s)
55
+ uri = uri("files-api/v2/projects/#{@projectId}/file", keys, params).require(:fileUri)
56
+ return get_raw(uri)
57
+ end
58
+
59
+ # Download Translated File - Single Locale - /files-api/v2/projects/{projectId}/locales/{localeId}/file (GET)
60
+ def download_translated(name, locale, params = nil)
61
+ keys = { :fileUri => name }
62
+ uri = uri("files-api/v2/projects/#{@projectId}/locales/#{locale}/file", keys, params).require(:fileUri)
63
+ return get_raw(uri)
64
+ end
65
+
66
+ # Download Translated Files - Multiple Locales as .ZIP - /files-api/v2/projects/{projectId}/files/zip (GET)
67
+ def download_translated_zip(names, params = nil)
68
+ keys = { :fileUris => names, :localeIds => locales }
69
+ uri = uri("files-api/v2/projects/#{@projectId}/files/zip", keys, params).require(:fileUris, :localeIds)
70
+ return get_raw(uri)
47
71
  end
48
72
 
73
+ # Download Translated File - All Locales as .ZIP - /files-api/v2/projects/{projectId}/locales/all/file/zip (GET)
74
+ def download_all_translated_zip(name, params = nil)
75
+ keys = { :fileUri => name }
76
+ uri = uri("files-api/v2/projects/#{@projectId}/locales/all/file/zip", keys, params).require(:fileUri)
77
+ return get_raw(uri)
78
+ end
79
+
80
+ # Download Translated File - All Locales in one File - CSV - /files-api/v2/projects/{projectId}/locales/all/file (GET)
81
+ def download_all_translated_csv(name, params = nil)
82
+ keys = { :fileUri => name }
83
+ uri = uri("files-api/v2/projects/#{@projectId}/locales/all/file", keys, params).require(:fileUri)
84
+ return get_raw(uri)
85
+ end
86
+
87
+ # Upload File - /files-api/v2/projects/{projectId}/file (POST)
49
88
  def upload(file, name, type, params = nil)
50
89
  keys = { :fileUri => name, :fileType => type }
51
- uri = uri(Services::FILE_UPLOAD, keys, params).require(:fileUri, :fileType)
90
+ uri = uri("files-api/v2/projects/#{@projectId}/file", keys, params).require(:fileUri, :fileType)
52
91
  file = ::File.open(file, 'rb') if file.is_a?(String)
53
- return post(uri.to_s, :file => file)
92
+ return post_file(uri, :file => file)
54
93
  end
55
94
 
95
+ # Rename - /files-api/v2/projects/{projectId}/file/rename (POST)
56
96
  def rename(name, newname, params = nil)
57
97
  keys = { :fileUri => name, :newFileUri => newname }
58
- uri = uri(Services::FILE_RENAME, keys, params).require(:fileUri, :newFileUri)
59
- return post(uri.to_s)
98
+ uri = uri("files-api/v2/projects/#{@projectId}/file/rename", keys, params).require(:fileUri, :newFileUri)
99
+ return post(uri)
60
100
  end
61
101
 
102
+ # Delete - /files-api/v2/projects/{projectId}/file/delete (POST)
62
103
  def delete(name, params = nil)
63
104
  keys = { :fileUri => name }
64
- uri = uri(Services::FILE_DELETE, keys, params).require(:fileUri)
65
- return api_delete(uri.to_s)
105
+ uri = uri("files-api/v2/projects/#{@projectId}/file/delete", keys, params).require(:fileUri)
106
+ return post(uri)
107
+ end
108
+
109
+ # Last Modified (by locale) - /files-api/v2/projects/{projectId}/locales/{localeId}/file/last-modified (GET)
110
+ def last_modified(name, locale, params = nil)
111
+ keys = { :fileUri => name }
112
+ uri = uri("files-api/v2/projects/#{@projectId}/locales/#{locale}/file/last-modified", keys, params).require(:fileUri)
113
+ return get(uri)
114
+ end
115
+
116
+ # Last Modified (all locales) - /files-api/v2/projects/{projectId}/file/last-modified (GET)
117
+ def last_modified_all(name, params = nil)
118
+ keys = { :fileUri => name }
119
+ uri = uri("files-api/v2/projects/#{@projectId}/file/last-modified", keys, params).require(:fileUri)
120
+ return get(uri)
121
+ end
122
+
123
+ # Get Translations - /files-api/v2/projects/{projectId}/locales/{localeId}/file/get-translations (POST)
124
+ def translations(locale, file, fileUri, params = nil)
125
+ keys = { :fileUri => fileUri }
126
+ uri = uri("files-api/v2/projects/#{@projectId}/locales/#{locale}/file/get-translations", keys, params).require(:fileUri)
127
+ return post_file_raw(uri, :file => file)
66
128
  end
67
129
 
68
- def import(file, name, type, state, params = nil)
130
+ # Import Translations - /files-api/v2/projects/{projectId}/locales/{localeId}/file/import (POST or PUT)
131
+ def import(locale, file, name, type, state, params = nil)
69
132
  keys = { :fileUri => name, :fileType => type, :translationState => state}
70
- uri = uri(Services::FILE_IMPORT, keys, params).require(:fileUri, :fileType, :locale, :translationState)
133
+ uri = uri("files-api/v2/projects/#{@projectId}/locales/#{locale}/file/import", keys, params).require(:fileUri, :fileType, :translationState)
71
134
  file = ::File.open(file, 'rb') if file.is_a?(String)
72
- return post(uri.to_s, :file => file)
135
+ return post_file(uri, :file => file)
73
136
  end
74
137
  end
75
138
 
@@ -0,0 +1,35 @@
1
+ # Copyright 2016 Smartling, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'smartling/api'
16
+
17
+ module Smartling
18
+
19
+ class Project < Api
20
+
21
+ # List Projects - /accounts-api/v2/accounts/{accountUid}/projects (GET)
22
+ def list(accountUid, params = nil)
23
+ uri = uri('accounts-api/v2/accounts/' + accountUid + '/projects', params)
24
+ return get(uri)
25
+ end
26
+
27
+ # Project Details - /projects-api/v2/projects/{projectId} (GET)
28
+ def details(projectId, params = nil)
29
+ uri = uri('projects-api/v2/projects/' + projectId, params)
30
+ return get(uri)
31
+ end
32
+
33
+ end
34
+ end
35
+
data/lib/smartling/uri.rb CHANGED
@@ -52,7 +52,7 @@ module Smartling
52
52
  params.map {|k,v|
53
53
  if v.respond_to?(:to_ary)
54
54
  v.to_ary.map {|w|
55
- k.to_s + '=' + format_value(w)
55
+ k.to_s + '[]=' + format_value(w)
56
56
  }.join('&')
57
57
  else
58
58
  k.to_s + '=' + format_value(v)
@@ -66,7 +66,7 @@ module Smartling
66
66
  end
67
67
 
68
68
  def format_time(t)
69
- t.utc.strftime('%Y-%m-%dT%H:%M:%S')
69
+ t.utc.iso8601
70
70
  end
71
71
 
72
72
  end
@@ -14,5 +14,5 @@
14
14
 
15
15
  module Smartling
16
16
  # This follows Semantic Versioning http://semver.org/
17
- VERSION = '1.0.1'
17
+ VERSION = '2.0.0'
18
18
  end
data/samples/file_api.rb CHANGED
@@ -21,92 +21,138 @@ def print_msg(msg)
21
21
  puts msg
22
22
  end
23
23
 
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
24
+ # change these values to use those found on the Project Settings -> API page in dashboard
25
+ USER_ID = 'USERID'
26
+ USER_SECRET = 'USERSECRET'
27
+ PROJECT_ID = 'PROJECTID'
26
28
 
27
29
  print_msg "Smartling Ruby client #{Smartling::VERSION}"
28
30
 
29
- # Initialize client to use File API on Sandbox
30
- sl = Smartling::File.sandbox(:apiKey => API_KEY, :projectId => PROJECT_ID)
31
31
 
32
32
  # Initialize client to use File API on Production
33
- #sl = Smartling::File.new(:apiKey => API_KEY, :projectId => PROJECT_ID)
33
+ # To test in a sandbox account, create a new Files SANDBOX project in the Smartling dashboard and use the API key and project ID from that.
34
+ sl = Smartling::File.sandbox(:userId => USER_ID, :userSecret => USER_SECRET, :projectId => PROJECT_ID)
34
35
 
35
36
  # Basic usage
36
37
 
38
+ begin
39
+ print_msg 'Listing all project files...'
40
+ res = sl.list
41
+ p res
42
+ rescue
43
+ end
44
+
37
45
  file = 'data.yaml' # your data file
38
46
  file_uri = 'my_files/data.yaml' # unique identifier given to the uploaded file
39
47
  file_type = 'YAML' # file type
40
48
 
49
+ begin
41
50
  print_msg "Uploading file '#{file}' using file URI '#{file_uri}' and file type '#{file_type}'..."
42
51
  res = sl.upload(file, file_uri, file_type)
43
52
  p res
53
+ rescue
54
+ end
44
55
 
56
+ begin
45
57
  print_msg 'Listing all project files...'
46
58
  res = sl.list
47
59
  p res
60
+ rescue
61
+ end
48
62
 
49
- lang = 'es-ES' # any language that exists in your project
63
+ lang = 'fr-FR' # any language that exists in your project
50
64
  state = 'PUBLISHED' # state at which imported strings are imported as
51
65
 
66
+ begin
52
67
  print_msg "Getting status for file URI '#{file_uri}' and language '#{lang}'..."
53
- res = sl.status(file_uri, :locale => lang)
68
+ res = sl.status(file_uri, lang)
54
69
  p res
70
+ rescue
71
+ end
55
72
 
73
+ begin
56
74
  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)
75
+ res = sl.import(lang, file, file_uri, file_type, state)
76
+ rescue
77
+ end
58
78
 
79
+ begin
59
80
  print_msg "Downloading translations for file URI '#{file_uri}' and language '#{lang}'..."
60
- data = sl.download(file_uri, :locale => lang)
81
+ data = sl.download_translated(file_uri, lang)
61
82
  puts data
83
+ rescue
84
+ end
62
85
 
63
- new_file_uri = 'my_files/new_data.yaml' # new uri to uniquely identify the previously uploaded file
86
+ new_file_uri = 'my_files/newdata.yaml' # new uri to uniquely identify the previously uploaded file
64
87
 
88
+ begin
65
89
  print_msg "Renaming file from '#{file_uri}' to '#{new_file_uri}'..."
66
90
  sl.rename(file_uri, new_file_uri)
91
+ rescue
92
+ end
67
93
 
94
+ begin
68
95
  print_msg "Deleting file '#{new_file_uri}'..."
69
96
  sl.delete(new_file_uri)
97
+ rescue
98
+ end
70
99
 
71
100
  # Extended parameters
72
-
101
+ begin
73
102
  print_msg 'Uploading file with callback URL provided...'
74
103
  res = sl.upload(file, 'name.yaml', 'YAML', :callbackUrl => 'http://yourdomain.com/someservice')
75
104
  p res
105
+ rescue
106
+ end
76
107
 
108
+ begin
77
109
  print_msg 'Uploading file with approved flag provided...'
78
- res = sl.upload(file, 'name.yaml', 'YAML', :approved => true)
110
+ res = sl.upload(file, 'name.yaml', 'YAML', :authorize => true)
79
111
  p res
112
+ rescue
113
+ end
80
114
 
115
+ begin
81
116
  print_msg 'Listing files using URI mask filter...'
82
117
  res = sl.list(:uriMask => '%.yaml')
83
118
  p res
119
+ rescue
120
+ end
84
121
 
122
+ begin
85
123
  print_msg 'Listing files using file type filter...'
86
124
  res = sl.list(:fileTypes => ['yaml', 'ios'])
87
125
  p res
126
+ rescue
127
+ end
88
128
 
89
- print_msg 'Listing files ordered by attributes...'
90
- res = sl.list(:orderBy => ['fileUri', 'wordCount_desc'])
91
- p res
92
-
129
+ begin
93
130
  print_msg 'Listing paginated files...'
94
131
  page, size = 2, 10
95
132
  res = sl.list(:offset => (page - 1) * size, :limit => size)
96
133
  p res
134
+ rescue
135
+ end
97
136
 
137
+ begin
98
138
  print_msg 'Listing files uploaded after a certain date...'
99
- res = sl.list(:lastUploadedAfter => Time.utc(2012, 04, 05))
139
+ res = sl.list(:lastUploadedAfter => Time.utc(2016, 10, 30))
100
140
  p res
141
+ rescue
142
+ end
101
143
 
144
+ begin
102
145
  print_msg 'Listing files uploaded between a date range...'
103
- res = sl.list(:lastUploadedAfter => Time.utc(2012, 04, 01), :lastUploadedBefore => Time.utc(2012, 05, 01))
104
- p res
105
-
106
- print_msg 'Listing files using translation status...'
107
- res = sl.list(:conditions => ['haveAllTranslated', 'haveAtLeastOneUnapproved'])
146
+ res = sl.list(:lastUploadedAfter => Time.utc(2016, 10, 30), :lastUploadedBefore => Time.utc(2016, 11, 10))
108
147
  p res
148
+ rescue
149
+ end
109
150
 
151
+ begin
110
152
  print_msg 'Listing files while combining multiple parameters...'
111
- res = sl.list(:fileTypes => 'yaml', :orderBy => 'fileUri', :offset => 20, :limit => 10)
153
+ res = sl.list(:uriMask => '%.yaml', :fileTypes => [:ios, :yaml],
154
+ :lastUploadedAfter => Time.now - 3600, :lastUploadedBefore => Time.now + 24*3600,
155
+ :offset => 0, :limit => 2)
112
156
  p res
157
+ rescue
158
+ end
data/tests/api_test.rb CHANGED
@@ -17,29 +17,34 @@ $:.unshift File.expand_path('../', __FILE__)
17
17
  require 'test_helper'
18
18
 
19
19
  module SmartlingTests
20
+ class StubResponse
21
+ attr_accessor :code, :body
22
+ end
23
+
20
24
  class SmartlingApiTest < Test::Unit::TestCase
21
25
 
22
26
  def stub_response(code, body)
23
- status = Net::HTTPResponse.new('', code, '')
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
27
+ response = StubResponse.new()
28
+ response.code = code
29
+ response.body = body
30
+ return response
29
31
  end
30
32
 
31
33
  def test_endpoints
34
+ base = 'https://api.smartling.com/'
35
+ sb = 'https://api.stg.smartling.net/'
36
+
32
37
  sl = Smartling::Api.new()
33
- assert_equal(Smartling::Endpoints::CURRENT, sl.baseUrl)
38
+ assert_equal(base, sl.baseUrl)
34
39
 
35
- sl = Smartling::Api.new(:baseUrl => Smartling::Endpoints::V1)
36
- assert_equal(Smartling::Endpoints::V1, sl.baseUrl)
40
+ sl = Smartling::Api.new(:baseUrl => base)
41
+ assert_equal(base, sl.baseUrl)
37
42
 
38
- sl = Smartling::Api.new(:baseUrl => Smartling::Endpoints::SANDBOX)
39
- assert_equal(Smartling::Endpoints::SANDBOX, sl.baseUrl)
43
+ sl = Smartling::Api.new(:baseUrl => sb)
44
+ assert_equal(sb, sl.baseUrl)
40
45
 
41
46
  sl = Smartling::Api.sandbox()
42
- assert_equal(Smartling::Endpoints::SANDBOX, sl.baseUrl)
47
+ assert_equal(sb, sl.baseUrl)
43
48
 
44
49
  sl = Smartling::Api.new(:baseUrl => 'custom')
45
50
  assert_equal('custom', sl.baseUrl)
@@ -63,10 +68,10 @@ module SmartlingTests
63
68
  res = stub_response(200, '{"response":{"code":"SUCCESS", "data":"foo"}}')
64
69
  assert_equal('foo', sl.process(res))
65
70
 
66
- res = stub_response(200, '{"response":{"code":"ERROR", "messages":[]}}')
71
+ res = stub_response(200, '{"response":{"code":"ERROR", "errors":[]}}')
67
72
  assert_raise RuntimeError do sl.process(res) end
68
73
 
69
- res = stub_response(500, '{"response":{"code":"ERROR", "messages":[]}}')
74
+ res = stub_response(500, '{"response":{"code":"ERROR", "errors":[]}}')
70
75
  assert_raise RuntimeError do sl.process(res) end
71
76
 
72
77
  res = stub_response(500, '{"response":{"code":"ERROR"}}')
@@ -77,7 +77,7 @@ we have: cookies
77
77
 
78
78
  res = nil
79
79
  assert_nothing_raised do
80
- res = sl.status(TEST_FILE_YAML, :locale => 'en-US')
80
+ res = sl.status_all(TEST_FILE_YAML)
81
81
  end
82
82
  @log.debug res.inspect
83
83
  end
@@ -88,18 +88,18 @@ we have: cookies
88
88
 
89
89
  res = nil
90
90
  assert_nothing_raised do
91
- res = sl.download(TEST_FILE_YAML, :locale => 'en-US')
91
+ res = sl.download_translated(TEST_FILE_YAML, 'en-US')
92
92
  end
93
93
  @log.debug res.inspect
94
94
  end
95
95
 
96
96
  def test_5_download_ru
97
- @log.debug '-> FileAPI:download RU'
97
+ @log.debug '-> FileAPI:download FR'
98
98
  sl = Smartling::File.new(@config)
99
99
 
100
100
  res = nil
101
101
  assert_nothing_raised do
102
- res = sl.download(TEST_FILE_YAML, :locale => 'ru-RU')
102
+ res = sl.download_translated(TEST_FILE_YAML, 'fr-FR')
103
103
  end
104
104
  @log.debug res.inspect
105
105
  end
@@ -120,15 +120,13 @@ we have: cookies
120
120
 
121
121
  @log.debug '-> FileAPI UTF-16 download EN'
122
122
  assert_nothing_raised do
123
- res = sl.download(TEST_FILE_UTF16, :locale => 'en-US')
123
+ res = sl.download(TEST_FILE_UTF16)
124
124
  end
125
125
  @log.debug res.inspect
126
126
 
127
- assert_equal(YAML.load(data), YAML.load(res))
128
-
129
- @log.debug '-> FileAPI UTF-16 download RU'
127
+ @log.debug '-> FileAPI UTF-16 download FR'
130
128
  assert_nothing_raised do
131
- res = sl.download(TEST_FILE_UTF16, :locale => 'ru-RU')
129
+ res = sl.download_translated(TEST_FILE_UTF16, 'fr-FR')
132
130
  end
133
131
  @log.debug res.inspect
134
132
  end
@@ -138,7 +136,7 @@ we have: cookies
138
136
  sl = Smartling::File.new(@config)
139
137
  res = nil
140
138
  assert_nothing_raised do
141
- res = sl.list(:locale => 'ru-RU', :uriMask => '%.yaml', :fileTypes => [:ios, :yaml],
139
+ res = sl.list(:uriMask => '%.yaml', :fileTypes => [:ios, :yaml],
142
140
  :lastUploadedAfter => Time.now - 3600, :lastUploadedBefore => Time.now + 24*3600,
143
141
  :offset => 0, :limit => 2)
144
142
  end
data/tests/test_helper.rb CHANGED
@@ -18,6 +18,7 @@ require 'logger'
18
18
  require 'smartling'
19
19
  require 'test/unit'
20
20
  require 'yaml'
21
+ require 'json'
21
22
 
22
23
  class Hash
23
24
  def keysym!
data/tests/uri_test.rb CHANGED
@@ -42,23 +42,23 @@ module SmartlingTests
42
42
 
43
43
  uri = Smartling::Uri.new('http://hello.wo/')
44
44
  uri.params = {:foo => Time.utc(2012, 04, 05, 11, 19, 59)}
45
- assert_equal('http://hello.wo/?foo=2012-04-05T11:19:59', uri.to_s)
45
+ assert_equal('http://hello.wo/?foo=2012-04-05T11:19:59Z', uri.to_s)
46
46
 
47
47
  uri = Smartling::Uri.new('http://hello.wo/')
48
48
  uri.params = {:foo => Time.utc(2012, 04, 05, 11, 49, 17).localtime}
49
- assert_equal('http://hello.wo/?foo=2012-04-05T11:49:17', uri.to_s)
49
+ assert_equal('http://hello.wo/?foo=2012-04-05T11:49:17Z', uri.to_s)
50
50
 
51
51
  uri = Smartling::Uri.new('http://hello.wo/')
52
52
  uri.params = {:foo => ['hello']}
53
- assert_equal('http://hello.wo/?foo=hello', uri.to_s)
53
+ assert_equal('http://hello.wo/?foo[]=hello', uri.to_s)
54
54
 
55
55
  uri = Smartling::Uri.new('http://hello.wo/')
56
56
  uri.params = {:foo => ['hello', 'world']}
57
- assert_equal('http://hello.wo/?foo=hello&foo=world', uri.to_s)
57
+ assert_equal('http://hello.wo/?foo[]=hello&foo[]=world', uri.to_s)
58
58
 
59
59
  uri = Smartling::Uri.new('http://hello.wo/')
60
60
  uri.params = {:foo => ['hello', 'world', 'of', Time.utc(2012)]}
61
- assert_equal('http://hello.wo/?foo=hello&foo=world&foo=of&foo=2012-01-01T00:00:00', uri.to_s)
61
+ assert_equal('http://hello.wo/?foo[]=hello&foo[]=world&foo[]=of&foo[]=2012-01-01T00:00:00Z', uri.to_s)
62
62
  end
63
63
 
64
64
  def test_require
@@ -90,7 +90,7 @@ module SmartlingTests
90
90
  def test_encode
91
91
  uri = Smartling::Uri.new('http://hello.wo/')
92
92
  uri.params = {:foo => ['hello & world!']}
93
- assert_equal('http://hello.wo/?foo=hello%20%26%20world%21', uri.to_s)
93
+ assert_equal('http://hello.wo/?foo[]=hello%20%26%20world%21', uri.to_s)
94
94
  end
95
95
 
96
96
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartling
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Pavel Ivashkov
7
+ - Emilien Huet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-02 00:00:00.000000000 Z
11
+ date: 2016-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rest-client
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.6'
33
+ version: '2.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.6'
40
+ version: '2.0'
41
41
  description: A Ruby library to utilize Smartling services
42
42
  email:
43
43
  - hi@smartling.com
@@ -50,6 +50,7 @@ files:
50
50
  - lib/smartling.rb
51
51
  - lib/smartling/api.rb
52
52
  - lib/smartling/fileapi.rb
53
+ - lib/smartling/projectapi.rb
53
54
  - lib/smartling/uri.rb
54
55
  - lib/smartling/version.rb
55
56
  - samples/data.yaml
@@ -69,23 +70,23 @@ require_paths:
69
70
  - lib
70
71
  required_ruby_version: !ruby/object:Gem::Requirement
71
72
  requirements:
72
- - - ! '>='
73
+ - - ">="
73
74
  - !ruby/object:Gem::Version
74
- version: 1.8.6
75
+ version: '2.1'
75
76
  required_rubygems_version: !ruby/object:Gem::Requirement
76
77
  requirements:
77
- - - ! '>='
78
+ - - ">="
78
79
  - !ruby/object:Gem::Version
79
80
  version: '0'
80
81
  requirements: []
81
82
  rubyforge_project:
82
- rubygems_version: 2.4.5
83
+ rubygems_version: 2.6.6
83
84
  signing_key:
84
85
  specification_version: 4
85
86
  summary: Smartling SDK
86
87
  test_files:
87
- - tests/test_helper.rb
88
88
  - tests/uri_test.rb
89
- - tests/api_test.rb
90
89
  - tests/config.sample
90
+ - tests/api_test.rb
91
+ - tests/test_helper.rb
91
92
  - tests/srv_fileapi_test.rb