Class: GitHub::Browser

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/github-api-client/browser.rb

Overview

Handles low-level HTTP requests

Class Method Summary collapse

Class Method Details

.base_uri(version = 'v2') ⇒ String

Returnes root uri for GitHub API

Parameters:

  • version (String) (defaults to: 'v2')

    GitHub api keyword, defaults to v2

Options Hash (version):

  • v1" ("v1")
  • v2" ("v2")
  • v3" ("v3")

Returns:

  • (String)

    Base GitHub API url for v2



12
13
14
15
# File 'lib/github-api-client/browser.rb', line 12

def self.base_uri(version = 'v2')
  gh_uri = GitHub::Config::Options[:server]||'github.com'
  "http://#{gh_uri}/api/#{version}/yaml"
end

.get(uri, version = 'v2') ⇒ String

Runs HTTP GET request at given uri

Parameters:

  • uri (String)

    URI to be joined with base_uri and requested

Returns:

  • (String)

    request result



20
21
22
23
24
# File 'lib/github-api-client/browser.rb', line 20

def self.get(uri, version = 'v2')
  uri = URI.parse(self.base_uri(version) + uri.gsub(" ","+"))
  puts "Requesting #{uri}" if GitHub::Config::Options[:verbose]
  Net::HTTP.get uri
end

.patch(uri, options = {}, version = 'v2') ⇒ String

Runs HTTP PATCH request at a given uri

Parameters:

  • uri (String)

    URI to be joined with base_uri and requested

Returns:

  • (String)

    request result



38
39
40
41
42
# File 'lib/github-api-client/browser.rb', line 38

def self.patch(uri, options = {}, version = 'v2')
  uri = uri.gsub(" ","+")
  puts "Requesting #{URI.parse(self.base_uri(version) + uri)} with options: #{options}" if GitHub::Config::Options[:verbose]
  Net::HTTP.patch URI.parse(self.base_uri + uri), options
end

.post(uri, options = {}, version = 'v2') ⇒ String

Runs HTTP POST requests with options such as GitHub::User.auth_info

Parameters:

  • uri (String)

    URI to be joined with base_uri and requested

Returns:

  • (String)

    request result



29
30
31
32
33
# File 'lib/github-api-client/browser.rb', line 29

def self.post(uri, options = {}, version = 'v2')
  uri = URI.parse(self.base_uri(version) + uri.gsub(" ","+"))
  puts "Requesting #{uri} with options: #{options}" if GitHub::Config::Options[:verbose]
  Net::HTTP.post_form uri, options
end