smartling 2.0.1 → 2.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17b29c43e1f75b0cc74c0e6445e3e085f9bcda80
4
- data.tar.gz: ce17a7a56792b0fce91742bb34f838f4d170ddf1
3
+ metadata.gz: 9dd1f6fbb39ef6828a38ac1837d08b4f40b4bba2
4
+ data.tar.gz: 0eadeae82917238c1646c112b58476a1fbf57333
5
5
  SHA512:
6
- metadata.gz: 72ff5936615bd36fddfc77bf653c843558c25838bff9148cd53783de39461ef54760ef2f0eeef4e6da9fdc8f1d8c03c1ebaddabe6cbc5403f0cfa6b4b98994d6
7
- data.tar.gz: 2d8ec564d206f8c72f9852e6caac474a739730dea453d9cd0a4a9dcca37a25b2310ecc5afa8df2f193ced159d272893e42b7fb05cc2a0475977bf468caa184b0
6
+ metadata.gz: 33d0bfd1ad76fce5d7b5fe54ff1701436886d57c5c6809f301d725dde72de87c4dc36ea2e33f642365c219fcf55b6820fb4e7429d746b2c4e3023f3fbca6e54c
7
+ data.tar.gz: 1a2d5d7250d7106a9f9d23869406a82c85d8e1957571a967b87a592e5abff6cf378ffd845fa95410101fd7d3d613a6f27a9f8f0c123e5df2fd33b2d79ba43a62
@@ -15,16 +15,16 @@
15
15
  require 'rest-client'
16
16
  require 'multi_json'
17
17
  require 'smartling/uri'
18
- require 'json'
18
+ require 'oj'
19
19
 
20
20
  module Smartling
21
21
 
22
22
  module Endpoints
23
23
  CURRENT = 'https://api.smartling.com/'
24
- SANDBOX = 'https://api.stg.smartling.net/'
25
24
  end
26
25
 
27
26
  class Api
27
+ EXPIRATION_OFFSET = 60
28
28
  attr_accessor :baseUrl, :prefix
29
29
 
30
30
  def initialize(args = {})
@@ -33,10 +33,6 @@ module Smartling
33
33
  @baseUrl = args[:baseUrl] || Endpoints::CURRENT
34
34
  end
35
35
 
36
- def self.sandbox(args = {})
37
- new(args.merge(:baseUrl => Endpoints::SANDBOX))
38
- end
39
-
40
36
  def uri(path, params1 = nil, params2 = nil)
41
37
  uri = Uri.new(@baseUrl, path)
42
38
  params = {}
@@ -48,19 +44,19 @@ module Smartling
48
44
 
49
45
  def check_response(res)
50
46
  return if res.code == 200
51
- format_api_error(res.body)
47
+ format_api_error(res)
52
48
  raise 'API_ERROR'
53
49
  end
54
50
 
55
51
  def process(res)
56
52
  check_response(res)
57
- body = MultiJson.decode(res.body)
53
+ body = MultiJson.load(res.body)
58
54
  if body['response']
59
55
  body = body['response']
60
56
  if body['code'] == 'SUCCESS'
61
57
  return body['data']
62
58
  else
63
- format_api_error(res.body)
59
+ format_api_error(res)
64
60
  raise 'API_ERROR'
65
61
  end
66
62
  end
@@ -70,7 +66,7 @@ module Smartling
70
66
 
71
67
  def format_api_error(res)
72
68
  begin
73
- body = MultiJson.decode(res.body)
69
+ body = MultiJson.load(res.body)
74
70
  rescue
75
71
  end
76
72
 
@@ -110,7 +106,7 @@ module Smartling
110
106
  call(uri, :get, true, false, true)
111
107
  end
112
108
  def post(uri, params = nil)
113
- call(uri, :post, true, false, false, params.to_json)
109
+ call(uri, :post, true, false, false, MultiJson.dump(params))
114
110
  end
115
111
  def post_file(uri, params = nil)
116
112
  call(uri, :post, true, true, false, params)
@@ -137,9 +133,9 @@ module Smartling
137
133
  def process_auth(response)
138
134
  now = Time.new.to_i
139
135
  @token = response['accessToken']
140
- @token_expiration = now + response['expiresIn'].to_i
136
+ @token_expiration = now + response['expiresIn'].to_i - EXPIRATION_OFFSET
141
137
  @refresh = response['refreshToken']
142
- @refresh_expiration = now + response['refreshExpiresIn'].to_i
138
+ @refresh_expiration = now + response['refreshExpiresIn'].to_i - EXPIRATION_OFFSET
143
139
  end
144
140
 
145
141
  # Authenticate - /auth-api/v2/authenticate (POST)
@@ -156,7 +152,7 @@ module Smartling
156
152
 
157
153
  # Otherwise call authenticate endpoint
158
154
  uri = uri('auth-api/v2/authenticate', {}, {})
159
- RestClient.post(uri.to_s, {:userIdentifier => @userId, :userSecret => @userSecret}.to_json, {:content_type => :json, :accept => :json}) {|res, _, _|
155
+ RestClient.post(uri.to_s, MultiJson.dump({:userIdentifier => @userId, :userSecret => @userSecret}), {:content_type => :json, :accept => :json}) {|res, _, _|
160
156
  process_auth(process(res))
161
157
  return @token
162
158
  }
@@ -165,7 +161,7 @@ module Smartling
165
161
  # Refresh Authentication - /auth-api/v2/authenticate/refresh (POST)
166
162
  def refresh()
167
163
  uri = uri('auth-api/v2/authenticate/refresh', {}, {})
168
- RestClient.post(uri.to_s, {:refreshToken => @refreshToken}.to_json, {:content_type => :json, :accept => :json}) {|res, _, _|
164
+ RestClient.post(uri.to_s, MultiJson.dump({:refreshToken => @refresh}), {:content_type => :json, :accept => :json}) {|res, _, _|
169
165
  process_auth(process(res))
170
166
  return @token
171
167
  }
@@ -14,5 +14,5 @@
14
14
 
15
15
  module Smartling
16
16
  # This follows Semantic Versioning http://semver.org/
17
- VERSION = '2.0.1'
17
+ VERSION = '2.0.3'
18
18
  end
@@ -30,129 +30,128 @@ print_msg "Smartling Ruby client #{Smartling::VERSION}"
30
30
 
31
31
 
32
32
  # Initialize client to use File API on Production
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)
33
+ sl = Smartling::File.new(:userId => USER_ID, :userSecret => USER_SECRET, :projectId => PROJECT_ID)
35
34
 
36
35
  # Basic usage
37
36
 
38
- begin
37
+ # begin
39
38
  print_msg 'Listing all project files...'
40
39
  res = sl.list
41
40
  p res
42
- rescue
43
- end
41
+ # rescue
42
+ # end
44
43
 
45
44
  file = 'data.yaml' # your data file
46
45
  file_uri = 'my_files/data.yaml' # unique identifier given to the uploaded file
47
46
  file_type = 'YAML' # file type
48
47
 
49
- begin
48
+ # begin
50
49
  print_msg "Uploading file '#{file}' using file URI '#{file_uri}' and file type '#{file_type}'..."
51
50
  res = sl.upload(file, file_uri, file_type)
52
51
  p res
53
- rescue
54
- end
52
+ # rescue
53
+ # end
55
54
 
56
- begin
55
+ # begin
57
56
  print_msg 'Listing all project files...'
58
57
  res = sl.list
59
58
  p res
60
- rescue
61
- end
59
+ # rescue
60
+ # end
62
61
 
63
62
  lang = 'fr-FR' # any language that exists in your project
64
63
  state = 'PUBLISHED' # state at which imported strings are imported as
65
64
 
66
- begin
65
+ # begin
67
66
  print_msg "Getting status for file URI '#{file_uri}' and language '#{lang}'..."
68
67
  res = sl.status(file_uri, lang)
69
68
  p res
70
- rescue
71
- end
69
+ # rescue
70
+ # end
72
71
 
73
- begin
72
+ # begin
74
73
  print_msg "Importing translation file '#{file}' using file URI '#{file_uri}' and file type '#{file_type}' and language '#{lang}' as '#{state}'..."
75
74
  res = sl.import(lang, file, file_uri, file_type, state)
76
- rescue
77
- end
75
+ # rescue
76
+ # end
78
77
 
79
- begin
78
+ # begin
80
79
  print_msg "Downloading translations for file URI '#{file_uri}' and language '#{lang}'..."
81
80
  data = sl.download_translated(file_uri, lang)
82
81
  puts data
83
- rescue
84
- end
82
+ # rescue
83
+ # end
85
84
 
86
85
  new_file_uri = 'my_files/newdata.yaml' # new uri to uniquely identify the previously uploaded file
87
86
 
88
- begin
87
+ # begin
89
88
  print_msg "Renaming file from '#{file_uri}' to '#{new_file_uri}'..."
90
89
  sl.rename(file_uri, new_file_uri)
91
- rescue
92
- end
90
+ # rescue
91
+ # end
93
92
 
94
- begin
93
+ # begin
95
94
  print_msg "Deleting file '#{new_file_uri}'..."
96
95
  sl.delete(new_file_uri)
97
- rescue
98
- end
96
+ # rescue
97
+ # end
99
98
 
100
99
  # Extended parameters
101
- begin
100
+ # begin
102
101
  print_msg 'Uploading file with callback URL provided...'
103
102
  res = sl.upload(file, 'name.yaml', 'YAML', :callbackUrl => 'http://yourdomain.com/someservice')
104
103
  p res
105
- rescue
106
- end
104
+ # rescue
105
+ # end
107
106
 
108
- begin
107
+ # begin
109
108
  print_msg 'Uploading file with approved flag provided...'
110
109
  res = sl.upload(file, 'name.yaml', 'YAML', :authorize => true)
111
110
  p res
112
- rescue
113
- end
111
+ # rescue
112
+ # end
114
113
 
115
- begin
114
+ # begin
116
115
  print_msg 'Listing files using URI mask filter...'
117
116
  res = sl.list(:uriMask => '%.yaml')
118
117
  p res
119
- rescue
120
- end
118
+ # rescue
119
+ # end
121
120
 
122
- begin
121
+ # begin
123
122
  print_msg 'Listing files using file type filter...'
124
123
  res = sl.list(:fileTypes => ['yaml', 'ios'])
125
124
  p res
126
- rescue
127
- end
125
+ # rescue
126
+ # end
128
127
 
129
- begin
128
+ # begin
130
129
  print_msg 'Listing paginated files...'
131
130
  page, size = 2, 10
132
131
  res = sl.list(:offset => (page - 1) * size, :limit => size)
133
132
  p res
134
- rescue
135
- end
133
+ # rescue
134
+ # end
136
135
 
137
- begin
136
+ # begin
138
137
  print_msg 'Listing files uploaded after a certain date...'
139
138
  res = sl.list(:lastUploadedAfter => Time.utc(2016, 10, 30))
140
139
  p res
141
- rescue
142
- end
140
+ # rescue
141
+ # end
143
142
 
144
- begin
143
+ # begin
145
144
  print_msg 'Listing files uploaded between a date range...'
146
145
  res = sl.list(:lastUploadedAfter => Time.utc(2016, 10, 30), :lastUploadedBefore => Time.utc(2016, 11, 10))
147
146
  p res
148
- rescue
149
- end
147
+ # rescue
148
+ # end
150
149
 
151
- begin
150
+ # begin
152
151
  print_msg 'Listing files while combining multiple parameters...'
153
152
  res = sl.list(:uriMask => '%.yaml', :fileTypes => [:ios, :yaml],
154
153
  :lastUploadedAfter => Time.now - 3600, :lastUploadedBefore => Time.now + 24*3600,
155
154
  :offset => 0, :limit => 2)
156
155
  p res
157
- rescue
158
- end
156
+ # rescue
157
+ # end
@@ -32,7 +32,7 @@ module SmartlingTests
32
32
 
33
33
  def test_endpoints
34
34
  base = 'https://api.smartling.com/'
35
- sb = 'https://api.stg.smartling.net/'
35
+ sb = 'https://api.test.smartling.net/'
36
36
 
37
37
  sl = Smartling::Api.new()
38
38
  assert_equal(base, sl.baseUrl)
@@ -43,9 +43,6 @@ module SmartlingTests
43
43
  sl = Smartling::Api.new(:baseUrl => sb)
44
44
  assert_equal(sb, sl.baseUrl)
45
45
 
46
- sl = Smartling::Api.sandbox()
47
- assert_equal(sb, sl.baseUrl)
48
-
49
46
  sl = Smartling::Api.new(:baseUrl => 'custom')
50
47
  assert_equal('custom', sl.baseUrl)
51
48
  end
@@ -1,6 +1,6 @@
1
1
  loglevel: 2 # DEBUG = 0, WARN = 2
2
2
  server:
3
- baseUrl: https://sandbox-api.smartling.com/v1/
3
+ baseUrl: https://api.stg.smartling.net/
4
4
  apiKey: key
5
5
  projectId: id
6
6
 
@@ -141,8 +141,6 @@ we have: cookies
141
141
  :offset => 0, :limit => 2)
142
142
  end
143
143
  @log.debug res.inspect
144
- # FIXME: when sandbox adds support for filter parameters
145
- assert(res['fileCount'] <= 2) unless sl.baseUrl == Smartling::Endpoints::SANDBOX
146
144
  end
147
145
 
148
146
  def test_8_rename
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartling
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emilien Huet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-23 00:00:00.000000000 Z
11
+ date: 2017-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: json
14
+ name: oj
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.0'
19
+ version: '3.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
- version: '2.0'
26
+ version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: multi_json
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -86,7 +86,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '2.1'
89
+ version: 2.1.9
90
90
  required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  requirements:
92
92
  - - ">="
@@ -94,13 +94,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  version: '0'
95
95
  requirements: []
96
96
  rubyforge_project:
97
- rubygems_version: 2.6.6
97
+ rubygems_version: 2.6.11
98
98
  signing_key:
99
99
  specification_version: 4
100
100
  summary: Smartling SDK
101
101
  test_files:
102
102
  - tests/uri_test.rb
103
103
  - tests/config.sample
104
- - tests/api_test.rb
105
104
  - tests/test_helper.rb
106
105
  - tests/srv_fileapi_test.rb
106
+ - tests/api_test.rb