github_api 0.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/LICENSE.txt +20 -0
  2. data/README.rdoc +159 -0
  3. data/Rakefile +52 -0
  4. data/features/github.feature +9 -0
  5. data/features/step_definitions/github_steps.rb +0 -0
  6. data/features/support/env.rb +13 -0
  7. data/lib/github_api.rb +55 -0
  8. data/lib/github_api/api.rb +133 -0
  9. data/lib/github_api/api/extract_options.rb +17 -0
  10. data/lib/github_api/api/mime.rb +5 -0
  11. data/lib/github_api/api/utils.rb +9 -0
  12. data/lib/github_api/client.rb +35 -0
  13. data/lib/github_api/configuration.rb +84 -0
  14. data/lib/github_api/connection.rb +91 -0
  15. data/lib/github_api/error.rb +35 -0
  16. data/lib/github_api/gists.rb +199 -0
  17. data/lib/github_api/gists/comments.rb +74 -0
  18. data/lib/github_api/git_data.rb +26 -0
  19. data/lib/github_api/git_data/blobs.rb +9 -0
  20. data/lib/github_api/git_data/commits.rb +9 -0
  21. data/lib/github_api/git_data/references.rb +9 -0
  22. data/lib/github_api/git_data/tags.rb +9 -0
  23. data/lib/github_api/git_data/trees.rb +9 -0
  24. data/lib/github_api/issues.rb +201 -0
  25. data/lib/github_api/issues/comments.rb +98 -0
  26. data/lib/github_api/issues/events.rb +50 -0
  27. data/lib/github_api/issues/labels.rb +191 -0
  28. data/lib/github_api/issues/milestones.rb +119 -0
  29. data/lib/github_api/orgs.rb +90 -0
  30. data/lib/github_api/orgs/members.rb +109 -0
  31. data/lib/github_api/orgs/teams.rb +236 -0
  32. data/lib/github_api/pull_requests.rb +210 -0
  33. data/lib/github_api/pull_requests/comments.rb +134 -0
  34. data/lib/github_api/repos.rb +256 -0
  35. data/lib/github_api/repos/collaborators.rb +59 -0
  36. data/lib/github_api/repos/commits.rb +115 -0
  37. data/lib/github_api/repos/downloads.rb +77 -0
  38. data/lib/github_api/repos/forks.rb +29 -0
  39. data/lib/github_api/repos/hooks.rb +67 -0
  40. data/lib/github_api/repos/keys.rb +53 -0
  41. data/lib/github_api/repos/watching.rb +50 -0
  42. data/lib/github_api/request.rb +75 -0
  43. data/lib/github_api/request/oauth2.rb +33 -0
  44. data/lib/github_api/response.rb +10 -0
  45. data/lib/github_api/response/jsonize.rb +22 -0
  46. data/lib/github_api/response/mashify.rb +26 -0
  47. data/lib/github_api/response/raise_error.rb +33 -0
  48. data/lib/github_api/users.rb +82 -0
  49. data/lib/github_api/users/emails.rb +49 -0
  50. data/lib/github_api/users/followers.rb +98 -0
  51. data/lib/github_api/users/keys.rb +84 -0
  52. data/lib/github_api/version.rb +12 -0
  53. data/spec/fixtures/collaborators_list.json +6 -0
  54. data/spec/fixtures/commits_list.json +25 -0
  55. data/spec/fixtures/repos_branches_list.json +7 -0
  56. data/spec/fixtures/repos_list.json +27 -0
  57. data/spec/github/api_spec.rb +6 -0
  58. data/spec/github/client_spec.rb +6 -0
  59. data/spec/github/gists/comments_spec.rb +5 -0
  60. data/spec/github/gists_spec.rb +5 -0
  61. data/spec/github/git_data/blobs_spec.rb +5 -0
  62. data/spec/github/git_data/commits_spec.rb +5 -0
  63. data/spec/github/git_data/references_spec.rb +5 -0
  64. data/spec/github/git_data/tags_spec.rb +5 -0
  65. data/spec/github/git_data/trees_spec.rb +5 -0
  66. data/spec/github/git_data_spec.rb +5 -0
  67. data/spec/github/issues/comments_spec.rb +5 -0
  68. data/spec/github/issues/events_spec.rb +5 -0
  69. data/spec/github/issues/labels_spec.rb +5 -0
  70. data/spec/github/issues/milestones_spec.rb +5 -0
  71. data/spec/github/issues_spec.rb +5 -0
  72. data/spec/github/orgs/members_spec.rb +5 -0
  73. data/spec/github/orgs/teams_spec.rb +5 -0
  74. data/spec/github/orgs_spec.rb +5 -0
  75. data/spec/github/repos/collaborators_spec.rb +6 -0
  76. data/spec/github/repos/commits_spec.rb +5 -0
  77. data/spec/github/repos/downloads_spec.rb +5 -0
  78. data/spec/github/repos/forks_spec.rb +5 -0
  79. data/spec/github/repos/hooks_spec.rb +5 -0
  80. data/spec/github/repos/keys_spec.rb +5 -0
  81. data/spec/github/repos/watching_spec.rb +5 -0
  82. data/spec/github/repos_spec.rb +35 -0
  83. data/spec/github_spec.rb +5 -0
  84. data/spec/spec_helper.rb +15 -0
  85. metadata +284 -0
@@ -0,0 +1,74 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class Gists
5
+ module Comments
6
+
7
+ REQUIRED_GIST_COMMENT_INPUTS = %w[ body ]
8
+
9
+ # List comments on a gist
10
+ #
11
+ # = Examples
12
+ # @github = Github.new
13
+ # @github.gists.gist_comments 'gist-id'
14
+ #
15
+ def gist_comments(gist_id, params={})
16
+ _normalize_params_keys(params)
17
+ get("/gists/#{gist_id}/comments", params)
18
+ end
19
+
20
+ # Get a single comment
21
+ #
22
+ # = Examples
23
+ # @github = Github.new
24
+ # @github.gists.gist_comment 'comment-id'
25
+ #
26
+ def gist_comment(comment_id, params={})
27
+ _normalize_params_keys(params)
28
+ get("/gists/comments/#{comment_id}", params)
29
+ end
30
+
31
+ # Create a comment
32
+ #
33
+ # = Examples
34
+ # @github = Github.new
35
+ # @github.gists.create_gist_comment 'gist-id'
36
+ #
37
+ def create_gist_comment(gist_id, params={})
38
+ _normalize_params_keys(params)
39
+ _filter_params_keys(REQUIRED_GIST_COMMENT_INPUTS, params)
40
+
41
+ raise ArgumentError, "Required inputs are: :body" unless _validate_inputs(REQUIRED_GIST_COMMENT_INPUTS, params)
42
+
43
+ post("/gists/#{gist_id}/comments", params)
44
+ end
45
+
46
+ # Edit a comment
47
+ #
48
+ # = Examples
49
+ # @github = Github.new
50
+ # @github.gists.edit_gist_comment 'comment-id'
51
+ #
52
+ def edit_gist_comment(comment_id, params={})
53
+ _normalize_params_keys(params)
54
+ _filter_params_keys(REQUIRED_GIST_COMMENT_INPUTS, params)
55
+
56
+ raise ArgumentError, "Required inputs are: :body" unless _validate_inputs(REQUIRED_GIST_COMMENT_INPUTS, params)
57
+
58
+ patch("/gists/comments/#{comment_id}", params)
59
+ end
60
+
61
+ # Delete a comment
62
+ #
63
+ # = Examples
64
+ # @github = Github.new
65
+ # @github.gists.delete_gist_comment 'comment-id'
66
+ #
67
+ def delete_gist_comment(comment_id, params={})
68
+ _normalize_params_keys(params)
69
+ delete("/gists/comments/#{comment_id}", params)
70
+ end
71
+
72
+ end # Comments
73
+ end # Gists
74
+ end # Github
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class GitData < API
5
+ extend AutoloadHelper
6
+
7
+ autoload_all 'github_api/git_data',
8
+ :Blobs => 'blobs',
9
+ :Commits => 'commits',
10
+ :References => 'references',
11
+ :Tags => 'tags',
12
+ :Trees => 'trees'
13
+
14
+ include Github::GitData::Blobs
15
+ include Github::GitData::Commits
16
+ include Github::GitData::References
17
+ include Github::GitData::Tags
18
+ include Github::GitData::Trees
19
+
20
+ # Creates new GitData API
21
+ def initialize(options = {})
22
+ super(options)
23
+ end
24
+
25
+ end # GitData
26
+ end # Github
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class GitData
5
+ module Blobs
6
+
7
+ end # Blobs
8
+ end # GitData
9
+ end # Github
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class GitData
5
+ module Commits
6
+
7
+ end # Commits
8
+ end # GitData
9
+ end # Github
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class GitData
5
+ module References
6
+
7
+ end # References
8
+ end # GitData
9
+ end # Github
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class GitData
5
+ module Tags
6
+
7
+ end # Tags
8
+ end # GitData
9
+ end # Github
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class GitData
5
+ module Trees
6
+
7
+ end # Trees
8
+ end # GitData
9
+ end # Github
@@ -0,0 +1,201 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class Issues < API
5
+ extend AutoloadHelper
6
+
7
+ autoload_all 'github_api/issues',
8
+ :Comments => 'comments',
9
+ :Events => 'events',
10
+ :Labels => 'labels',
11
+ :Milestones => 'milestones'
12
+
13
+ include Github::Issues::Comments
14
+ include Github::Issues::Events
15
+ include Github::Issues::Labels
16
+ include Github::Issues::Milestones
17
+
18
+ VALID_ISSUE_PARAM_NAMES = %w[
19
+ filter
20
+ state
21
+ labels
22
+ sort
23
+ direction
24
+ since
25
+ milestone
26
+ assignee
27
+ mentioned
28
+ title
29
+ body
30
+ ]
31
+
32
+ VALID_ISSUE_PARAM_VALUES = {
33
+ 'filter' => %w[ assigned created mentioned subscribed ],
34
+ 'state' => %w[ open closed ],
35
+ 'sort' => %w[ created updated comments ],
36
+ 'direction' => %w[ desc asc ],
37
+ 'since' => %r{\d{4}-\d{2}-\d{5}:\d{2}:\d{3}}
38
+ }
39
+
40
+ # Creates new Issues API
41
+ def initialize(options = {})
42
+ super(options)
43
+ end
44
+
45
+ # List your issues
46
+ #
47
+ # = Parameters
48
+ # <tt>:filter</tt>
49
+ # * <tt>assigned</tt>: Issues assigned to you (default)
50
+ # * <tt>created</tt>: Issues assigned to you (default)
51
+ # * <tt>mentioned</tt>: Issues assigned to you (default)
52
+ # * <tt>subscribed</tt>: Issues assigned to you (default)
53
+ # <tt>:state</tt> - <tt>open</tt>, <tt>closed</tt>, default: <tt>open</tt>
54
+ # <tt>:labels</tt> - String list of comma separated Label names. Example: bug,ui,@high
55
+ # <tt>:sort</tt> - <tt>created</tt>, <tt>updated</tt>, <tt>comments</tt>, default: <tt>created</tt>
56
+ # <tt>:direction</tt> - <tt>asc</tt>, <tt>desc</tt>, default: <tt>desc</tt>
57
+ # <tt>:since</tt> - Optional string of a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ
58
+ #
59
+ # = Examples
60
+ # @github = Github.new :oauth_token => '...'
61
+ # @github.issues.issues :since => '2011-04-12312:12:121',
62
+ # :filter => 'created',
63
+ # :state => 'open',
64
+ # :labels => "bug,ui,bla",
65
+ # :sort => 'comments',
66
+ # :direction => 'asc'
67
+ #
68
+ def issues(params={})
69
+ _normalize_params_keys(params)
70
+ _filter_params_keys(VALID_ISSUE_PARAM_NAMES, params)
71
+ _validate_params_values(VALID_ISSUE_PARAM_VALUES, params)
72
+
73
+ response = get("/issues", params)
74
+ return response unless block_given?
75
+ response.each { |el| yield el }
76
+ end
77
+
78
+ # List issues for a repository
79
+ #
80
+ # = Parameters
81
+ # <tt>:milestone</tt>
82
+ # * Integer Milestone number
83
+ # * <tt>none</tt> for Issues with no Milestone.
84
+ # * <tt>*</tt> for Issues with any Milestone
85
+ # <tt>:state</tt> - <tt>open</tt>, <tt>closed</tt>, default: <tt>open</tt>
86
+ # <tt>:assignee</tt>
87
+ # * String User login
88
+ # * <tt>none</tt> for Issues with no assigned User.
89
+ # * <tt>*</tt> for Issues with any assigned User.
90
+ # <tt>:mentioned</tt> String User login
91
+ # <tt>:labels</tt> - String list of comma separated Label names. Example: bug,ui,@high
92
+ # <tt>:sort</tt> - <tt>created</tt>, <tt>updated</tt>, <tt>comments</tt>, default: <tt>created</tt>
93
+ # <tt>:direction</tt> - <tt>asc</tt>, <tt>desc</tt>, default: <tt>desc</tt>
94
+ # <tt>:since</tt> - Optional string of a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ
95
+ # <tt></tt>, default: <tt>due_date</tt>
96
+ # <tt>:direction</tt> - <tt>asc</tt>, <tt>desc</tt>, default: <tt>desc</tt>
97
+ #
98
+ # = Examples
99
+ # @github = Github.new :user => 'user-name', :repo => 'repo-name'
100
+ # @github.issues.repo_issues :milestone => 1,
101
+ # :state => 'open',
102
+ # :assignee => '*',
103
+ # :mentioned => 'octocat',
104
+ # :labels => "bug,ui,bla",
105
+ # :sort => 'comments',
106
+ # :direction => 'asc'
107
+ #
108
+ def repo_issues(user_name=nil, repo_name=nil, params={})
109
+ _update_user_repo_params(user_name, repo_name)
110
+ _validate_user_repo_params(user, repo) unless user? && repo?
111
+
112
+ _normalize_params_keys(params)
113
+ _filter_params_keys(VALID_ISSUE_PARAM_NAMES, params)
114
+ _validate_params_values(VALID_ISSUE_PARAM_VALUES, params)
115
+
116
+ response = get("/repos/#{user}/#{repo}/issues", params)
117
+ return response unless block_given?
118
+ response.each { |el| yield el }
119
+ end
120
+
121
+ # Get a single issue
122
+ #
123
+ # = Examples
124
+ # @github = Github.new
125
+ # @github.issues.get_issue 'user-name', 'repo-name', 'issue-id'
126
+ #
127
+ def get_issue(user_name, repo_name, issue_id, params={})
128
+ _update_user_repo_params(user_name, repo_name)
129
+ _validate_user_repo_params(user, repo) unless user? && repo?
130
+ _normalize_params_keys(params)
131
+
132
+ get("/repos/#{user}/#{repo}/issues/#{issue_id}")
133
+ end
134
+
135
+ # Create an issue
136
+ #
137
+ # = Inputs
138
+ # <tt>:title</tt> - Required string
139
+ # <tt>:body</tt> - Optional string
140
+ # <tt>:assignee</tt> - Optional string - Login for the user that this issue should be assigned to.
141
+ # <tt>:milestone</tt> - Optional number - Milestone to associate this issue with
142
+ # <tt>:labels</tt> - Optional array of strings - Labels to associate with this issue
143
+ # = Examples
144
+ # @github = Github.new :user => 'user-name', :repo => 'repo-name'
145
+ # @github.issues.create_issue
146
+ # "title" => "Found a bug",
147
+ # "body" => "I'm having a problem with this.",
148
+ # "assignee" => "octocat",
149
+ # "milestone" => 1,
150
+ # "labels" => [
151
+ # "Label1",
152
+ # "Label2"
153
+ # ]
154
+ #
155
+ def create_issue(user_name=nil, repo_name=nil, params={})
156
+ _update_user_repo_params(user_name, repo_name)
157
+ _validate_user_repo_params(user, repo) unless user? && repo?
158
+
159
+ _normalize_params_keys(params)
160
+ _filter_params_keys(VALID_MILESTONE_INPUTS, params)
161
+
162
+ raise ArgumentError, "Required params are: :title" unless _validate_inputs(%w[ title ], params)
163
+
164
+ post("/repos/#{user}/#{repo}/issues", params)
165
+ end
166
+
167
+ # Edit an issue
168
+ #
169
+ # = Inputs
170
+ # <tt>:title</tt> - Optional string
171
+ # <tt>:body</tt> - Optional string
172
+ # <tt>:assignee</tt> - Optional string - Login for the user that this issue should be assigned to.
173
+ # <tt>:state</tt> - Optional string - State of the issue:<tt>open</tt> or <tt>closed</tt>
174
+ # <tt>:milestone</tt> - Optional number - Milestone to associate this issue with
175
+ # <tt>:labels</tt> - Optional array of strings - Labels to associate with this issue. Pass one or more Labels to replace the set of Labels on this Issue. Send an empty array ([]) to clear all Labels from the Issue.
176
+ #
177
+ # = Examples
178
+ # @github = Github.new
179
+ # @github.issues.create_issue 'user-name', 'repo-name', 'issue-id'
180
+ # "title" => "Found a bug",
181
+ # "body" => "I'm having a problem with this.",
182
+ # "assignee" => "octocat",
183
+ # "milestone" => 1,
184
+ # "labels" => [
185
+ # "Label1",
186
+ # "Label2"
187
+ # ]
188
+ #
189
+ def edit_issue(user_name, repo_name, issue_id, params={})
190
+ _update_user_repo_params(user_name, repo_name)
191
+ _validate_user_repo_params(user, repo) unless user? && repo?
192
+ _validate_presence_of issue_id
193
+
194
+ _normalize_params_keys(params)
195
+ _filter_params_keys(VALID_MILESTONE_INPUTS, params)
196
+
197
+ patch("/repos/#{user}/#{repo}/issues/#{issue_id}", params)
198
+ end
199
+
200
+ end # Issues
201
+ end # Github
@@ -0,0 +1,98 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class Issues
5
+ module Comments
6
+
7
+ VALID_ISSUE_COMMENT_PARAM_NAME = %w[ body ]
8
+
9
+ # List comments on an issue
10
+ #
11
+ # = Examples
12
+ # @github = Github.new
13
+ # @github.issues.issue_comments 'user-name', 'repo-name', 'issue-id'
14
+ #
15
+ def issue_comments(user_name, repo_name, issue_id, params={})
16
+ _update_user_repo_params(user_name, repo_name)
17
+ _validate_user_repo_params(user, repo) unless user? && repo?
18
+ _normalize_params_keys(params)
19
+
20
+ get("/repos/#{user}/#{repo}/issues/#{issue_id}/comments", params)
21
+ end
22
+
23
+ # Get a single comment
24
+ #
25
+ # = Examples
26
+ # @github = Github.new
27
+ # @github.issues.issue_comment 'user-name', 'repo-name', 'comment-id'
28
+ #
29
+ def issue_comment(user_name, repo_name, comment_id, params={})
30
+ _update_user_repo_params(user_name, repo_name)
31
+ _validate_user_repo_params(user, repo) unless user? && repo?
32
+ _validate_presence_of comment_id
33
+ _normalize_params_keys(params)
34
+
35
+ get("/repos/#{user}/#{repo}/issues/comments/#{comment_id}")
36
+ end
37
+
38
+ # Create a comment
39
+ #
40
+ # = Inputs
41
+ # <tt>:body</tt> Required string
42
+ #
43
+ # = Examples
44
+ # @github = Github.new
45
+ # @github.issues.create_issue_comment 'user-name', 'repo-name', 'issue-id',
46
+ # "body" => 'a new comment'
47
+ #
48
+ def create_issue_comment(user_name, repo_name, issue_id, params={})
49
+ _update_user_repo_params(user_name, repo_name)
50
+ _validate_user_repo_params(user, repo) unless user? && repo?
51
+ _validate_presence_of issue_id
52
+
53
+ _normalize_params_keys(params)
54
+ _filter_params_keys(VALID_ISSUE_COMMENT_PARAM_NAME, params)
55
+
56
+ post("/repos/#{user}/#{repo}/issues/#{issue_id}/comments")
57
+ end
58
+
59
+ # Edit a comment
60
+ #
61
+ # = Inputs
62
+ # <tt>:body</tt> Required string
63
+ #
64
+ # = Examples
65
+ # @github = Github.new
66
+ # @github.issues.edit_issue_comment 'user-name', 'repo-name', 'comment-id',
67
+ # "body" => 'a new comment'
68
+ #
69
+ def edit_issue_comment(user_name, repo_name, comment_id, params={})
70
+ _update_user_repo_params(user_name, repo_name)
71
+ _validate_user_repo_params(user, repo) unless user? && repo?
72
+ _validate_presence_of comment_id
73
+
74
+ _normalize_params_keys(params)
75
+ _filter_params_keys(VALID_ISSUE_COMMENT_PARAM_NAME, params)
76
+
77
+ patch("/repos/#{user}/#{repo}/issues/comments/#{comment_id}")
78
+ end
79
+
80
+ # Delete a comment
81
+ #
82
+ # = Examples
83
+ # @github = Github.new
84
+ # @github.issues.delete_issue_comment 'user-name', 'repo-name', 'comment-id'
85
+ #
86
+ def delete_issue_comment(user_name, repo_name, comment_id, params={})
87
+ _update_user_repo_params(user_name, repo_name)
88
+ _validate_user_repo_params(user, repo) unless user? && repo?
89
+ _validate_presence_of comment_id
90
+
91
+ _normalize_params_keys(params)
92
+
93
+ delete("/repos/#{user}/#{repo}/issues/comments/#{comment_id}")
94
+ end
95
+
96
+ end # Comments
97
+ end # Issues
98
+ end # Github