Class: Ghee::Connection

Inherits:
Faraday::Connection
  • Object
show all
Defined in:
lib/ghee/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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"}


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ghee/connection.rb', line 17

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('https://api.github.com') do |builder|
    builder.use     Faraday::Request::JSON
    builder.use     FaradayMiddleware::ParseJson
    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/json'
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



7
8
9
# File 'lib/ghee/connection.rb', line 7

def hash
  @hash
end