Class: Ghee::Connection
- Inherits:
-
Faraday::Connection
- Object
- Faraday::Connection
- Ghee::Connection
- Defined in:
- lib/ghee/connection.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
-
#initialize(hash = {}) ⇒ Connection
constructor
Instantiates connection, accepts an options hash for authenticated access.
- #parallel_connection(adapter = :typhoeus) ⇒ Object
Constructor Details
#initialize(hash = {}) ⇒ Connection
Instantiates connection, accepts an options hash for authenticated access
OAuth2 expects
:access_token => "OAuth Token"
Basic auth expects
:basic_auth => {:user_name => "octocat", :password => "secret"}
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ghee/connection.rb', line 23 def initialize(hash={}) @hash = hash access_token = hash[:access_token] if hash.has_key?:access_token basic_auth = hash[:basic_auth] if hash.has_key?:basic_auth super(hash[:api_url] || 'https://api.github.com') do |builder| yield builder if block_given? builder.use Faraday::Response::RaiseGheeError builder.use FaradayMiddleware::EncodeJson builder.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/ builder.adapter Faraday.default_adapter end self.headers["Authorization"] = "token #{access_token}" if access_token self.basic_auth(basic_auth[:user_name], basic_auth[:password]) if basic_auth self.headers["Accept"] = 'application/vnd.github.v3.full+json' end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
7 8 9 |
# File 'lib/ghee/connection.rb', line 7 def hash @hash end |
Instance Method Details
#parallel_connection(adapter = :typhoeus) ⇒ Object
9 10 11 12 13 |
# File 'lib/ghee/connection.rb', line 9 def parallel_connection(adapter=:typhoeus) conn = self.class.new @hash conn.adapter adapter conn end |