Class: HttpConnect::BasicRestClient
- Inherits:
-
Object
- Object
- HttpConnect::BasicRestClient
- Defined in:
- lib/http_connect.rb
Overview
BasicRestClient
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
base url of the http request.
-
#connection_timeout ⇒ Object
connection timeout.
-
#custom_headers ⇒ Object
custom http headers to add to the request.
-
#read_write_timeout ⇒ Object
read and write http request timeout.
-
#use_ssl ⇒ Object
helps to set the request scheme to https.
Instance Method Summary collapse
-
#delete(path, accept, content = {}) ⇒ Object
delete().
-
#execute(http_webrequest) ⇒ Object
execute().
-
#get(path, accept, content = {}) ⇒ Object
get().
-
#initialize(base_url) ⇒ BasicRestClient
constructor
initialize().
-
#post(path, content_type, accept, content = {}) ⇒ Object
post().
-
#put(path, content_type, accept, content = {}) ⇒ Object
put().
-
#set_basic_auth(username, password) ⇒ Object
set_basic_auth().
Constructor Details
#initialize(base_url) ⇒ BasicRestClient
initialize()
29 30 31 32 33 34 35 |
# File 'lib/http_connect.rb', line 29 def initialize(base_url) @base_url = base_url @custom_headers = {} @read_write_timeout = 8000 @connection_timeout = 2000 @use_ssl = false end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
base url of the http request
22 23 24 |
# File 'lib/http_connect.rb', line 22 def base_url @base_url end |
#connection_timeout ⇒ Object
connection timeout
25 26 27 |
# File 'lib/http_connect.rb', line 25 def connection_timeout @connection_timeout end |
#custom_headers ⇒ Object
custom http headers to add to the request
23 24 25 |
# File 'lib/http_connect.rb', line 23 def custom_headers @custom_headers end |
#read_write_timeout ⇒ Object
read and write http request timeout
24 25 26 |
# File 'lib/http_connect.rb', line 24 def read_write_timeout @read_write_timeout end |
#use_ssl ⇒ Object
helps to set the request scheme to https
26 27 28 |
# File 'lib/http_connect.rb', line 26 def use_ssl @use_ssl end |
Instance Method Details
#delete(path, accept, content = {}) ⇒ Object
delete(). It helps send an HTTP DELETE request to delete the specified resource
98 99 100 |
# File 'lib/http_connect.rb', line 98 def delete(path, accept, content = {}) execute HttpConnect::HttpDelete.new(path, nil, accept, content) end |
#execute(http_webrequest) ⇒ Object
execute(). It helps execute an Http request one can use the following object:
- HttpPost
- HttpGet
- HttpDelete
- HttpPut
53 54 55 56 57 58 59 60 |
# File 'lib/http_connect.rb', line 53 def execute(http_webrequest) (http_webrequest.is_a? HttpRequest) ? do_http_request(http_webrequest.path, http_webrequest.http_method, http_webrequest.content_type, http_webrequest.accept, http_webrequest.content) : raise('http_webrequest is not a subclass of HttpRequest') end |
#get(path, accept, content = {}) ⇒ Object
get(). It helps send an HTTP GET request to fetch the specified resource
88 89 90 |
# File 'lib/http_connect.rb', line 88 def get(path, accept, content = {}) execute HttpConnect::HttpGet.new(path, nil, accept, content) end |
#post(path, content_type, accept, content = {}) ⇒ Object
post(). It helps send an HTTP POST request to create the specified resource
68 69 70 |
# File 'lib/http_connect.rb', line 68 def post(path, content_type, accept, content = {}) execute HttpConnect::HttpPost.new(path, content_type, accept, content) end |
#put(path, content_type, accept, content = {}) ⇒ Object
put(). It helps send an HTTP PUT request to create or modified the specified resource
78 79 80 |
# File 'lib/http_connect.rb', line 78 def put(path, content_type, accept, content = {}) execute HttpConnect::HttpPut.new(path, content_type, accept, content) end |
#set_basic_auth(username, password) ⇒ Object
set_basic_auth()
40 41 42 43 |
# File 'lib/http_connect.rb', line 40 def set_basic_auth(username, password) @custom_headers['Authorization'] = "Basic #{Base64.encode64(username + ':' + password)}".chomp end |