smartring 0.0.1 → 0.0.2

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
  SHA256:
3
- metadata.gz: 1ff999e9fccd2e5dc5ef5fb4708f55ea6b0a5d35a1fd3fb8e4133aa1e6691a5e
4
- data.tar.gz: c8f983c46d6ce9d8d8174d75406b262ba1584186ee7ceef07407c4e0111ef8cf
3
+ metadata.gz: 837a79f27bba855d63ff0055ef98af9f3b065c09f4d9172a8107af31a15fde77
4
+ data.tar.gz: 5afc964127b1f19de3c0c8462e854c98e24a6df02a4341625ef94b4ee5204bfe
5
5
  SHA512:
6
- metadata.gz: 5d890e27264dbaedbefada0a2d2da93afbb39e37905599fe415c3a07a5a6936bd0bf4d3e930bcc0c17cbd7a012c7c3249bb0a7e6cbd26a61a07d4cc46e2166c1
7
- data.tar.gz: 3a05050cde3198f794953b226ab3554e78c082e555f9b4ed83c223fce44abc7209e2f4a38a4a89968dab316fad39cfc961487e1bf8d8198d91d09dd538bc7beb
6
+ metadata.gz: a6aa2a8fb795346e6e4bad8b49737bc2e4b09af53ab6668b71f32818e061415c882767a94f5807bc83094b82e11f6ec8e299f42c76d8503a85df232411fa61c8
7
+ data.tar.gz: 4cabd64289c24452b2365045d4b3a0d286086c8a4725ba6032e44f0fd37d45d10d0177ac0485e354971f851cab944261b96a5eec32d14f5cb08e183795aed04f
@@ -11,7 +11,12 @@ module Smartling
11
11
  get(path)
12
12
  end
13
13
 
14
- def file(project_id: @project_id, file_uri:, locale: nil)
14
+ def file_types(project_id: @project_id)
15
+ path = "/files-api/v2/projects/#{project_id}/file-types"
16
+ get(path)
17
+ end
18
+
19
+ def file_status(project_id: @project_id, file_uri:, locale: nil)
15
20
  path = ["/files-api/v2/projects/#{project_id}"]
16
21
  path << "locales/#{locale}" unless locale.nil?
17
22
  path << 'file/status'
@@ -19,11 +24,39 @@ module Smartling
19
24
  get(path, query: { fileUri: file_uri })
20
25
  end
21
26
 
27
+ alias file file_status
28
+
29
+ def download_original_file(project_id: @project_id, file_uri:)
30
+ path = "/files-api/v2/projects/#{project_id}/file"
31
+ get(path, query: { fileUri: file_uri })
32
+ end
33
+
34
+ def download_translated_file(project_id: @project_id, file_uri:, locale:,
35
+ retrieval_type: nil, include_original: nil)
36
+ path = "/files-api/v2/projects/#{project_id}/locales/#{locale}/file"
37
+ query = { fileUri: file_uri }
38
+ query[:retrievalType] = retrieval_type unless retrieval_type.nil?
39
+ query[:includeOriginalStrings] = true if include_original
40
+ get(path, query: query)
41
+ end
42
+
43
+ def download_file(project_id: @project_id, file_uri:, locale: nil)
44
+ return download_translated_file(project_id: project_id,
45
+ file_uri: file_uri,
46
+ locale: locale) unless locale.nil?
47
+ download_original_file(project_id: project_id, file_uri: file_uri)
48
+ end
49
+
22
50
  def delete_file(project_id: @project_id, file_uri:)
23
51
  path = "/files-api/v2/projects/#{project_id}/file/delete"
24
52
  post(path, body: { fileUri: file_uri })
25
53
  end
26
54
 
55
+ def rename_file(project_id: @project_id, file_uri:, new_file_uri:)
56
+ path = "/files-api/v2/projects/#{project_id}/file/rename"
57
+ post(path, body: { fileUri: file_uri, newFileUri: new_file_uri })
58
+ end
59
+
27
60
  def upload_file(project_id: @project_id, file:, file_uri:, file_type:,
28
61
  callback: nil, authorize: nil, locales_to_authorize: nil,
29
62
  smartling: {})
@@ -39,6 +72,39 @@ module Smartling
39
72
  post(path, body: body)
40
73
  end
41
74
 
75
+ def import_translations(project_id: @project_id, file_uri:, locale:,
76
+ file:, file_type:, translation_state: nil,
77
+ overwrite: nil)
78
+ raise(InvalidFile, file) unless Files.valid_file?(file)
79
+ path = "/files-api/v2/projects/#{project_id}/locales/#{locale}/file/import"
80
+ body = { file: file, fileUri: file_uri, fileType: file_type }
81
+ body[:translationState] = translation_state unless translation_state.nil?
82
+ body[:overwrite] = overwrite unless overwrite.nil?
83
+ post(path, body: body)
84
+ end
85
+
86
+ def translate_file(project_id: @project_id, file_uri:, locale:, file:,
87
+ file_type:, retrieval_type: nil,
88
+ include_original_strings: nil)
89
+ raise(InvalidFile, file) unless Files.valid_file?(file)
90
+ path = "/files-api/v2/projects/#{project_id}/locales/#{locale}/file/get-translations"
91
+ body = { file: file, fileUri: file_uri, fileType: file_type }
92
+ body[:retrievalType] = retrieval_type unless retrieval_type.nil?
93
+ body[:includeOriginalStrings] = include_original_strings unless include_original_strings.nil?
94
+ post(path, body: body)
95
+ end
96
+
97
+ def file_last_modified(project_id: @project_id, file_uri:, locale: nil,
98
+ since: nil)
99
+ path = ["/files-api/v2/projects/#{project_id}"]
100
+ path << "locales/#{locale}" unless locale.nil?
101
+ path << 'file/last-modified'
102
+ path = path.join('/')
103
+ query = { fileUri: file_uri }
104
+ query[:lastModifiedAfter] = since.to_s.iso8601 unless since.nil?
105
+ get(path, query: query)
106
+ end
107
+
42
108
  InvalidFile = Class.new(ArgumentError)
43
109
 
44
110
  def self.valid_file?(content)
@@ -19,18 +19,87 @@ describe Smartling::Files do
19
19
  end
20
20
  end
21
21
 
22
- describe 'file' do
22
+ describe 'file_types' do
23
+ it 'lists file types' do
24
+ smartling.expect(:get, nil) do |path|
25
+ assert_match %r{files-api/v2/projects/1/file-types$}, path
26
+ end
27
+ smartling.file_types(project_id: 1)
28
+ end
29
+ end
30
+
31
+ describe 'file_status' do
23
32
  it 'gets the /file/status endpoint with the right param' do
24
33
  smartling.expect(:get, nil) do |path, query:|
25
34
  assert_match %r{files-api/v2/projects/1/file/status$}, path
26
35
  assert_equal({ fileUri: 'x' }, query)
27
36
  end
28
- smartling.file(project_id: 1, file_uri: 'x')
37
+ smartling.file_status(project_id: 1, file_uri: 'x')
38
+ end
39
+ end
40
+
41
+ describe 'download_file with no locale' do
42
+ it 'gets /file with the right param' do
43
+ smartling.expect(:get, nil) do |path, query:|
44
+ assert_match %r{files-api/v2/projects/1/file$}, path
45
+ assert_equal({ fileUri: 'x' }, query)
46
+ end
47
+ smartling.download_file(project_id: 1, file_uri: 'x')
48
+ end
49
+ end
50
+
51
+ describe 'download_original_file' do
52
+ it 'gets /file with the right param' do
53
+ smartling.expect(:get, nil) do |path, query:|
54
+ assert_match %r{files-api/v2/projects/1/file$}, path
55
+ assert_equal({ fileUri: 'x' }, query)
56
+ end
57
+ smartling.download_original_file(project_id: 1, file_uri: 'x')
58
+ end
59
+ end
60
+
61
+ describe 'download_file with a locale' do
62
+ it 'gets /locales/<locale>/file with the right param' do
63
+ smartling.expect(:get, nil) do |path, query:|
64
+ assert_match %r{files-api/v2/projects/1/locales/es/file$}, path
65
+ assert_equal({ fileUri: 'x' }, query)
66
+ end
67
+ smartling.download_file(project_id: 1, file_uri: 'x', locale: 'es')
68
+ end
69
+ end
70
+
71
+ describe 'download_translated_file' do
72
+ it 'gets /locales/x/file with the right param' do
73
+ smartling.expect(:get, nil) do |path, query:|
74
+ assert_match %r{files-api/v2/projects/1/locales/es/file$}, path
75
+ assert_equal({ fileUri: 'x' }, query)
76
+ end
77
+ smartling.download_translated_file(project_id: 1, file_uri: 'x', locale: 'es')
78
+ end
79
+ end
80
+
81
+ describe 'file_last_modified (without locale)' do
82
+ it 'gets /file/last-modified with the right param' do
83
+ smartling.expect(:get, nil) do |path, query:|
84
+ assert_match %r{files-api/v2/projects/1/file/last-modified$}, path
85
+ assert_equal({ fileUri: 'x' }, query)
86
+ end
87
+ smartling.file_last_modified(project_id: 1, file_uri: 'x')
88
+ end
89
+ end
90
+
91
+ describe 'file_last_modified (with locale)' do
92
+ it 'gets /locales/x/file/last-modified with the right param' do
93
+ smartling.expect(:get, nil) do |path, query:|
94
+ assert_match %r{files-api/v2/projects/1/locales/es/file/last-modified$}, path
95
+ assert_equal({ fileUri: 'x' }, query)
96
+ end
97
+ smartling.file_last_modified(project_id: 1, file_uri: 'x', locale: 'es')
29
98
  end
30
99
  end
31
100
 
32
101
  describe 'file with locale' do
33
- it 'gets the /locale/x/file/status endpoint with the right params' do
102
+ it 'gets the /locales/x/file/status endpoint with the right params' do
34
103
  smartling.expect(:get, nil) do |path, query:|
35
104
  assert_match %r{files-api/v2/projects/1/locales/es/file/status$}, path
36
105
  assert_equal({ fileUri: 'x' }, query)
@@ -49,6 +118,16 @@ describe Smartling::Files do
49
118
  end
50
119
  end
51
120
 
121
+ describe 'rename_file' do
122
+ it 'posts the right body to the right endpoint' do
123
+ smartling.expect(:post, nil) do |path, body:|
124
+ assert_match %r{files-api/v2/projects/1/file/rename$}, path,
125
+ assert_equal({ fileUri: 'x', newFileUri: 'y' }, body)
126
+ end
127
+ smartling.rename_file(project_id: 1, file_uri: 'x', new_file_uri: 'y')
128
+ end
129
+ end
130
+
52
131
  describe 'upload_file' do
53
132
  it 'posts the right body to the right endpoint' do
54
133
  smartling.expect(:post, nil) do |path, body:|
@@ -75,4 +154,34 @@ describe Smartling::Files do
75
154
  end
76
155
  end
77
156
  end
157
+
158
+ describe 'import_translations' do
159
+ it 'posts the right body to the right endpoint' do
160
+ smartling.expect(:post, nil) do |path, body:|
161
+ assert_equal '/files-api/v2/projects/1/locales/es/file/import', path
162
+ assert_equal 'x', body.fetch(:fileUri)
163
+ assert_equal 'json', body.fetch(:fileType)
164
+ assert_equal '"hello"', body.fetch(:file).read
165
+ assert_equal 'application/json', body.fetch(:file).content_type
166
+ end
167
+ file = UploadIO.new(StringIO.new('"hello"'), 'application/json')
168
+ smartling.import_translations(project_id: 1, file: file, file_uri: 'x',
169
+ file_type: 'json', locale: 'es')
170
+ end
171
+ end
172
+
173
+ describe 'translate_file' do
174
+ it 'posts the right body to the right endpoint' do
175
+ smartling.expect(:post, nil) do |path, body:|
176
+ assert_equal '/files-api/v2/projects/1/locales/es/file/get-translations', path
177
+ assert_equal 'x', body.fetch(:fileUri)
178
+ assert_equal 'json', body.fetch(:fileType)
179
+ assert_equal '"hello"', body.fetch(:file).read
180
+ assert_equal 'application/json', body.fetch(:file).content_type
181
+ end
182
+ file = UploadIO.new(StringIO.new('"hello"'), 'application/json')
183
+ smartling.translate_file(project_id: 1, file: file, file_uri: 'x',
184
+ file_type: 'json', locale: 'es')
185
+ end
186
+ end
78
187
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartring
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - JJ Buckley
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-16 00:00:00.000000000 Z
11
+ date: 2018-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv