Class: Docker::Distribution::Connection
- Inherits:
-
Object
- Object
- Docker::Distribution::Connection
- Includes:
- Error
- Defined in:
- lib/docker/distribution/api/connection.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url, opts) ⇒ Connection
constructor
Create a new Connection.
- #log_request(request) ⇒ Object
-
#request(*args, &block) ⇒ Object
Send a request to the server with the ‘.
- #to_s ⇒ Object
Constructor Details
#initialize(url, opts) ⇒ Connection
Create a new Connection. This method takes a url (String) and options (Hash). These are passed to Excon, so any options valid for ‘Excon.new` can be passed here.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/docker/distribution/api/connection.rb', line 14 def initialize(url, opts) case when !url.is_a?(String) raise ArgumentError, "Expected a String, got: '#{url.class}'" when !opts.is_a?(Hash) raise ArgumentError, "Expected a Hash, got: '#{opts.class}'" else uri = URI.parse(url) if ['https', 'http'].include? uri.scheme @url, @options = url, opts else @url, @options = "http://#{uri}", opts end end end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/docker/distribution/api/connection.rb', line 9 def @options end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
9 10 11 |
# File 'lib/docker/distribution/api/connection.rb', line 9 def url @url end |
Instance Method Details
#log_request(request) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/docker/distribution/api/connection.rb', line 57 def log_request(request) if Api.logger Api.logger.debug( [request[:method], request[:path], request[:query], request[:body]] ) end end |
#request(*args, &block) ⇒ Object
Send a request to the server with the ‘
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/docker/distribution/api/connection.rb', line 39 def request(*args, &block) request = compile_request_params(*args, &block) log_request(request) resource.request(request) rescue Excon::Errors::BadRequest => ex raise ClientError, ex.response.body rescue Excon::Errors::Unauthorized => ex raise UnauthorizedError, ex.response.body rescue Excon::Errors::NotFound => ex raise NotFoundError, ex.response.body rescue Excon::Errors::Conflict => ex raise ConflictError, ex.response.body rescue Excon::Errors::InternalServerError => ex raise ServerError, ex.response.body rescue Excon::Errors::Timeout => ex raise TimeoutError, ex. end |
#to_s ⇒ Object
70 71 72 |
# File 'lib/docker/distribution/api/connection.rb', line 70 def to_s "Docker::Distribution::Connection { :url => #{url}, :options => #{} }" end |