New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic rest-client only post_file. #5
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ def initialize(msg=nil) | |
end | ||
end | ||
|
||
require_relative 'wrappers/base_wrapper' | ||
|
||
def self.puts(s) | ||
Kernel.puts("rest gem: #{s}") | ||
end | ||
|
@@ -49,7 +51,6 @@ def initialize(options={}) | |
@wrapper = Rest::Wrappers::NetHttpPersistentWrapper.new(self) | ||
Rest.puts "Using net-http-persistent gem." | ||
else | ||
require_relative 'wrappers/rest_client_wrapper' | ||
@wrapper = Rest::Wrappers::RestClientWrapper.new | ||
Rest.puts "Using rest-client gem. Please install 'typhoeus' or net-http-persistent gem for best performance." | ||
end | ||
|
@@ -134,6 +135,14 @@ def delete(url, req_hash={}) | |
return res | ||
end | ||
|
||
def post_file(url, req_hash={}) | ||
res = nil | ||
perform_op do | ||
res = @wrapper.post_file(url, req_hash) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, can you add that to comments? |
||
end | ||
return res | ||
end | ||
|
||
def close | ||
@wrapper.close | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,32 @@ | ||
class BaseWrapper | ||
|
||
def post_file(url, req_hash={}) | ||
response = nil | ||
begin | ||
if req_hash[:body] | ||
req_hash = req_hash.merge(req_hash[:body]) | ||
req_hash.delete(:body) | ||
end | ||
|
||
headers = {} | ||
if req_hash[:headers] | ||
headers = req_hash[:headers] | ||
req_hash.delete(:headers) | ||
end | ||
|
||
r2 = RestClient.post(url, req_hash, headers) | ||
response = Rest::Wrappers::RestClientResponseWrapper.new(r2) | ||
rescue RestClient::Exception => ex | ||
raise Rest::Wrappers::RestClientExceptionWrapper.new(ex) | ||
end | ||
response | ||
end | ||
|
||
# if wrapper has a close/shutdown, override this | ||
def close | ||
|
||
end | ||
end | ||
end | ||
|
||
# we need it for post_file, ok as gem already depends on it | ||
require_relative 'rest_client_wrapper' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be at the top? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no it's ok. rest_client_wrapper inherits base_wrapper, so need to be included after it, but as base uses rest for post_file (actually, just needs exception classes) it's good to include it here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the file passed in the param? What is the param name user should pass in? Comment would be good here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sample usage