Module: HttpHandler

Included in:
RepoHttpHandler, UserHttpHandler
Defined in:
lib/github_api_ruby_lib/http/http_handler.rb

Class Method Summary collapse

Class Method Details

.create_http(uri) ⇒ Object



4
5
6
7
# File 'lib/github_api_ruby_lib/http/http_handler.rb', line 4

def self.create_http(uri)
  @@http=Net::HTTP.new(uri.host,uri.port)
  @@http.use_ssl = true
end

.get_response(https, uri) ⇒ Object

Method gets response from GET request, checks for validiation, and returns json

Attributes

  • https - HTTP object sending the GET request. Must be previously initialized

  • uri - Uri object holding converted API url, used for sending GET request



16
17
18
19
20
21
22
23
24
# File 'lib/github_api_ruby_lib/http/http_handler.rb', line 16

def self.get_response(https,uri)  # :yields: JSON

  result=https.get(uri)
  if result.code =="200"
    return JSON.parse(result.body)
  else
    raise "HTTP failed with code: #{result.code}"
  end
end

.initiate_http(uri) ⇒ Object

Creates a new HTTP object with the given uri’s host and port

Attributes

  • uri - Uri object containing api link



31
32
33
34
35
# File 'lib/github_api_ruby_lib/http/http_handler.rb', line 31

def self.initiate_http(uri) # :yields: HTTP
  http=Net::HTTP.new(uri.host,uri.port)
  http.use_ssl = true
  return http
end