Module: Github::Connection

Extended by:
Connection
Includes:
Constants
Included in:
Connection, Request
Defined in:
lib/github_api/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

Instance Method Details

#connection(api, options = {}) ⇒ Object

Creates http connection

Returns a Fraday::Connection object


65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/github_api/connection.rb', line 65

def connection(api, options = {})
  connection_options = default_options(options)
  connection_options.merge!(builder: stack(options.merge!(api: api)))
  if options[:connection_options]
    connection_options.deep_merge!(options[:connection_options])
  end
  if ENV['DEBUG']
    p "Connection options : \n"
    pp connection_options
  end
  Faraday.new(connection_options)
end

#default_headersHash[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

Returns:


22
23
24
25
26
27
28
29
# File 'lib/github_api/connection.rb', line 22

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

Returns:

  • (Hash[Symbol])

    the default options


37
38
39
40
41
42
43
44
45
# File 'lib/github_api/connection.rb', line 37

def default_options(options = {})
  headers = default_headers.merge(options[:headers] || {})
  headers.merge!({USER_AGENT => options[:user_agent]})
  {
    headers: headers,
    ssl: options[:ssl],
    url: options[:endpoint]
  }
end

#stack(options = {}) ⇒ Object

Exposes middleware builder to facilitate custom stacks and easy addition of new extensions such as cache adapter.


51
52
53
54
55
56
57
58
59
60
# File 'lib/github_api/connection.rb', line 51

def stack(options = {})
  @stack ||= begin
    builder_class = if defined?(Faraday::RackBuilder)
                      Faraday::RackBuilder
                    else
                      Faraday::Builder
                    end
    builder_class.new(&Github.default_middleware(options))
  end
end