github_api 0.3.5 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. data/LICENSE.txt +20 -0
  2. data/README.rdoc +228 -0
  3. data/Rakefile +52 -0
  4. data/features/github_api.feature +50 -0
  5. data/features/options.feature +4 -0
  6. data/features/pagination.feature +4 -0
  7. data/features/step_definitions/github_api_steps.rb +11 -0
  8. data/features/support/env.rb +13 -0
  9. data/lib/github_api.rb +73 -0
  10. data/lib/github_api/api.rb +175 -0
  11. data/lib/github_api/api/utils.rb +9 -0
  12. data/lib/github_api/authorization.rb +73 -0
  13. data/lib/github_api/authorizations.rb +119 -0
  14. data/lib/github_api/cache_control.rb +19 -0
  15. data/lib/github_api/client.rb +55 -0
  16. data/lib/github_api/compatibility.rb +23 -0
  17. data/lib/github_api/configuration.rb +96 -0
  18. data/lib/github_api/connection.rb +75 -0
  19. data/lib/github_api/core_ext/array.rb +14 -0
  20. data/lib/github_api/core_ext/hash.rb +42 -0
  21. data/lib/github_api/error.rb +35 -0
  22. data/lib/github_api/events.rb +202 -0
  23. data/lib/github_api/gists.rb +200 -0
  24. data/lib/github_api/gists/comments.rb +86 -0
  25. data/lib/github_api/git_data.rb +26 -0
  26. data/lib/github_api/git_data/blobs.rb +51 -0
  27. data/lib/github_api/git_data/commits.rb +78 -0
  28. data/lib/github_api/git_data/references.rb +113 -0
  29. data/lib/github_api/git_data/tags.rb +78 -0
  30. data/lib/github_api/git_data/trees.rb +89 -0
  31. data/lib/github_api/issues.rb +215 -0
  32. data/lib/github_api/issues/comments.rb +123 -0
  33. data/lib/github_api/issues/events.rb +54 -0
  34. data/lib/github_api/issues/labels.rb +191 -0
  35. data/lib/github_api/issues/milestones.rb +140 -0
  36. data/lib/github_api/mime_type.rb +55 -0
  37. data/lib/github_api/orgs.rb +95 -0
  38. data/lib/github_api/orgs/members.rb +120 -0
  39. data/lib/github_api/orgs/teams.rb +245 -0
  40. data/lib/github_api/pull_requests.rb +224 -0
  41. data/lib/github_api/pull_requests/comments.rb +144 -0
  42. data/lib/github_api/repos.rb +286 -0
  43. data/lib/github_api/repos/collaborators.rb +81 -0
  44. data/lib/github_api/repos/commits.rb +180 -0
  45. data/lib/github_api/repos/downloads.rb +155 -0
  46. data/lib/github_api/repos/forks.rb +48 -0
  47. data/lib/github_api/repos/hooks.rb +174 -0
  48. data/lib/github_api/repos/keys.rb +104 -0
  49. data/lib/github_api/repos/pub_sub_hubbub.rb +102 -0
  50. data/lib/github_api/repos/watching.rb +94 -0
  51. data/lib/github_api/request.rb +84 -0
  52. data/lib/github_api/request/basic_auth.rb +31 -0
  53. data/lib/github_api/request/caching.rb +33 -0
  54. data/lib/github_api/request/oauth2.rb +33 -0
  55. data/lib/github_api/response.rb +28 -0
  56. data/lib/github_api/response/helpers.rb +14 -0
  57. data/lib/github_api/response/jsonize.rb +26 -0
  58. data/lib/github_api/response/mashify.rb +24 -0
  59. data/lib/github_api/response/raise_error.rb +33 -0
  60. data/lib/github_api/result.rb +42 -0
  61. data/lib/github_api/users.rb +84 -0
  62. data/lib/github_api/users/emails.rb +49 -0
  63. data/lib/github_api/users/followers.rb +98 -0
  64. data/lib/github_api/users/keys.rb +84 -0
  65. data/lib/github_api/version.rb +12 -0
  66. data/spec/README.rdoc +22 -0
  67. data/spec/coverage_adapter.rb +15 -0
  68. data/spec/fixtures/auths/authorization.json +14 -0
  69. data/spec/fixtures/auths/authorizations.json +16 -0
  70. data/spec/fixtures/events/events.json +29 -0
  71. data/spec/fixtures/issues/comment.json +13 -0
  72. data/spec/fixtures/issues/comments.json +15 -0
  73. data/spec/fixtures/issues/event.json +13 -0
  74. data/spec/fixtures/issues/events.json +15 -0
  75. data/spec/fixtures/issues/issue.json +56 -0
  76. data/spec/fixtures/issues/issues.json +58 -0
  77. data/spec/fixtures/issues/milestone.json +18 -0
  78. data/spec/fixtures/issues/milestones.json +20 -0
  79. data/spec/fixtures/orgs/members.json +9 -0
  80. data/spec/fixtures/orgs/org.json +18 -0
  81. data/spec/fixtures/orgs/orgs.json +8 -0
  82. data/spec/fixtures/orgs/team.json +8 -0
  83. data/spec/fixtures/orgs/team_repos.json +29 -0
  84. data/spec/fixtures/orgs/teams.json +7 -0
  85. data/spec/fixtures/repos/branches.json +9 -0
  86. data/spec/fixtures/repos/collaborators.json +8 -0
  87. data/spec/fixtures/repos/commit.json +53 -0
  88. data/spec/fixtures/repos/commit_comment.json +16 -0
  89. data/spec/fixtures/repos/commit_comments.json +18 -0
  90. data/spec/fixtures/repos/commits.json +27 -0
  91. data/spec/fixtures/repos/contributors.json +8 -0
  92. data/spec/fixtures/repos/download.json +10 -0
  93. data/spec/fixtures/repos/download_s3.json +21 -0
  94. data/spec/fixtures/repos/downloads.json +12 -0
  95. data/spec/fixtures/repos/fork.json +27 -0
  96. data/spec/fixtures/repos/forks.json +29 -0
  97. data/spec/fixtures/repos/hook.json +15 -0
  98. data/spec/fixtures/repos/hooks.json +10 -0
  99. data/spec/fixtures/repos/key.json +6 -0
  100. data/spec/fixtures/repos/keys.json +8 -0
  101. data/spec/fixtures/repos/languages.json +4 -0
  102. data/spec/fixtures/repos/repo.json +90 -0
  103. data/spec/fixtures/repos/repo_comments.json +18 -0
  104. data/spec/fixtures/repos/repos.json +29 -0
  105. data/spec/fixtures/repos/tags.json +11 -0
  106. data/spec/fixtures/repos/teams.json +7 -0
  107. data/spec/fixtures/repos/watched.json +29 -0
  108. data/spec/fixtures/repos/watchers.json +8 -0
  109. data/spec/fixtures/users/user.json +32 -0
  110. data/spec/github/api_spec.rb +25 -0
  111. data/spec/github/authorization_spec.rb +176 -0
  112. data/spec/github/authorizations_spec.rb +242 -0
  113. data/spec/github/client_spec.rb +50 -0
  114. data/spec/github/core_ext/hash_spec.rb +44 -0
  115. data/spec/github/events_spec.rb +491 -0
  116. data/spec/github/gists/comments_spec.rb +5 -0
  117. data/spec/github/gists_spec.rb +5 -0
  118. data/spec/github/git_data/blobs_spec.rb +5 -0
  119. data/spec/github/git_data/commits_spec.rb +5 -0
  120. data/spec/github/git_data/references_spec.rb +5 -0
  121. data/spec/github/git_data/tags_spec.rb +5 -0
  122. data/spec/github/git_data/trees_spec.rb +5 -0
  123. data/spec/github/git_data_spec.rb +5 -0
  124. data/spec/github/issues/comments_spec.rb +254 -0
  125. data/spec/github/issues/events_spec.rb +153 -0
  126. data/spec/github/issues/labels_spec.rb +5 -0
  127. data/spec/github/issues/milestones_spec.rb +260 -0
  128. data/spec/github/issues_spec.rb +287 -0
  129. data/spec/github/mime_type_spec.rb +70 -0
  130. data/spec/github/orgs/members_spec.rb +275 -0
  131. data/spec/github/orgs/teams_spec.rb +563 -0
  132. data/spec/github/orgs_spec.rb +160 -0
  133. data/spec/github/repos/collaborators_spec.rb +169 -0
  134. data/spec/github/repos/commits_spec.rb +424 -0
  135. data/spec/github/repos/downloads_spec.rb +247 -0
  136. data/spec/github/repos/forks_spec.rb +108 -0
  137. data/spec/github/repos/hooks_spec.rb +333 -0
  138. data/spec/github/repos/keys_spec.rb +217 -0
  139. data/spec/github/repos/pub_sub_hubbub_spec.rb +83 -0
  140. data/spec/github/repos/watching_spec.rb +222 -0
  141. data/spec/github/repos_spec.rb +571 -0
  142. data/spec/github/result_spec.rb +43 -0
  143. data/spec/github/users_spec.rb +140 -0
  144. data/spec/github_spec.rb +109 -0
  145. data/spec/spec_helper.rb +86 -0
  146. data/spec/support/base.rb +13 -0
  147. metadata +149 -4
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class Issues
5
+ module Events
6
+
7
+ # List events for an issue
8
+ #
9
+ # = Examples
10
+ # @github = Github.new
11
+ # @github.issues.events 'user-name', 'repo-name', 'issue-id'
12
+ #
13
+ # List events for a repository
14
+ #
15
+ # = Examples
16
+ # @github = Github.new
17
+ # @github.issues.events 'user-name', 'repo-name'
18
+ #
19
+ def events(user_name=nil, repo_name=nil, issue_id=nil, params={})
20
+ _update_user_repo_params(user_name, repo_name)
21
+ _validate_user_repo_params(user, repo) unless user? && repo?
22
+ _normalize_params_keys(params)
23
+
24
+ response = if issue_id
25
+ get("/repos/#{user}/#{repo}/issues/#{issue_id}/events", params)
26
+ else
27
+ get("/repos/#{user}/#{repo}/issues/events", params)
28
+ end
29
+ return response unless block_given?
30
+ response.each { |el| yield el }
31
+ end
32
+ alias :list_events :events
33
+ alias :issue_events :events
34
+ alias :repo_events :events
35
+
36
+ # Get a single event
37
+ #
38
+ # = Examples
39
+ # @github = Github.new
40
+ # @github.issues.event 'user-name', 'repo-name', 'event-id'
41
+ #
42
+ def event(user_name, repo_name, event_id, params={})
43
+ _update_user_repo_params(user_name, repo_name)
44
+ _validate_user_repo_params(user, repo) unless user? && repo?
45
+ _validate_presence_of event_id
46
+ _normalize_params_keys(params)
47
+
48
+ get("/repos/#{user}/#{repo}/issues/events/#{event_id}")
49
+ end
50
+ alias :get_event :event
51
+
52
+ end # Events
53
+ end # Issues
54
+ end # Github
@@ -0,0 +1,191 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class Issues
5
+ module Labels
6
+
7
+ VALID_LABEL_INPUTS = %w[ name color ]
8
+
9
+ # List all labels for a repository
10
+ #
11
+ # = Examples
12
+ # @github = Github.new :user => 'user-name', :repo => 'repo-name'
13
+ # @github.issues.labels
14
+ # @github.issues.labels { |label| ... }
15
+ #
16
+ def labels(user_name=nil, repo_name=nil, params={})
17
+ _update_user_repo_params(user_name, repo_name)
18
+ _validate_user_repo_params(user, repo) unless user? && repo?
19
+ _normalize_params_keys(params)
20
+
21
+ response = get("/repos/#{user}/#{repo}/labels", params)
22
+ return response unless block_given?
23
+ response.each { |el| yield el }
24
+ end
25
+
26
+ # Get a single label
27
+ #
28
+ # = Examples
29
+ # @github = Github.new
30
+ # @github.issues.label 'user-name', 'repo-name', 'label-id'
31
+ #
32
+ def label(user_name, repo_name, label_id, params={})
33
+ _update_user_repo_params(user_name, repo_name)
34
+ _validate_user_repo_params(user, repo) unless user? && repo?
35
+ _normalize_params_keys(params)
36
+
37
+ get("/repos/#{user}/#{repo}/labels/#{label_id}", params)
38
+ end
39
+
40
+ # Create a label
41
+ #
42
+ # = Inputs
43
+ # <tt>:name</tt> - Required string
44
+ # <tt>:color</tt> - Required string - 6 character hex code, without leading #
45
+ #
46
+ # = Examples
47
+ # @github = Github.new :user => 'user-name', :repo => 'repo-name'
48
+ # @github.issues.create_label :name => 'API', :color => 'FFFFFF'
49
+ #
50
+ def create_label(user_name=nil, repo_name=nil, params={})
51
+ _update_user_repo_params(user_name, repo_name)
52
+ _validate_user_repo_params(user, repo) unless user? && repo?
53
+
54
+ _normalize_params_keys(params)
55
+ _filter_params_keys(VALID_LABEL_INPUTS, params)
56
+
57
+ raise ArgumentError, "Required params are: :name, :color" unless _validate_inputs(VALID_LABEL_INPUTS, params)
58
+
59
+ post("/repos/#{user}/#{repo}/labels", params)
60
+ end
61
+
62
+ # Update a label
63
+ #
64
+ # = Inputs
65
+ # <tt>:name</tt> - Required string
66
+ # <tt>:color</tt> - Required string - 6 character hex code, without leading #
67
+ #
68
+ # = Examples
69
+ # @github = Github.new
70
+ # @github.issues.update_label 'user-name', 'repo-name', 'label-id', :name => 'API', :color => "FFFFFF"
71
+ #
72
+ def update_label(user_name, repo_name, label_id, params={})
73
+ _update_user_repo_params(user_name, repo_name)
74
+ _validate_user_repo_params(user, repo) unless user? && repo?
75
+ _validate_presence_of label_id
76
+
77
+ _normalize_params_keys(params)
78
+ _filter_params_keys(VALID_LABEL_INPUTS, params)
79
+
80
+ raise ArgumentError, "Required params are: :name, :color" unless _validate_inputs(VALID_LABEL_INPUTS, params)
81
+
82
+ patch("/repos/#{user}/#{repo}/labels/#{label_id}", params)
83
+ end
84
+
85
+ # Delete a label
86
+ #
87
+ # = Examples
88
+ # @github = Github.new
89
+ # @github.issues.delete_label 'user-name', 'repo-name', 'label-id'
90
+ #
91
+ def delete_label(user_name, repo_name, label_id, params={})
92
+ _update_user_repo_params(user_name, repo_name)
93
+ _validate_user_repo_params(user, repo) unless user? && repo?
94
+ _validate_presence_of milestone_id
95
+ _normalize_params_keys(params)
96
+
97
+ delete("/repos/#{user}/#{repo}/labels/#{label_id}", params)
98
+ end
99
+
100
+ # List labels on an issue
101
+ #
102
+ # = Examples
103
+ # @github = Github.new
104
+ # @github.issues.labels_for 'user-name', 'repo-name', 'issue-id'
105
+ #
106
+ def labels_for(user_name, repo_name, issue_id, params={})
107
+ _update_user_repo_params(user_name, repo_name)
108
+ _validate_user_repo_params(user, repo) unless user? && repo?
109
+ _validate_presence_of(issue_id)
110
+ _normalize_params_keys(params)
111
+
112
+ get("/repos/#{user}/#{repo}/issues/#{issue_id}/labels", params)
113
+ end
114
+
115
+ # Add labels to an issue
116
+ #
117
+ # = Examples
118
+ # @github = Github.new
119
+ # @github.issues.add_labels 'user-name', 'repo-name', 'issue-id', 'label1', 'label2', ...
120
+ #
121
+ def add_labels(user_name, repo_name, issue_id, *args)
122
+ params = args.last.is_a?(Hash) ? args.pop : {}
123
+ params['data'] = [args].flatten unless args.nil?
124
+ _update_user_repo_params(user_name, repo_name)
125
+ _validate_user_repo_params(user, repo) unless user? && repo?
126
+ _validate_presence_of(issue_id)
127
+ _normalize_params_keys(params)
128
+
129
+ post("/repos/#{user}/#{repo}/issues/#{issue_id}/labels", params)
130
+ end
131
+
132
+ # Remove a label from an issue
133
+ #
134
+ # = Examples
135
+ # @github = Github.new
136
+ # @github.issues.remove_label 'user-name', 'repo-name', 'issue-id', 'label-id'
137
+ #
138
+ # Remove all labels from an issue
139
+ # = Examples
140
+ # @github = Github.new
141
+ # @github.issues.remove_label 'user-name', 'repo-name', 'issue-id'
142
+ #
143
+ def remove_label(user_name, repo_name, issue_id, label_id=nil, params={})
144
+ _update_user_repo_params(user_name, repo_name)
145
+ _validate_user_repo_params(user, repo) unless user? && repo?
146
+ _validate_presence_of(issue_id)
147
+ _normalize_params_keys(params)
148
+
149
+ if label_id
150
+ delete("/repos/#{user}/#{repo}/issues/#{issue_id}/labels/#{label_id}", params)
151
+ else
152
+ delete("/repos/#{user}/#{repo}/issues/#{issue_id}/labels", params)
153
+ end
154
+ end
155
+
156
+ # Replace all labels for an issue
157
+ #
158
+ # Sending an empty array ([]) will remove all Labels from the Issue.
159
+ #
160
+ # = Examples
161
+ # @github = Github.new
162
+ # @github.issues.replace_labels 'user-name', 'repo-name', 'issue-id', 'label1', 'label2', ...
163
+ #
164
+ def replace_labels(user_name, repo_name, issue_id, *args)
165
+ params = args.last.is_a?(Hash) ? args.pop : {}
166
+ params['data'] = [args].flatten unless args.nil?
167
+ _update_user_repo_params(user_name, repo_name)
168
+ _validate_user_repo_params(user, repo) unless user? && repo?
169
+ _validate_presence_of(issue_id)
170
+ _normalize_params_keys(params)
171
+
172
+ put("/repos/#{user}/#{repo}/issues/#{issue_id}/labels", params)
173
+ end
174
+
175
+ # Get labels for every issue in a milestone
176
+ #
177
+ # = Examples
178
+ # @github = Github.new
179
+ # @github.issues.get_label 'user-name', 'repo-name', 'milestone-id'
180
+ #
181
+ def get_label(user_name, repo_name, milestone_id, params={})
182
+ _update_user_repo_params(user_name, repo_name)
183
+ _validate_user_repo_params(user, repo) unless user? && repo?
184
+ _validate_presence_of(issue_id)
185
+
186
+ get("/repos/#{user}/#{repo}/milestones/#{milestone_id}/labels", params)
187
+ end
188
+
189
+ end # Labels
190
+ end # Issues
191
+ end # Github
@@ -0,0 +1,140 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class Issues
5
+ module Milestones
6
+
7
+ VALID_MILESTONE_OPTIONS = {
8
+ 'state' => %w[ open closed ],
9
+ 'sort' => %w[ due_date completeness ],
10
+ 'direction' => %w[ desc asc ]
11
+ }.freeze # :nodoc:
12
+
13
+ VALID_MILESTONE_INPUTS = %w[
14
+ title
15
+ state
16
+ description
17
+ due_on
18
+ ].freeze # :nodoc:
19
+
20
+ # List milestones for a repository
21
+ #
22
+ # = Parameters
23
+ # <tt>:state</tt> - <tt>open</tt>, <tt>closed</tt>, default: <tt>open</tt>
24
+ # <tt>:sort</tt> - <tt>due_date</tt>, <tt>completeness</tt>, default: <tt>due_date</tt>
25
+ # <tt>:direction</tt> - <tt>asc</tt>, <tt>desc</tt>, default: <tt>desc</tt>
26
+ #
27
+ # = Examples
28
+ # @github = Github.new :user => 'user-name', :repo => 'repo-name'
29
+ # @github.issues.milestones
30
+ #
31
+ # or
32
+ #
33
+ # @github.issues.milestones :state => 'open',
34
+ # :sort => 'due_date',
35
+ # :direction => 'asc'
36
+ #
37
+ def milestones(user_name=nil, repo_name=nil, params={})
38
+ _update_user_repo_params(user_name, repo_name)
39
+ _validate_user_repo_params(user, repo) unless user? && repo?
40
+
41
+ _normalize_params_keys(params)
42
+ _filter_params_keys(VALID_MILESTONE_OPTIONS.keys, params)
43
+ _validate_params_values(VALID_MILESTONE_OPTIONS, params)
44
+
45
+ response = get("/repos/#{user}/#{repo}/milestones", params)
46
+ return response unless block_given?
47
+ response.each { |el| yield el }
48
+ end
49
+ alias :list_milestones :milestones
50
+
51
+ # Get a single milestone
52
+ #
53
+ # = Examples
54
+ # @github = Github.new
55
+ # @github.issues.milestone 'user-name', 'repo-name', 'milestone-id'
56
+ #
57
+ def milestone(user_name, repo_name, milestone_id, params={})
58
+ _update_user_repo_params(user_name, repo_name)
59
+ _validate_user_repo_params(user, repo) unless user? && repo?
60
+ _validate_presence_of milestone_id
61
+ _normalize_params_keys(params)
62
+
63
+ get("/repos/#{user}/#{repo}/milestones/#{milestone_id}", params)
64
+ end
65
+ alias :get_milestone :milestone
66
+
67
+ # Create a milestone
68
+ #
69
+ # = Inputs
70
+ # <tt>:title</tt> - Required string
71
+ # <tt>:state</tt> - Optional string - <tt>open</tt> or <tt>closed</tt>
72
+ # <tt>:description</tt> - Optional string
73
+ # <tt>:due_on</tt> - Optional string - ISO 8601 time
74
+ #
75
+ # = Examples
76
+ # @github = Github.new :user => 'user-name', :repo => 'repo-name'
77
+ # @github.issues.create_milestone :title => 'hello-world',
78
+ # :state => "open or closed",
79
+ # :description => "String",
80
+ # :due_on => "Time"
81
+ #
82
+ def create_milestone(user_name=nil, repo_name=nil, params={})
83
+ _update_user_repo_params(user_name, repo_name)
84
+ _validate_user_repo_params(user, repo) unless user? && repo?
85
+
86
+ _normalize_params_keys(params)
87
+ _filter_params_keys(VALID_MILESTONE_INPUTS, params)
88
+
89
+ raise ArgumentError, "Required params are: :title" unless _validate_inputs(%w[ title ], params)
90
+
91
+ post("/repos/#{user}/#{repo}/milestones", params)
92
+ end
93
+
94
+ # Update a milestone
95
+ #
96
+ # = Inputs
97
+ # <tt>:title</tt> - Required string
98
+ # <tt>:state</tt> - Optional string - <tt>open</tt> or <tt>closed</tt>
99
+ # <tt>:description</tt> - Optional string
100
+ # <tt>:due_on</tt> - Optional string - ISO 8601 time
101
+ #
102
+ # = Examples
103
+ # @github = Github.new
104
+ # @github.issues.update_milestone 'user-name', 'repo-name', 'milestone-id',
105
+ # :title => 'hello-world',
106
+ # :state => "open or closed",
107
+ # :description => "String",
108
+ # :due_on => "Time"
109
+ #
110
+ def update_milestone(user_name, repo_name, milestone_id, params={})
111
+ _update_user_repo_params(user_name, repo_name)
112
+ _validate_user_repo_params(user, repo) unless user? && repo?
113
+ _validate_presence_of milestone_id
114
+
115
+ _normalize_params_keys(params)
116
+ _filter_params_keys(VALID_MILESTONE_INPUTS, params)
117
+
118
+ raise ArgumentError, "Required params are: :title" unless _validate_inputs(%w[ title ], params)
119
+
120
+ patch("/repos/#{user}/#{repo}/milestones/#{milestone_id}", params)
121
+ end
122
+
123
+ # Delete a milestone
124
+ #
125
+ # = Examples
126
+ # @github = Github.new
127
+ # @github.issues.delete_milestone 'user-name', 'repo-name', 'milestone-id'
128
+ #
129
+ def delete_milestone(user_name, repo_name, milestone_id, params={})
130
+ _update_user_repo_params(user_name, repo_name)
131
+ _validate_user_repo_params(user, repo) unless user? && repo?
132
+ _validate_presence_of milestone_id
133
+ _normalize_params_keys(params)
134
+
135
+ delete("/repos/#{user}/#{repo}/milestones/#{milestone_id}", params)
136
+ end
137
+
138
+ end # Milestones
139
+ end # Issues
140
+ end # Github
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ module MimeType
5
+
6
+ attr_accessor :accepts
7
+
8
+ RESOURCE_LOOKUP = {
9
+ :json => 'json',
10
+ :issue => 'vnd.github-issue.',
11
+ :issue_comment => 'vnd.github-issuecomment.',
12
+ :commit_comment => 'vnd.github-commitcomment.',
13
+ :pull_request => 'vnd.github-pull.',
14
+ :pull_comment => 'vnd.github-pullcomment.',
15
+ :gist_comment => 'vnd.github-gistcomment.',
16
+ :blob => 'vnd.github-blob.'
17
+ }
18
+
19
+ MIME_LOOKUP = {
20
+ :json => 'json',
21
+ :blob => 'raw',
22
+ :raw => 'raw+json',
23
+ :text => 'text+json',
24
+ :html => 'html+json',
25
+ :full => 'full+json'
26
+ }
27
+
28
+ def parse(resource = nil, mime_type = :json)
29
+ resource = lookup_resource(resource) if resource
30
+ mime_type = lookup_mime(mime_type)
31
+ self.accepts = "application/#{resource || ''}#{mime_type}"
32
+ end
33
+
34
+ def lookup_resource(name)
35
+ RESOURCE_LOOKUP.fetch(name)
36
+ end
37
+
38
+ def lookup_mime(name)
39
+ MIME_LOOKUP.fetch(name)
40
+ end
41
+
42
+ def _normalize_name(name)
43
+ puts "NAME: #{name}"
44
+ case name
45
+ when String
46
+ name.strip.downcase.to_sym
47
+ when Symbol
48
+ name
49
+ else
50
+ raise ArgumentError, 'Provided MIME Type is not a valid or recognized entry'
51
+ end
52
+ end
53
+
54
+ end # MimeType
55
+ end # Github
@@ -0,0 +1,95 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class Orgs < API
5
+ extend AutoloadHelper
6
+
7
+ autoload_all 'github_api/orgs',
8
+ :Members => 'members',
9
+ :Teams => 'teams'
10
+
11
+ include Github::Orgs::Members
12
+ include Github::Orgs::Teams
13
+
14
+ VALID_ORG_PARAM_NAMES = %w[
15
+ billing_email
16
+ company
17
+ email
18
+ location
19
+ name
20
+ ].freeze
21
+
22
+ # Creates new Orgs API
23
+ def initialize(options = {})
24
+ super(options)
25
+ end
26
+
27
+ # List all public organizations for a user.
28
+ #
29
+ # = Examples
30
+ # @github = Github.new :user => 'user-name'
31
+ # @github.orgs.orgs
32
+ #
33
+ # List public and private organizations for the authenticated user.
34
+ #
35
+ # @github = Github.new :oauth_token => '..'
36
+ # @github.orgs.orgs 'github'
37
+ #
38
+ def orgs(user_name=nil, params={})
39
+ _update_user_repo_params(user_name)
40
+ _normalize_params_keys(params)
41
+
42
+ response = if user?
43
+ get("/users/#{user}/orgs", params)
44
+ else
45
+ get("/user/orgs", params)
46
+ end
47
+ return response unless block_given?
48
+ response.each { |el| yield el }
49
+ end
50
+ alias :list_orgs :orgs
51
+ alias :list_organizations :orgs
52
+
53
+ # Get properties for a single organization
54
+ #
55
+ # = Examples
56
+ # @github = Github.new
57
+ # @github.orgs.org 'github'
58
+ #
59
+ def org(org_name, params={})
60
+ _validate_presence_of org_name
61
+ get("/orgs/#{org_name}", params)
62
+ end
63
+ alias :get_org :org
64
+ alias :organisation :org
65
+
66
+ # Edit organization
67
+ #
68
+ # = Parameters
69
+ # <tt>:billing_email</tt> - Optional string - Billing email address. This address is not publicized.
70
+ # <tt>:company</tt> - Optional string
71
+ # <tt>:email</tt> - Optional string
72
+ # <tt>:location</tt> - Optional string
73
+ # <tt>:name</tt> - Optional string
74
+ #
75
+ # = Examples
76
+ # @github = Github.new :oauth_token => '...'
77
+ # @github.orgs.edit_org 'github',
78
+ # "billing_email" => "support@github.com",
79
+ # "blog" => "https://github.com/blog",
80
+ # "company" => "GitHub",
81
+ # "email" => "support@github.com",
82
+ # "location" => "San Francisco",
83
+ # "name" => "github"
84
+ #
85
+ def edit_org(org_name, params={})
86
+ _validate_presence_of org_name
87
+ _normalize_params_keys(params)
88
+ _filter_params_keys(VALID_ORG_PARAM_NAMES, params)
89
+
90
+ patch("/orgs/#{org_name}", params)
91
+ end
92
+ alias :edit_organization :edit_org
93
+
94
+ end # Orgs
95
+ end # Github