Module: Rancher::Connection
Overview
Network layer for API clients.
Constant Summary collapse
- CONVENIENCE_HEADERS =
Set.new([:accept, :content_type])
Instance Method Summary collapse
-
#agent ⇒ Sawyer::Agent
Hypermedia agent for the Rancher API.
-
#delete(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP DELETE request.
-
#get(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP GET request.
-
#head(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP HEAD request.
-
#last_response ⇒ Sawyer::Response
Response for last HTTP request.
-
#paginate(url, options = {}, &block) ⇒ Sawyer::Resource
Make one or more HTTP GET requests, optionally fetching the next page of results from URL in Link response header based on value in #auto_paginate.
-
#patch(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP PATCH request.
-
#post(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP POST request.
-
#put(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP PUT request.
-
#root ⇒ Sawyer::Resource
Fetch the root resource for the API.
Methods included from Classify
Methods included from Authentication
Instance Method Details
#agent ⇒ Sawyer::Agent
Hypermedia agent for the Rancher API
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/rancher/connection.rb', line 106 def agent @agent ||= Sawyer::Agent.new(endpoint, ) do |http| http.headers[:accept] = default_media_type http.headers[:content_type] = "application/json" http.headers[:user_agent] = user_agent if basic_authenticated? http.basic_auth(@access_key, @secret_key) end end end |
#delete(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP DELETE request
56 57 58 |
# File 'lib/rancher/connection.rb', line 56 def delete(url, = {}) request :delete, url, end |
#get(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP GET request
20 21 22 |
# File 'lib/rancher/connection.rb', line 20 def get(url, = {}) request :get, url, parse_query_and_convenience_headers() end |
#head(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP HEAD request
65 66 67 |
# File 'lib/rancher/connection.rb', line 65 def head(url, = {}) request :head, url, parse_query_and_convenience_headers() end |
#last_response ⇒ Sawyer::Response
Response for last HTTP request
127 128 129 |
# File 'lib/rancher/connection.rb', line 127 def last_response @last_response if defined? @last_response end |
#paginate(url, options = {}, &block) ⇒ Sawyer::Resource
Make one or more HTTP GET requests, optionally fetching the next page of results from URL in Link response header based on value in #auto_paginate.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/rancher/connection.rb', line 80 def paginate(url, = {}, &block) opts = parse_query_and_convenience_headers(.dup) if @auto_paginate || @per_page opts[:query][:per_page] ||= @per_page || (@auto_paginate ? 100 : nil) end data = request(:get, url, opts.dup) if @auto_paginate while @last_response.rels[:next] && rate_limit.remaining > 0 @last_response = @last_response.rels[:next].get(:headers => opts[:headers]) if block_given? yield(data, @last_response) else data.concat(@last_response.data) if @last_response.data.is_a?(Array) end end end data end |
#patch(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP PATCH request
47 48 49 |
# File 'lib/rancher/connection.rb', line 47 def patch(url, = {}) request :patch, url, end |
#post(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP POST request
29 30 31 |
# File 'lib/rancher/connection.rb', line 29 def post(url, = {}) request :post, url, end |
#put(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP PUT request
38 39 40 |
# File 'lib/rancher/connection.rb', line 38 def put(url, = {}) request :put, url, end |
#root ⇒ Sawyer::Resource
Fetch the root resource for the API
120 121 122 |
# File 'lib/rancher/connection.rb', line 120 def root get "" end |