Class: Hubba::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/hubba/client.rb

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



8
9
10
11
12
13
# File 'lib/hubba/client.rb', line 8

def initialize
  uri = URI.parse( "https://api.github.com" )
  @http = Net::HTTP.new(uri.host, uri.port)
  @http.use_ssl = true
  @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end

Instance Method Details

#get(request_uri) ⇒ Object

method initialize



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/hubba/client.rb', line 15

def get( request_uri )
  puts "GET #{request_uri}"

  req = Net::HTTP::Get.new( request_uri )
  ## req = Net::HTTP::Get.new( "/users/geraldb" )

  ## req = Net::HTTP::Get.new( "/users/geraldb/repos" )

  req["User-Agent"] = "ruby/github.rb"                  ## required by GitHub API 

  req["Accept" ]    = "application/vnd.github.v3+json"  ## recommend by GitHub API


  res = @http.request(req)

  # Get specific header

  # response["content-type"]

  # => "text/html; charset=UTF-8"


  # Iterate all response headers.

  res.each_header do |key, value|
    p "#{key} => #{value}"
  end
  # => "location => http://www.google.com/"

  # => "content-type => text/html; charset=UTF-8"

  # ...


  json = JSON.parse( res.body )
  ## pp json

  json
end