Class: JFoundry::BaseClient
- Inherits:
-
Object
- Object
- JFoundry::BaseClient
- Extended by:
- Forwardable
- Includes:
- ProxyOptions
- Defined in:
- lib/jfoundry/baseclient.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#rest_client ⇒ Object
readonly
Returns the value of attribute rest_client.
Instance Method Summary collapse
- #delete(*args) ⇒ Object
- #get(*args) ⇒ Object
-
#info ⇒ Object
Cloud metadata.
-
#initialize(target, access_key, secret_key, version) ⇒ BaseClient
constructor
A new instance of BaseClient.
- #post(*args) ⇒ Object
- #put(*args) ⇒ Object
- #request(method, *args) ⇒ Object
- #request_raw(method, path, options) ⇒ Object
- #stream_url(url, &blk) ⇒ Object
- #trace=(trace) ⇒ Object
Methods included from ProxyOptions
Constructor Details
#initialize(target, access_key, secret_key, version) ⇒ BaseClient
Returns a new instance of BaseClient.
20 21 22 23 24 25 |
# File 'lib/jfoundry/baseclient.rb', line 20 def initialize(target, access_key, secret_key, version) @rest_client = JFoundry::RestClient.new(target, access_key, secret_key, version) self.trace = false self.backtrace = false self.log = false end |
Instance Attribute Details
#rest_client ⇒ Object (readonly)
Returns the value of attribute rest_client.
14 15 16 |
# File 'lib/jfoundry/baseclient.rb', line 14 def rest_client @rest_client end |
Instance Method Details
#delete(*args) ⇒ Object
41 42 43 |
# File 'lib/jfoundry/baseclient.rb', line 41 def delete(*args) request("DELETE", *args) end |
#get(*args) ⇒ Object
37 38 39 |
# File 'lib/jfoundry/baseclient.rb', line 37 def get(*args) request("GET", *args) end |
#info ⇒ Object
Cloud metadata
33 34 35 |
# File 'lib/jfoundry/baseclient.rb', line 33 def info get("info", :accept => :json) end |
#post(*args) ⇒ Object
45 46 47 |
# File 'lib/jfoundry/baseclient.rb', line 45 def post(*args) request("POST", *args) end |
#put(*args) ⇒ Object
49 50 51 |
# File 'lib/jfoundry/baseclient.rb', line 49 def put(*args) request("PUT", *args) end |
#request(method, *args) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/jfoundry/baseclient.rb', line 53 def request(method, *args) #puts "args: ", args path, = normalize_arguments(args) #puts "path: ", path #puts "options: ", options request, response = request_raw(method, path, ) handle_response(response, , request) end |
#request_raw(method, path, options) ⇒ Object
62 63 64 |
# File 'lib/jfoundry/baseclient.rb', line 62 def request_raw(method, path, ) @rest_client.request(method, path, ) end |
#stream_url(url, &blk) ⇒ Object
66 67 68 69 70 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 |
# File 'lib/jfoundry/baseclient.rb', line 66 def stream_url(url, &blk) uri = URI.parse(url) opts = {} if uri.scheme == "https" opts[:use_ssl] = true opts[:verify_mode] = OpenSSL::SSL::VERIFY_NONE end Net::HTTP.start(uri.host, uri.port, *(uri), opts) do |http| http.read_timeout = 5 req = Net::HTTP::Get.new(uri.request_uri) #req["Authorization"] = token.auth_header if token http.request(req) do |response| case response when Net::HTTPOK response.read_body(&blk) when Net::HTTPNotFound raise JFoundry::NotFound.new(response.body, 404) when Net::HTTPForbidden raise JFoundry::Denied.new(response.body, 403) when Net:: raise JFoundry::.new(response.body, 401) else raise JFoundry::BadResponse.new(response.body, response.code) end end end end |
#trace=(trace) ⇒ Object
27 28 29 30 |
# File 'lib/jfoundry/baseclient.rb', line 27 def trace=(trace) @rest_client.trace = trace #@uaa.trace = trace if @uaa end |