Skip to content

Commit 65db494

Browse files
authored
feat: Add the 'Download File Preview' API support (#98)
1 parent 7b541e3 commit 65db494

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/crowdin-api/api_resources/source_files.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,22 @@ def download_file(file_id = nil, destination = nil, project_id = config.project_
267267
Web::SendRequest.new(request, destination).perform
268268
end
269269

270+
# @param file_id [Integer] File ID
271+
# @param destination [String] Destination of File
272+
# * {https://developer.crowdin.com/api/v2/#operation/api.projects.files.preview.get API Documentation}
273+
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.files.preview.get Enterprise API Documentation}
274+
def download_file_preview(file_id = nil, destination = nil, project_id = config.project_id)
275+
file_id || raise_parameter_is_required_error(:file_id)
276+
project_id || raise_project_id_is_required_error
277+
278+
request = Web::Request.new(
279+
connection,
280+
:get,
281+
"#{config.target_api_url}/projects/#{project_id}/files/#{file_id}/preview"
282+
)
283+
Web::SendRequest.new(request, destination).perform
284+
end
285+
270286
# @param query [Hash] Request Body
271287
# @param file_id [Integer] File ID
272288
# * {https://developer.crowdin.com/api/v2/#operation/api.projects.files.revisions.getMany API Documentation}

spec/api_resources/source_files_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@
160160
end
161161
end
162162

163+
describe '#download_file_preview' do
164+
let(:file_id) { 1 }
165+
166+
it 'when request are valid', :default do
167+
stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/files/#{file_id}/preview")
168+
download_file_preview = @crowdin.download_file_preview(file_id, nil, project_id)
169+
expect(download_file_preview).to eq(200)
170+
end
171+
end
172+
163173
describe '#list_file_revisions' do
164174
let(:file_id) { 1 }
165175

0 commit comments

Comments
 (0)