Class: GHClient::Connection
- Inherits:
-
Object
- Object
- GHClient::Connection
- Defined in:
- lib/ghclient/connection.rb
Constant Summary collapse
- BASE_URL =
'https://api.github.com'- ACCESS_TOKEN =
'6afbf23e799a6d16d7a2cc69645307ea4a3a6c74'
Instance Attribute Summary collapse
-
#last_response ⇒ Object
readonly
Returns the value of attribute last_response.
Instance Method Summary collapse
- #check_and_parse_response!(response) ⇒ Object
- #check_options!(options) ⇒ Object
- #get(path) ⇒ Object
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize(options = {}) ⇒ Connection
Returns a new instance of Connection.
15 16 17 18 19 |
# File 'lib/ghclient/connection.rb', line 15 def initialize = {} = [:access_token] ||= ACCESS_TOKEN () end |
Instance Attribute Details
#last_response ⇒ Object (readonly)
Returns the value of attribute last_response.
13 14 15 |
# File 'lib/ghclient/connection.rb', line 13 def last_response @last_response end |
Instance Method Details
#check_and_parse_response!(response) ⇒ Object
31 32 33 34 |
# File 'lib/ghclient/connection.rb', line 31 def check_and_parse_response!(response) @last_response = response JSON.parse(response.body) end |
#check_options!(options) ⇒ Object
21 22 23 |
# File 'lib/ghclient/connection.rb', line 21 def () [:access_token] || (raise NoAccessToken) end |
#get(path) ⇒ Object
25 26 27 28 29 |
# File 'lib/ghclient/connection.rb', line 25 def get path uri = URI(BASE_URL + path + "?access_token=#{@options[:access_token]}") response = Net::HTTP.get_response(uri) check_and_parse_response!(response) end |