Module: PuppetForge::Connection Private
- Included in:
- V3::Module, V3::ModuleRelease
- Defined in:
- lib/shared/puppet_forge/connection.rb,
lib/shared/puppet_forge/connection/connection_failure.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Provide a common mixin for adding a HTTP connection to classes.
This module provides a common method for creating HTTP connections as well as reusing a single connection object between multiple classes. Including classes can invoke #conn to get a reasonably configured HTTP connection. Connection objects can be passed with the #conn= method.
Defined Under Namespace
Classes: ConnectionFailure
Constant Summary collapse
- USER_AGENT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"PuppetForge/#{PuppetForge::VERSION} Faraday/#{Faraday::VERSION} Ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} (#{RUBY_PLATFORM})"
Instance Attribute Summary collapse
-
#conn ⇒ Faraday::Connection
private
An existing Faraday connection if one was already set, otherwise a new Faraday connection.
Class Method Summary collapse
- .authorization ⇒ Object private
- .authorization=(token) ⇒ Object private
Instance Method Summary collapse
-
#make_connection(url, adapter_args = nil) ⇒ Faraday::Connection
private
Generate a new Faraday connection for the given URL.
Instance Attribute Details
#conn ⇒ Faraday::Connection
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns An existing Faraday connection if one was already set, otherwise a new Faraday connection.
39 40 41 |
# File 'lib/shared/puppet_forge/connection.rb', line 39 def conn @conn ||= make_connection('https://forgeapi.puppetlabs.com') end |
Class Method Details
.authorization ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
33 34 35 |
# File 'lib/shared/puppet_forge/connection.rb', line 33 def self. @authorization end |
.authorization=(token) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
29 30 31 |
# File 'lib/shared/puppet_forge/connection.rb', line 29 def self.(token) @authorization = token end |
Instance Method Details
#make_connection(url, adapter_args = nil) ⇒ Faraday::Connection
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generate a new Faraday connection for the given URL.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/shared/puppet_forge/connection.rb', line 47 def make_connection(url, adapter_args = nil) adapter_args ||= [Faraday.default_adapter] = { :headers => { :user_agent => USER_AGENT }} if token = PuppetForge::Connection. [:headers][:authorization] = token end Faraday.new(url, ) do |builder| builder.response(:json, :content_type => /\bjson$/) builder.response(:raise_error) builder.use(:connection_failure) builder.adapter(*adapter_args) end end |