Class: CFoundry::RestClient
- Inherits:
-
Object
- Object
- CFoundry::RestClient
- Includes:
- TraceHelpers
- Defined in:
- lib/cfoundry/rest_client.rb
Defined Under Namespace
Classes: HTTPFactory
Constant Summary collapse
- LOG_LENGTH =
10
- HTTP_METHODS =
{ "GET" => Net::HTTP::Get, "PUT" => Net::HTTP::Put, "POST" => Net::HTTP::Post, "DELETE" => Net::HTTP::Delete, "HEAD" => Net::HTTP::Head, }
- DEFAULT_OPTIONS =
{ :follow_redirects => true }
Constants included from TraceHelpers
TraceHelpers::PROTECTED_ATTRIBUTES
Instance Attribute Summary collapse
-
#backtrace ⇒ Object
Returns the value of attribute backtrace.
-
#http_proxy ⇒ Object
Returns the value of attribute http_proxy.
-
#https_proxy ⇒ Object
Returns the value of attribute https_proxy.
-
#log ⇒ Object
Returns the value of attribute log.
-
#request_id ⇒ Object
Returns the value of attribute request_id.
-
#target ⇒ Object
Returns the value of attribute target.
-
#token ⇒ Object
Returns the value of attribute token.
-
#trace ⇒ Object
Returns the value of attribute trace.
Instance Method Summary collapse
- #generate_headers(payload, options) ⇒ Object
-
#initialize(target, token = nil) ⇒ RestClient
constructor
A new instance of RestClient.
- #request(method, path, options = {}) ⇒ Object
Methods included from TraceHelpers
#request_trace, #response_trace
Constructor Details
#initialize(target, token = nil) ⇒ RestClient
Returns a new instance of RestClient.
53 54 55 56 57 58 59 |
# File 'lib/cfoundry/rest_client.rb', line 53 def initialize(target, token = nil) @target = target @token = token @trace = false @backtrace = false @log = false end |
Instance Attribute Details
#backtrace ⇒ Object
Returns the value of attribute backtrace.
50 51 52 |
# File 'lib/cfoundry/rest_client.rb', line 50 def backtrace @backtrace end |
#http_proxy ⇒ Object
Returns the value of attribute http_proxy.
50 51 52 |
# File 'lib/cfoundry/rest_client.rb', line 50 def http_proxy @http_proxy end |
#https_proxy ⇒ Object
Returns the value of attribute https_proxy.
50 51 52 |
# File 'lib/cfoundry/rest_client.rb', line 50 def https_proxy @https_proxy end |
#log ⇒ Object
Returns the value of attribute log.
50 51 52 |
# File 'lib/cfoundry/rest_client.rb', line 50 def log @log end |
#request_id ⇒ Object
Returns the value of attribute request_id.
50 51 52 |
# File 'lib/cfoundry/rest_client.rb', line 50 def request_id @request_id end |
#target ⇒ Object
Returns the value of attribute target.
48 49 50 |
# File 'lib/cfoundry/rest_client.rb', line 48 def target @target end |
#token ⇒ Object
Returns the value of attribute token.
50 51 52 |
# File 'lib/cfoundry/rest_client.rb', line 50 def token @token end |
#trace ⇒ Object
Returns the value of attribute trace.
50 51 52 |
# File 'lib/cfoundry/rest_client.rb', line 50 def trace @trace end |
Instance Method Details
#generate_headers(payload, options) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/cfoundry/rest_client.rb', line 72 def generate_headers(payload, ) headers = {} if payload.is_a?(String) headers["Content-Length"] = payload.size elsif !payload headers["Content-Length"] = 0 end headers["X-Request-Id"] = @request_id if @request_id headers["Authorization"] = @token.auth_header if @token if accept_type = mimetype([:accept]) headers["Accept"] = accept_type end if content_type = mimetype([:content]) headers["Content-Type"] = content_type end headers.merge!([:headers]) if [:headers] headers end |
#request(method, path, options = {}) ⇒ Object
68 69 70 |
# File 'lib/cfoundry/rest_client.rb', line 68 def request(method, path, = {}) request_uri(method, construct_url(path), DEFAULT_OPTIONS.merge()) end |