rubhub 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/README.md +0 -0
  2. data/lib/github/events/events.rb +45 -0
  3. data/lib/github/gists/gists.rb +66 -0
  4. data/lib/github/gists/gists_comments.rb +35 -0
  5. data/lib/github/gitdata/gitdata.rb +12 -0
  6. data/lib/github/gitdata/gitdata_blobs.rb +24 -0
  7. data/lib/github/gitdata/gitdata_commits.rb +42 -0
  8. data/lib/github/gitdata/gitdata_references.rb +44 -0
  9. data/lib/github/gitdata/gitdata_tags.rb +33 -0
  10. data/lib/github/gitdata/gitdata_trees.rb +25 -0
  11. data/lib/github/github.rb +95 -0
  12. data/lib/github/issues/issues.rb +84 -0
  13. data/lib/github/issues/issues_comments.rb +40 -0
  14. data/lib/github/issues/issues_events.rb +22 -0
  15. data/lib/github/issues/issues_labels.rb +76 -0
  16. data/lib/github/issues/issues_milestones.rb +54 -0
  17. data/lib/github/orgs/orgs.rb +32 -0
  18. data/lib/github/orgs/orgs_members.rb +40 -0
  19. data/lib/github/orgs/orgs_teams.rb +78 -0
  20. data/lib/github/pullreqs/pullreqs.rb +76 -0
  21. data/lib/github/pullreqs/pullreqs_reviewcomments.rb +53 -0
  22. data/lib/github/repos/repos.rb +104 -0
  23. data/lib/github/repos/repos_collaborators.rb +27 -0
  24. data/lib/github/repos/repos_commits.rb +72 -0
  25. data/lib/github/repos/repos_downloads.rb +55 -0
  26. data/lib/github/repos/repos_forks.rb +25 -0
  27. data/lib/github/repos/repos_hooks.rb +57 -0
  28. data/lib/github/repos/repos_keys.rb +43 -0
  29. data/lib/github/repos/repos_watching.rb +33 -0
  30. data/lib/github/users/users.rb +34 -0
  31. data/lib/github/users/users_emails.rb +22 -0
  32. data/lib/github/users/users_followers.rb +31 -0
  33. data/lib/github/users/users_keys.rb +37 -0
  34. data/lib/rubhub.rb +38 -0
  35. data/test/test.rb +9 -0
  36. metadata +101 -0
@@ -0,0 +1,104 @@
1
+ class Repos
2
+ attr_accessor :github, :collaborators, :commits, :downloads, :forks, :keys, :watching, :hooks
3
+
4
+ def initialize(github)
5
+ @github = github
6
+ @collaborators = ReposCollaborators.new(github)
7
+ @commits = ReposCommits.new(github)
8
+ @downloads = ReposDownloads.new(github)
9
+ @forks = ReposForks.new(github)
10
+ @keys = ReposKeys.new(github)
11
+ @watching = ReposWatching.new(github)
12
+ @hooks = ReposHooks.new(github)
13
+ end
14
+
15
+ def listRepos(user=nil)
16
+ username = user == nil ? @github.username : user
17
+ url = 'users/%s/repos' % user != @github.username ? username : 'user/repos'
18
+ @github.get(url)
19
+ end
20
+
21
+ def createUserRepo(name, description=nil, homepage=nil, private=FALSE, has_issues=TRUE, has_wiki=TRUE,
22
+ has_downloads=TRUE)
23
+ params = {
24
+ :name => name,
25
+ :private => private,
26
+ :has_issues => has_issues,
27
+ :has_wiki => has_wiki,
28
+ :has_downloads => has_downloads,
29
+ :description => description,
30
+ :homepage => homepage
31
+ }
32
+ params = @github.removeEmptyParams(params)
33
+ data = params.to_json
34
+ @github.post('user/repos', data)
35
+ end
36
+
37
+ def listOrgRepos(org)
38
+ @github.get('orgs/%s/repos' % org)
39
+ end
40
+
41
+ def createOrgRepo(org, name, description=nil, homepage=nil, private=FALSE,
42
+ has_issues=TRUE, has_wiki=TRUE, has_downloads=TRUE)
43
+ params = {
44
+ :name => name,
45
+ :private => private,
46
+ :has_issues => has_issues,
47
+ :has_wiki => has_wiki,
48
+ :has_downloads => has_downloads,
49
+ :description => description,
50
+ :homepage => homepage
51
+ }
52
+ params = @github.removeEmptyParams(params)
53
+ data = params.to_json
54
+ @github.post('orgs/%s/repos' % org, data)
55
+ end
56
+
57
+ def getRepo(repo, user=nil)
58
+ username = user == nil ? @github.username : user
59
+ @github.get('repos/%s/%s' % [username, repo])
60
+ end
61
+
62
+ def editRepo(repo, name, description=nil, homepage=nil, private=FALSE,
63
+ has_issues=TRUE, has_wiki=TRUE, has_downloads=TRUE, user=nil)
64
+ username = user == nil ? @github.username : user
65
+ params = {
66
+ :name => name,
67
+ :description => description,
68
+ :homepage => homepage,
69
+ :private => private,
70
+ :has_issues => has_issues,
71
+ :has_wiki => has_wiki,
72
+ :has_downloads => has_downloads
73
+ }
74
+ params = @github.removeEmptyParams(params)
75
+ data = params.to_json
76
+ @github.patch('repos/%s/%s' % [username, repo], data)
77
+ end
78
+
79
+ def listContributors(repo, user=nil)
80
+ username = user == nil ? @github.username : user
81
+ @github.get(
82
+ 'repos/%s/%s/contributors' % [username, repo])
83
+ end
84
+
85
+ def listLangs(repo, user=nil)
86
+ username = user == nil ? @github.username : user
87
+ @github.get('repos/%s/%s/languages' % [username, repo])
88
+ end
89
+
90
+ def listTeams(repo, user=nil)
91
+ username = user == nil ? @github.username : user
92
+ @github.get('repos/%s/%s/teams' % [username, repo])
93
+ end
94
+
95
+ def listTags(repo, user=nil)
96
+ username = user == nil ? @github.username : user
97
+ @github.get('repos/%s/%s/tags' % [username, repo])
98
+ end
99
+
100
+ def listBranches(repo, user=nil)
101
+ username = user == nil ? @github.username : user
102
+ @github.get('repos/%s/%s/branches' % [username, repo])
103
+ end
104
+ end
@@ -0,0 +1,27 @@
1
+ class ReposCollaborators
2
+ attr_accessor :github
3
+
4
+ def initialize(github)
5
+ @github = github
6
+ end
7
+
8
+ def list(repo, user=nil)
9
+ username = user == nil ? @github.username : user
10
+ @github.get('repos/%s/%s/collaborators' % [username, repo])
11
+ end
12
+
13
+ def get(repo, collaborator, user=nil)
14
+ username = user == nil ? @github.username : user
15
+ @github.get('repos/%s/%s/collaborators/%s' % [username, repo, collaborator])
16
+ end
17
+
18
+ def addCollaborator(repo, collaborator, user=nil)
19
+ username = user == nil ? @github.username : user
20
+ @github.put('repos/%s/%s/collaborators/%s' % [username, repo, collaborator])
21
+ end
22
+
23
+ def deleteCollaborator(repo, collaborator, user=nil)
24
+ username = user == nil ? @github.username : user
25
+ @github.delete('repos/%s/%s/collaborators/%s' % [username, repo, collaborator])
26
+ end
27
+ end
@@ -0,0 +1,72 @@
1
+ class ReposCommits
2
+ attr_accessor :github
3
+
4
+ def initialize(github)
5
+ @github = github
6
+ end
7
+
8
+ def listCommits(repo, sha=nil, path=nil, user=nil)
9
+ username = user == nil ? @github.username : user
10
+ params = {
11
+ :sha => sha,
12
+ :path => path
13
+ }
14
+ params = @github.removeEmptyParams(params)
15
+ params = @github.parameterize(params)
16
+ url = params ? 'repos/%s/%s/commits?%s' % [username, repo, params] : 'repos/%s/%s/commits'
17
+ @github.get(url)
18
+ end
19
+
20
+ def getCommit(repo, sha, user=nil)
21
+ username = user == nil ? @github.username : user
22
+ @github.get('repos/%s/%s/commits/%s' % [username, repo, sha])
23
+ end
24
+
25
+ def listRepoComments(repo, user=nil)
26
+ username = user == nil ? @github.username : user
27
+ @github.get('repos/%s/%s/comments' % [username, repo])
28
+ end
29
+
30
+ def listComments(repo, sha, user=nil)
31
+ username = user == nil ? @github.username : user
32
+ @github.get('repos/%s/%s/comments/%s/comments' % [username, repo, sha])
33
+ end
34
+
35
+ def createComment(repo, sha, body, line, path, position, user=nil)
36
+ username = user == nil ? @github.username : user
37
+ params = {
38
+ :body => body,
39
+ :commit_id => sha,
40
+ :line => line,
41
+ :path => path,
42
+ :position => position
43
+ }
44
+ data = params.to_json
45
+ @github.post('repos/%s/%s/commits/%s/comments' % [username, repo, sha], data)
46
+ end
47
+
48
+ def getSingleComment(repo, id, user=nil)
49
+ username = user == nil ? @github.username : user
50
+ @github.get('repos/%s/%s/comment/%s' % [username, repo, id])
51
+ end
52
+
53
+ def updateComment(repo, id, body, user=nil)
54
+ username = user == nil ? @github.username : user
55
+ params = {
56
+ :body => body
57
+ }
58
+ data = params.to_json
59
+ @github.post('repos/%s/%s/comments/%s' % [username, repo, id], data)
60
+ end
61
+
62
+ def CompareCommits(repo, base, head, user=nil)
63
+ username = user == nil ? @github.username : user
64
+ @github.get('repos/%s/%s/compare/%s...:%s' % [username, repo, base, head])
65
+ end
66
+
67
+
68
+ def deleteComment(repo, id, user=nil)
69
+ username = user == nil ? @github.username : user
70
+ @github.delete('repos/%s/%s/comments/%s' % [username, repo, id])
71
+ end
72
+ end
@@ -0,0 +1,55 @@
1
+ class ReposDownloads
2
+ attr_accessor :github
3
+
4
+ def initialize(github)
5
+ @github = github
6
+ end
7
+
8
+ def getDownloads(repo, user=nil)
9
+ username = user == nil ? @github.username : user
10
+ @github.get('repos/%s/%s/downloads' % [username, repo])
11
+ end
12
+
13
+ def getDownload(repo, id, user=nil)
14
+ username = user == nil ? @github.username : user
15
+ @github.get('repos/%s/%s/downloads/%s' % [username, repo, id])
16
+ end
17
+
18
+ def createDownload(repo, filePath, description=nil, content_type=nil, user=nil)
19
+ puts 'user:%s' % @github.username
20
+ puts 'password:%s' % @github.password
21
+ # PART 1: Create the resource @ github
22
+ username = user == nil ? @github.username : user
23
+ params = {
24
+ :name => Pathname.new(filePath).basename,
25
+ :size => File.new(filePath).size,
26
+ :description => description,
27
+ :content_type => content_type
28
+ }
29
+ params = @github.removeEmptyParams(params)
30
+ data = params.to_json
31
+ resource = @github.post('repos/%s/%s/downloads' % [username, repo], data)
32
+ # PART 2: Create the download @ Amazon s3
33
+ response = RestClient.post(resource['s3_url'], [
34
+ ['key', resource['path']],
35
+ ['acl', resource['acl']],
36
+ ['success_action_status', 201],
37
+ ['Filename', resource['name']],
38
+ ['AWSAccessKeyId', resource['accesskeyid']],
39
+ ['Policy', resource['policy']],
40
+ ['Signature', resource['signature']],
41
+ ['Content-Type', resource['mime_type']],
42
+ ['file', File.open(filePath)]
43
+ ])
44
+ if response.code == 201
45
+ resource['html_url']
46
+ else
47
+ response.code
48
+ end
49
+ end
50
+
51
+ def deleteDownload(repo, id, user=nil)
52
+ username = user == nil ? @github.username : user
53
+ @github.delete('repos/%s/%s/downloads/%s' % [username, repo, id],)
54
+ end
55
+ end
@@ -0,0 +1,25 @@
1
+ class ReposForks
2
+ attr_accessor :github
3
+
4
+ def initialize(github)
5
+ @github = github
6
+ end
7
+
8
+ def listForks(repo, sort=nil, user=nil)
9
+ username = user == nil ? @github.username : user
10
+ url = 'repos/%s/%s/forks' % [username, repo]
11
+ if sort
12
+ url = '%s?%s=%s' % ['sort', sort]
13
+ end
14
+ @github.get(url)
15
+ end
16
+
17
+ def createFork(repo, org=nil, user=nil)
18
+ username = user == nil ? @github.username : user
19
+ url = 'repos/%s/%s/forks' % [username, repo]
20
+ if org
21
+ url = '%s?%s=%s' % [url, 'org', org]
22
+ end
23
+ @github.post(url)
24
+ end
25
+ end
@@ -0,0 +1,57 @@
1
+ class ReposHooks
2
+ attr_accessor :github
3
+
4
+ def initialize(github)
5
+ @github = github
6
+ end
7
+
8
+ def listHooks(repo, user=nil)
9
+ username = user == nil ? @github.username : user
10
+ @github.get('repos/%s/%s/hooks' % [username, repo])
11
+ end
12
+
13
+ def getHook(repo, id, user=nil)
14
+ username = user == nil ? @github.username : user
15
+ @github.get('repos/%s/%s/hooks/%s' % [username, repo, id])
16
+ end
17
+
18
+ def createHook(repo, name, config, events=nil, active=TRUE,
19
+ user=nil)
20
+ username = user == nil ? @github.username : user
21
+ params = {
22
+ :name => name,
23
+ :config => config,
24
+ :events => events,
25
+ :active => active
26
+ }
27
+ params = @github.removeEmptyParams(params)
28
+ data = params.to_json
29
+ @github.post('repos/%s/%s/hooks' % [username, repo], data)
30
+ end
31
+
32
+ def editHook(repo, id, name, config, events=nil, add_events=nil,
33
+ remove_events=nil, active=TRUE, user=nil)
34
+ username = user == nil ? @github.username : user
35
+ params = {
36
+ :name => name,
37
+ :config => config,
38
+ :events => events,
39
+ :add_events => add_events,
40
+ :remove_events => remove_events,
41
+ :active => active
42
+ }
43
+ params = @github.removeEmptyParams(params)
44
+ data = params.to_json
45
+ @github.patch('repos/%s/%s/hooks/%s' % [username, repo, id], data)
46
+ end
47
+
48
+ def testHook(repo, id, user=nil)
49
+ username = user == nil ? @github.username : user
50
+ @github.post('repos/%s/%s/hooks/%s/test' % [username, repo, id])
51
+ end
52
+
53
+ def deleteHook(repo, id, user=nil)
54
+ username = user == nil ? @github.username : user
55
+ @github.delete('repos/%s/%s/hooks/%s' % [username, repo, id])
56
+ end
57
+ end
@@ -0,0 +1,43 @@
1
+ class ReposKeys
2
+ attr_accessor :github
3
+
4
+ def initialize(github)
5
+ @github = github
6
+ end
7
+
8
+ def listKeys(repo, user=nil)
9
+ username = user == nil ? @github.username : user
10
+ @github.get('repos/%s/%s/keys' % [username, repo])
11
+ end
12
+
13
+ def getKey(repo, id, user=nil)
14
+ username = user == nil ? @github.username : user
15
+ @github.get('repos/%s/%s/keys/%s' % [username, repo, id])
16
+ end
17
+
18
+ def createKey(repo, title, key, user=nil)
19
+ username = user == nil ? @github.username : user
20
+ params = {
21
+ :title => title,
22
+ :key => key
23
+ }
24
+ data = params.to_json
25
+ @github.post('repos/%s/%s/keys' % [username, repo], data)
26
+ end
27
+
28
+ def editKey(repo, id, title=nil, key=nil, user=nil)
29
+ username = user == nil ? @github.username : user
30
+ params = {
31
+ :title => title,
32
+ :key => key
33
+ }
34
+ params = @github.removeEmptyParams(params)
35
+ data = params.to_json
36
+ @github.patch('repos/%s/%s/keys/%s' % [username, repo, id], data)
37
+ end
38
+
39
+ def deleteKey(repo, id, user=nil)
40
+ username = user == nil ? @github.username : user
41
+ @github.delete('repos/%s/%s/keys/%s' % [username, repo, id])
42
+ end
43
+ end
@@ -0,0 +1,33 @@
1
+ class ReposWatching
2
+ attr_accessor :github
3
+
4
+ def initialize(github)
5
+ @github = github
6
+ end
7
+
8
+ def listWatchers(repo, user=nil)
9
+ username = user == nil ? @github.username : user
10
+ @github.get('repos/%s/%s/watchers' % [username, repo])
11
+ end
12
+
13
+ def listWatchedRepos(user=nil)
14
+ url = (user != nil and user != @github.username) ?
15
+ 'users/%s/watched' % user : 'user/watched'
16
+ @github.get(url)
17
+ end
18
+
19
+ def checkIfWatching(repo, user=nil)
20
+ username = user == nil ? @github.username : user
21
+ @github.get('user/watched/%s/%s' % [username, repo])
22
+ end
23
+
24
+ def watchRepo(repo, user=nil)
25
+ username = user == nil ? @github.username : user
26
+ @github.put('user/watched/%s/%s' % [username, repo])
27
+ end
28
+
29
+ def stopWatching(repo, user=nil)
30
+ username = user == nil ? @github.username : user
31
+ @github.delete('user/watched/%s/%s' % [username, repo])
32
+ end
33
+ end
@@ -0,0 +1,34 @@
1
+ class Users
2
+ attr_accessor :github, :emails, :followers, :keys
3
+
4
+ def initialize(github)
5
+ @github = github
6
+ @emails = UsersEmails.new(github)
7
+ @followers = UsersFollowers.new(github)
8
+ @keys = UsersKeys.new(github)
9
+ end
10
+
11
+ def getUser(user=nil)
12
+ url = (user != nil and user != @github.username) ?
13
+ 'users/%s' % user : 'user'
14
+ @github.get(url)
15
+ end
16
+
17
+ def updateUser(name=nil, email=nil, blog=nil, company=nil,
18
+ location=nil, hireable=FALSE, bio=nil)
19
+ params = {
20
+ :name => name,
21
+ :email => email,
22
+ :blog => blog,
23
+ :company => company,
24
+ :location => location,
25
+ :hireable => hireable,
26
+ :bio => bio
27
+ }
28
+ params = @github.removeEmptyParams(params)
29
+ data = params.to_json
30
+ @github.patch('user', data)
31
+ end
32
+ end
33
+
34
+