Class: MgmtConsole::Client
- Inherits:
-
Object
- Object
- MgmtConsole::Client
- Includes:
- Authentication, EngageCommunities, EngageEnvironments, EngageInstances, EngageServers, ServerEnvironments, SpigitConfigs, Configurable
- Defined in:
- lib/mgmt_console/client.rb,
lib/mgmt_console/client/engage_servers.rb,
lib/mgmt_console/client/spigit_configs.rb,
lib/mgmt_console/client/engage_instances.rb,
lib/mgmt_console/client/engage_communities.rb,
lib/mgmt_console/client/engage_environments.rb,
lib/mgmt_console/client/server_environments.rb
Overview
Client for the Mgmt Console API
Defined Under Namespace
Modules: EngageCommunities, EngageEnvironments, EngageInstances, EngageServers, ServerEnvironments, SpigitConfigs
Constant Summary collapse
- CONVENIENCE_HEADERS =
Set.new([:accept, :content_type])
Instance Attribute Summary
Attributes included from Configurable
#access_token, #api_endpoint, #auto_paginate, #client_id, #client_secret, #connection_options, #default_media_type, #login, #middleware, #netrc, #netrc_file, #password, #per_page, #proxy, #ssl_verify, #user_agent, #web_endpoint
Instance Method Summary collapse
-
#access_token=(value) ⇒ Object
Set OAuth access token for authentication.
-
#agent ⇒ Sawyer::Agent
Hypermedia agent for the GitHub 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.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#inspect ⇒ String
Text representation of the client, masking tokens and passwords.
-
#last_response ⇒ Sawyer::Response
Response for last HTTP request.
-
#octokit_warn(*message) ⇒ nil
Wrapper around Kernel#warn to print warnings unless OCTOKIT_SILENT is set to true.
-
#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 MgmtConsole::Configurable#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.
-
#same_options?(opts) ⇒ Boolean
Compares client options to a Hash of requested options.
Methods included from SpigitConfigs
#create_spigit_config, #spigit_configs, #update_engage_instance
Methods included from EngageInstances
#create_engage_instance, #engage_instances, #update_engage_instance
Methods included from EngageServers
#create_engage_server, #engage_servers, #update_engage_server
Methods included from EngageCommunities
#create_engage_communities, #engage_communities
Methods included from EngageEnvironments
#create_engage_environment, #engage_environments, #update_engage_environment
Methods included from ServerEnvironments
#create_server_environment, #server_environments
Methods included from Configurable
Methods included from Authentication
#token_authenticated?, #user_authenticated?
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
31 32 33 34 35 36 |
# File 'lib/mgmt_console/client.rb', line 31 def initialize( = {}) # Use options passed in, but fall back to module defaults MgmtConsole::Configurable.keys.each do |key| instance_variable_set(:"@#{key}", resolve_opt(, key)) end end |
Instance Method Details
#access_token=(value) ⇒ Object
Set OAuth access token for authentication
181 182 183 184 |
# File 'lib/mgmt_console/client.rb', line 181 def access_token=(value) reset_agent @access_token = value end |
#agent ⇒ Sawyer::Agent
Hypermedia agent for the GitHub API
151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/mgmt_console/client.rb', line 151 def agent @agent ||= Sawyer::Agent.new(api_endpoint, ) do |http| http.headers[:accept] = default_media_type http.headers[:content_type] = "application/json" http.headers[:user_agent] = user_agent http.ssl[:verify] = ssl_verify if token_authenticated? http.headers['X-User-Token'] = @access_token end end end |
#delete(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP DELETE request
101 102 103 |
# File 'lib/mgmt_console/client.rb', line 101 def delete(url, = {}) request :delete, url, end |
#get(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP GET request
65 66 67 |
# File 'lib/mgmt_console/client.rb', line 65 def get(url, = {}) request :get, url, parse_query_and_convenience_headers() end |
#head(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP HEAD request
110 111 112 |
# File 'lib/mgmt_console/client.rb', line 110 def head(url, = {}) request :head, url, parse_query_and_convenience_headers() end |
#inspect ⇒ String
Text representation of the client, masking tokens and passwords
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mgmt_console/client.rb', line 49 def inspect inspected = super # Only show last 4 of token, secret if @access_token inspected = inspected.gsub! @access_token, "#{'*'*36}#{@access_token[36..-1]}" end inspected end |
#last_response ⇒ Sawyer::Response
Response for last HTTP request
174 175 176 |
# File 'lib/mgmt_console/client.rb', line 174 def last_response @last_response if defined? @last_response end |
#octokit_warn(*message) ⇒ nil
Wrapper around Kernel#warn to print warnings unless OCTOKIT_SILENT is set to true.
190 191 192 193 194 |
# File 'lib/mgmt_console/client.rb', line 190 def octokit_warn(*) unless ENV['OCTOKIT_SILENT'] warn end 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 MgmtConsole::Configurable#auto_paginate.
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/mgmt_console/client.rb', line 125 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) if @auto_paginate while @last_response.rels[:next]# && rate_limit.remaining > 0 @last_response = @last_response.rels[:next].get 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
92 93 94 |
# File 'lib/mgmt_console/client.rb', line 92 def patch(url, = {}) request :patch, url, end |
#post(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP POST request
74 75 76 |
# File 'lib/mgmt_console/client.rb', line 74 def post(url, = {}) request :post, url, end |
#put(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP PUT request
83 84 85 |
# File 'lib/mgmt_console/client.rb', line 83 def put(url, = {}) request :put, url, end |
#root ⇒ Sawyer::Resource
Fetch the root resource for the API
167 168 169 |
# File 'lib/mgmt_console/client.rb', line 167 def root get "/" end |
#same_options?(opts) ⇒ Boolean
Compares client options to a Hash of requested options
42 43 44 |
# File 'lib/mgmt_console/client.rb', line 42 def (opts) opts.hash == .hash end |