Module: Github::Connection
- Extended by:
- Connection
- Includes:
- Constants
- Included in:
- Connection, Request
- Defined in:
- lib/github_api2/connection.rb
Overview
Specifies Http connection options
Constant Summary collapse
- ALLOWED_OPTIONS =
[ :headers, :url, :params, :request, :ssl ].freeze
Constants included from Constants
Github::Constants::ACCEPT, Github::Constants::ACCEPTED_OAUTH_SCOPES, Github::Constants::ACCEPT_CHARSET, Github::Constants::CACHE_CONTROL, Github::Constants::CONTENT_LENGTH, Github::Constants::CONTENT_TYPE, Github::Constants::DATE, Github::Constants::ETAG, Github::Constants::HEADER_LAST, Github::Constants::HEADER_LINK, Github::Constants::HEADER_NEXT, Github::Constants::LOCATION, Github::Constants::META_FIRST, Github::Constants::META_LAST, Github::Constants::META_NEXT, Github::Constants::META_PREV, Github::Constants::META_REL, Github::Constants::OAUTH_SCOPES, Github::Constants::PARAM_PAGE, Github::Constants::PARAM_PER_PAGE, Github::Constants::PARAM_START_PAGE, Github::Constants::RATELIMIT_LIMIT, Github::Constants::RATELIMIT_REMAINING, Github::Constants::RATELIMIT_RESET, Github::Constants::SERVER, Github::Constants::USER_AGENT
Instance Method Summary collapse
-
#connection(api, options = {}) ⇒ Object
Creates http connection.
-
#default_headers ⇒ Hash[String]
private
Default requets header information.
-
#default_options(options = {}) ⇒ Hash[Symbol]
private
Create default connection options.
-
#stack(options = {}) ⇒ Object
Exposes middleware builder to facilitate custom stacks and easy addition of new extensions such as cache adapter.
Instance Method Details
#connection(api, options = {}) ⇒ Object
Creates http connection
Returns a Faraday::Connection object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/github_api2/connection.rb', line 69 def connection(api, = {}) = () .merge!(builder: stack(.merge!(api: api))) if [:connection_options] .deep_merge!([:connection_options]) end if ENV['DEBUG'] p "Connection options : \n" pp end Faraday.new() end |
#default_headers ⇒ Hash[String]
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.
Default requets header information
26 27 28 29 30 31 32 33 |
# File 'lib/github_api2/connection.rb', line 26 def default_headers { ACCEPT => 'application/vnd.github.v3+json,' \ 'application/vnd.github.beta+json;q=0.5,' \ 'application/json;q=0.1', ACCEPT_CHARSET => 'utf-8' } end |
#default_options(options = {}) ⇒ Hash[Symbol]
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.
Create default connection options
41 42 43 44 45 46 47 48 49 |
# File 'lib/github_api2/connection.rb', line 41 def ( = {}) headers = default_headers.merge([:headers] || {}) headers.merge!({USER_AGENT => [:user_agent]}) { headers: headers, ssl: [:ssl], url: [:endpoint] } end |
#stack(options = {}) ⇒ Object
Exposes middleware builder to facilitate custom stacks and easy addition of new extensions such as cache adapter.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/github_api2/connection.rb', line 55 def stack( = {}) @stack ||= begin builder_class = if defined?(Faraday::RackBuilder) Faraday::RackBuilder else Faraday::Builder end builder_class.new(&Github.default_middleware()) end end |