Class: Github

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ Github

Returns a new instance of Github.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/github/github.rb', line 5

def initialize(username, password)
  @apiurl = 'https://api.github.com'
  @username = username
  @password = password
  @events = Events.new(self)
  @gists = Gists.new(self)
  @gitdata = GitData.new(self)
  @issues = Issues.new(self)
  @orgs = Orgs.new(self)
  @pullreqs = PullReq.new(self)
  @repos = Repos.new(self)
  @users = Users.new(self)
  @events = Events.new(self)
end

Instance Attribute Details

#apiurlObject (readonly)

Returns the value of attribute apiurl.



2
3
4
# File 'lib/github/github.rb', line 2

def apiurl
  @apiurl
end

#eventsObject

Returns the value of attribute events.



3
4
5
# File 'lib/github/github.rb', line 3

def events
  @events
end

#gistsObject

Returns the value of attribute gists.



3
4
5
# File 'lib/github/github.rb', line 3

def gists
  @gists
end

#gitdataObject

Returns the value of attribute gitdata.



3
4
5
# File 'lib/github/github.rb', line 3

def gitdata
  @gitdata
end

#issuesObject

Returns the value of attribute issues.



3
4
5
# File 'lib/github/github.rb', line 3

def issues
  @issues
end

#orgsObject

Returns the value of attribute orgs.



3
4
5
# File 'lib/github/github.rb', line 3

def orgs
  @orgs
end

#passwordObject (readonly)

Returns the value of attribute password.



2
3
4
# File 'lib/github/github.rb', line 2

def password
  @password
end

#pullreqsObject

Returns the value of attribute pullreqs.



3
4
5
# File 'lib/github/github.rb', line 3

def pullreqs
  @pullreqs
end

#reposObject

Returns the value of attribute repos.



3
4
5
# File 'lib/github/github.rb', line 3

def repos
  @repos
end

#usernameObject (readonly)

Returns the value of attribute username.



2
3
4
# File 'lib/github/github.rb', line 2

def username
  @username
end

#usersObject

Returns the value of attribute users.



3
4
5
# File 'lib/github/github.rb', line 3

def users
  @users
end

Instance Method Details

#buildurl(path) ⇒ Object



84
85
86
# File 'lib/github/github.rb', line 84

def buildurl(path)
  @apiurl + ((path[0] == '/') ? path : ('/%s' % path))
end

#delete(path, data = nil) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'lib/github/github.rb', line 73

def delete(path, data=nil)
  uri = URI(buildurl(path))
  req = Net::HTTP::Delete.new(uri.request_uri)
  req.basic_auth @username, @password
  req.body = data
  res = Net::HTTP.start(uri.hostname, use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE) { |http|
    http.request(req)
  }
  res.body ? JSON.parse(res.body) : res.code
end

#get(path) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/github/github.rb', line 30

def get(path)
  uri = URI(buildurl(path))
  req = Net::HTTP::Get.new(uri.request_uri, initheader = {'Accept' => 'application/json'})
  req.basic_auth @username, @password
  res = Net::HTTP.start(uri.hostname, use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE) { |http|
    http.request(req)
  }
  JSON.parse(res.body)
end

#head(path) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/github/github.rb', line 20

def head(path)
  uri = URI(buildurl(path))
  req = Net::HTTP::Head.new(uri.request_uri)
  req.basic_auth @username, @password
  res = Net::HTTP.start(uri.hostname, use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE) { |http|
    http.request(req)
  }
  JSON.parse(res.body)
end

#parameterize(params) ⇒ Object



88
89
90
# File 'lib/github/github.rb', line 88

def parameterize(params)
  URI.escape(params.collect { |k, v| "#{k}=#{v}" }.join('&'))
end

#patch(path, data) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/github/github.rb', line 51

def patch(path, data)
  uri = URI(buildurl(path))
  req = Net::HTTP::Patch.new(uri.request_uri, initheader = {'Content-Type' => 'application/json'})
  req.basic_auth @username, @password
  req.body = data
  res = Net::HTTP.start(uri.hostname, use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE) { |http|
    http.request(req)
  }
  JSON.parse(res.body)
end

#post(path, data = nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/github/github.rb', line 40

def post(path, data=nil)
  uri = URI(buildurl(path))
  req = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' => 'application/json'})
  req.basic_auth @username, @password
  req.body = data
  res = Net::HTTP.start(uri.hostname, use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE) { |http|
    http.request(req)
  }
  res.body
end

#put(path, data = nil) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/github/github.rb', line 62

def put(path, data=nil)
  uri = URI(buildurl(path))
  req = Net::HTTP::Put.new(uri.request_uri, initheader = {'Content-Type' => 'application/json'})
  req.basic_auth @username, @password
  req.body = data
  res = Net::HTTP.start(uri.hostname, use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE) { |http|
    http.request(req)
  }
  JSON.parse(res.body)
end

#removeEmptyParams(params) ⇒ Object



92
93
94
# File 'lib/github/github.rb', line 92

def removeEmptyParams(params)
  params.delete_if { |k, v| v.nil? }
end