Class: JFoundry::RestClient
- Inherits:
-
Object
- Object
- JFoundry::RestClient
- Includes:
- ProxyOptions, Signature::Version, Timer, TraceHelpers
- Defined in:
- lib/jfoundry/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
-
#access_key ⇒ Object
Returns the value of attribute access_key.
-
#backtrace ⇒ Object
Returns the value of attribute backtrace.
-
#from ⇒ Object
Returns the value of attribute from.
-
#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.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
-
#target ⇒ Object
Returns the value of attribute target.
-
#trace ⇒ Object
Returns the value of attribute trace.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #generate_headers(uri, payload, options) ⇒ Object
-
#initialize(target, access_key, secret_key, version, from) ⇒ RestClient
constructor
A new instance of RestClient.
- #request(method, path, options = {}) ⇒ Object
Methods included from Signature::Version
#generate_signature, #string_to_sign
Methods included from Signer
Methods included from Timer
Methods included from ProxyOptions
Methods included from TraceHelpers
#request_trace, #response_trace
Constructor Details
#initialize(target, access_key, secret_key, version, from) ⇒ RestClient
Returns a new instance of RestClient.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/jfoundry/rest_client.rb', line 48 def initialize(target, access_key, secret_key, version, from) @target = target #@token = token @access_key = access_key @secret_key = secret_key @version = version @from = from @trace = false @backtrace = false @log = false end |
Instance Attribute Details
#access_key ⇒ Object
Returns the value of attribute access_key.
45 46 47 |
# File 'lib/jfoundry/rest_client.rb', line 45 def access_key @access_key end |
#backtrace ⇒ Object
Returns the value of attribute backtrace.
45 46 47 |
# File 'lib/jfoundry/rest_client.rb', line 45 def backtrace @backtrace end |
#from ⇒ Object
Returns the value of attribute from.
45 46 47 |
# File 'lib/jfoundry/rest_client.rb', line 45 def from @from end |
#http_proxy ⇒ Object
Returns the value of attribute http_proxy.
45 46 47 |
# File 'lib/jfoundry/rest_client.rb', line 45 def http_proxy @http_proxy end |
#https_proxy ⇒ Object
Returns the value of attribute https_proxy.
45 46 47 |
# File 'lib/jfoundry/rest_client.rb', line 45 def https_proxy @https_proxy end |
#log ⇒ Object
Returns the value of attribute log.
45 46 47 |
# File 'lib/jfoundry/rest_client.rb', line 45 def log @log end |
#request_id ⇒ Object
Returns the value of attribute request_id.
45 46 47 |
# File 'lib/jfoundry/rest_client.rb', line 45 def request_id @request_id end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
45 46 47 |
# File 'lib/jfoundry/rest_client.rb', line 45 def secret_key @secret_key end |
#target ⇒ Object
Returns the value of attribute target.
43 44 45 |
# File 'lib/jfoundry/rest_client.rb', line 43 def target @target end |
#trace ⇒ Object
Returns the value of attribute trace.
45 46 47 |
# File 'lib/jfoundry/rest_client.rb', line 45 def trace @trace end |
#version ⇒ Object
Returns the value of attribute version.
45 46 47 |
# File 'lib/jfoundry/rest_client.rb', line 45 def version @version end |
Instance Method Details
#generate_headers(uri, payload, options) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/jfoundry/rest_client.rb', line 71 def generate_headers(uri, 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 headers['Version'] = @version headers['From'] = @from headers['Date'] = get_time headers['ACCESS-KEY'] = @access_key headers['Path'] = URI.parse(uri.to_s).path 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
67 68 69 |
# File 'lib/jfoundry/rest_client.rb', line 67 def request(method, path, = {}) request_uri(method, construct_url(path), DEFAULT_OPTIONS.merge()) end |