Skip to content

Commit

Permalink
Implement project update
Browse files Browse the repository at this point in the history
  • Loading branch information
İsmail Akbudak committed Mar 12, 2018
1 parent 609f44f commit 9f4aeaf
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
8 changes: 8 additions & 0 deletions examples/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
PROJECT_ID = 'EXAMPLE_PROJECT_ID'.freeze
puts project.get(PROJECT_ID)

# Update project
model = {
'name' => 'Updated name',
'description' => 'Updated description',
'externalTag' => 'id'
}
puts project.update(PROJECT_ID, model)

# Delete project
puts project.delete(PROJECT_ID)

Expand Down
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)
uri.query = URI.encode_www_form(params) if %w[get delete post_multipart].include?(method.to_s)
request = SmartcatSDK::Util::Request.prepare(headers, method, params, uri)
request.basic_auth(@user, @password)
connect_and_send(request)
Expand Down
8 changes: 8 additions & 0 deletions lib/smartcat_sdk/rest/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ def get(project_id)
prepare_request(:get, "#{@resource}/#{project_id}")
end

def update(project_id, project_model)
prepare_request(
:put,
"#{@resource}/#{project_id}",
params: project_model
)
end

def delete(project_id)
prepare_request(:delete, "#{@resource}/#{project_id}")
end
Expand Down
7 changes: 5 additions & 2 deletions lib/smartcat_sdk/util/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ def prepare(headers, method, params, uri)
return Net::HTTP::Post::Multipart.new(uri, params, HTTP_HEADERS.merge(headers))
end
method_class = Net::HTTP.const_get method.to_s.capitalize
request = method_class.new(uri.to_s, headers)
request.form_data = params if %w[post put].include?(method)
request = method_class.new(uri, headers)
if %w[post put].include?(method.to_s)
request.content_type = 'application/json'
request.body = JSON.dump(params)
end
request
end
end
Expand Down

0 comments on commit 9f4aeaf

Please sign in to comment.