Skip to content

Commit

Permalink
Implement project document add end-point
Browse files Browse the repository at this point in the history
  • Loading branch information
İsmail Akbudak committed Mar 12, 2018
1 parent d952903 commit 6b1a713
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
9 changes: 8 additions & 1 deletion examples/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@

# Post add target language to project
puts project.add_language(PROJECT_ID, 'de')
puts project.add_language(PROJECT_ID, 'it')
puts project.add_language(PROJECT_ID, 'it')

# Post add document to project
puts project.add_document(
PROJECT_ID,
files_model: [{ externalId: 'test1' }, { externalId: 'test2' }],
files: %w[files/Test.txt files/Test-2.txt]
)
2 changes: 1 addition & 1 deletion lib/smartcat_sdk/rest/base_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def prepare_request(method, path, params: {}, headers: {})
request_path = @config.host
request_path += "/api/integration/v1/#{path}"
uri = URI.parse(request_path)
uri.query = URI.encode_www_form(params) if %w[get delete post_multipart].include?(method.to_s)
uri.query = URI.encode_www_form(params) if %w[get delete].include?(method.to_s)
request = SmartcatSDK::Util::Request.prepare(headers, method, params, uri)
request.basic_auth(@user, @password)
connect_and_send(request)
Expand Down
9 changes: 9 additions & 0 deletions lib/smartcat_sdk/rest/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ def add_language(project_id, target_language)
"#{@resource}/language?projectId=#{project_id}&targetLanguage=#{target_language}"
)
end

def add_document(project_id, files: [], files_model: [])
prepare_request(
:post_multipart,
"#{@resource}/document?projectId=#{project_id}",
params: SmartcatSDK::Util::Project.params(files_model, files),
headers: SmartcatSDK::Util::Project.model_headers
)
end
end
end
end

0 comments on commit 6b1a713

Please sign in to comment.