github_api_v3 0.1.0 → 0.2.0

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 (65) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/README.md +132 -29
  4. data/lib/github_api_v3/client/gists.rb +75 -5
  5. data/lib/github_api_v3/client/gitignore.rb +33 -0
  6. data/lib/github_api_v3/client/markdown.rb +29 -0
  7. data/lib/github_api_v3/client/repos.rb +8 -5
  8. data/lib/github_api_v3/client/users.rb +3 -3
  9. data/lib/github_api_v3/client.rb +100 -8
  10. data/lib/github_api_v3/default.rb +5 -0
  11. data/lib/github_api_v3/error.rb +13 -0
  12. data/lib/github_api_v3/version.rb +1 -1
  13. data/spec/cassettes/GitHub_Client_Gists/_create_delete_gist/creates_a_gist.json +1 -1
  14. data/spec/cassettes/GitHub_Client_Gists/_create_delete_gist/deletes_a_gist.json +1 -1
  15. data/spec/cassettes/GitHub_Client_Gists/_create_gist_comment/creates_the_comment.json +1 -0
  16. data/spec/cassettes/GitHub_Client_Gists/_create_gist_comment/returns_comment_information_after_creation.json +1 -0
  17. data/spec/cassettes/GitHub_Client_Gists/_delete_gist_comment/deletes_the_comment.json +1 -0
  18. data/spec/cassettes/GitHub_Client_Gists/_delete_gist_comment/returns_true_or_false.json +1 -0
  19. data/spec/cassettes/GitHub_Client_Gists/_edit_gist_comment/edits_the_comment.json +1 -0
  20. data/spec/cassettes/GitHub_Client_Gists/_edit_gist_comment/returns_comment_information_after_editing.json +1 -0
  21. data/spec/cassettes/GitHub_Client_Gists/_fork_gist/forks_a_gist.json +1 -1
  22. data/spec/cassettes/GitHub_Client_Gists/_fork_gist/returns_false_when_not_found.json +1 -0
  23. data/spec/cassettes/GitHub_Client_Gists/_gist/returns_a_404_when_not_found.json +1 -0
  24. data/spec/cassettes/GitHub_Client_Gists/_gist_comment/returns_a_404_when_not_found.json +1 -0
  25. data/spec/cassettes/GitHub_Client_Gists/_gist_comment/returns_a_comment.json +1 -0
  26. data/spec/cassettes/GitHub_Client_Gists/_gist_comments/returns_a_404_when_not_found.json +1 -0
  27. data/spec/cassettes/GitHub_Client_Gists/_gist_comments/returns_a_list_of_comments.json +1 -0
  28. data/spec/cassettes/GitHub_Client_Gists/_gist_starred_/returns_false_when_not_found.json +1 -0
  29. data/spec/cassettes/GitHub_Client_Gists/_gist_starred_/should_return_true_or_false.json +1 -1
  30. data/spec/cassettes/GitHub_Client_Gists/_star_gist/returns_false_when_not_found.json +1 -0
  31. data/spec/cassettes/GitHub_Client_Gists/_star_gist/stars_a_gist.json +1 -1
  32. data/spec/cassettes/GitHub_Client_Gists/_unstar_gist/returns_false_when_not_found.json +1 -0
  33. data/spec/cassettes/GitHub_Client_Gists/_unstar_gist/unstars_a_gist.json +1 -1
  34. data/spec/cassettes/GitHub_Client_Gitignore/_gitignore/returns_a_hash.json +1 -0
  35. data/spec/cassettes/GitHub_Client_Gitignore/_gitignore/returns_the_correct_template.json +1 -0
  36. data/spec/cassettes/GitHub_Client_Gitignore/_gitignore_list/returns_an_array_of_templates.json +1 -0
  37. data/spec/cassettes/GitHub_Client_Markdown/_markdown/returns_rendered_markdown.json +1 -0
  38. data/spec/cassettes/GitHub_Client_Repos/_add_remove_collaborator/adds_a_collaborator.json +1 -1
  39. data/spec/cassettes/GitHub_Client_Repos/_add_remove_collaborator/removes_a_collaborator.json +1 -1
  40. data/spec/cassettes/GitHub_Client_Repos/_branch/returns_a_404_if_repo_not_found.json +1 -0
  41. data/spec/cassettes/GitHub_Client_Repos/_collaborator_/returns_a_boolean.json +1 -1
  42. data/spec/cassettes/GitHub_Client_Repos/_collaborators/returns_a_404_if_repo_not_found.json +1 -0
  43. data/spec/cassettes/GitHub_Client_Repos/_contributors/returns_a_404_if_repo_not_found.json +1 -0
  44. data/spec/cassettes/GitHub_Client_Repos/_create_repo/returns_unauthorized_when_not_authorized.json +1 -0
  45. data/spec/cassettes/GitHub_Client_Repos/_delete_repo/deletes_a_repo.json +1 -1
  46. data/spec/cassettes/GitHub_Client_Repos/_delete_repo/returns_false_if_not_authorized.json +1 -0
  47. data/spec/cassettes/GitHub_Client_Repos/_delete_repo/returns_false_when_not_found.json +1 -0
  48. data/spec/cassettes/GitHub_Client_Repos/_delete_repo/returns_unauthorized_if_not_authorized.json +1 -0
  49. data/spec/cassettes/GitHub_Client_Repos/_languages/returns_a_404_if_repo_not_found.json +1 -0
  50. data/spec/cassettes/GitHub_Client_Repos/_org_repos/returns_a_404_if_not_found.json +1 -0
  51. data/spec/cassettes/GitHub_Client_Repos/_org_repos/returns_a_404_if_repo_not_found.json +1 -0
  52. data/spec/cassettes/GitHub_Client_Repos/_tags/returns_a_404_if_repo_not_found.json +1 -0
  53. data/spec/cassettes/GitHub_Client_Users/_events/returns_a_404_for_user_not_found.json +1 -0
  54. data/spec/cassettes/GitHub_Client_Users/_follow/follows_a_user.json +1 -1
  55. data/spec/cassettes/GitHub_Client_Users/_follows_/returns_false_when_not_following.json +1 -0
  56. data/spec/cassettes/GitHub_Client_Users/_follows_/{returns_a_boolean.json → returns_true_when_following.json} +1 -1
  57. data/spec/cassettes/GitHub_Client_Users/_unfollow/unfollows_a_user.json +1 -1
  58. data/spec/cassettes/GitHub_Client_Users/_user/returns_a_404_if_user_not_found.json +1 -0
  59. data/spec/cassettes/GitHub_Client_Users/keys/returns_404_for_user_not_found.json +1 -0
  60. data/spec/github_api_v3/client/gists_spec.rb +83 -0
  61. data/spec/github_api_v3/client/gitignore_spec.rb +23 -0
  62. data/spec/github_api_v3/client/markdown_spec.rb +12 -0
  63. data/spec/github_api_v3/client/repos_spec.rb +37 -1
  64. data/spec/github_api_v3/client/users_spec.rb +20 -5
  65. metadata +77 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 971067aab5382fac16ce777598632fc15e967a90
4
- data.tar.gz: ef210e058a8dcf7e83e7bbf500ab8c469aafbf69
3
+ metadata.gz: bd0406fd884e781cfdc83e36808666c83cad39e4
4
+ data.tar.gz: f4a3414547c49f1c6eb4ca040bb968b6a9a2a92a
5
5
  SHA512:
6
- metadata.gz: 437519533b96ab76c076e91562a171fe1b84c9fa425c7f10c3e31cc814cb5a011c1e35a8b96b6df0938411b0aed95e02a040a5dcf7f5078013e8734d5cc2e118
7
- data.tar.gz: a3af2b6ba0563b841b447b57c96956f94be30d78edf3a4043378bb67d257b5ccc94b775bde27f474392f63a9669fa43a73776211cad0e309ab35eed486f4c697
6
+ metadata.gz: 29f439a47344bae930b71495dea13f84a8f5da4558a75e71d09e4cac398b74d804a64aac0b2756557a162c99fe9e2a1fe3cce34258d34d7dbc90a635c6753001
7
+ data.tar.gz: 1c4e26602951983561dab72d654d826ce6d07b27808002ffeeb33b95ef79d8fdfa6aa4cbc848642b9bdc44cb0feaa253ab1d6b625aca704a2f53a18693f14f2b
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --color
2
2
  --format progress
3
+ --order default
data/README.md CHANGED
@@ -4,8 +4,14 @@
4
4
 
5
5
  This is a simple wrapper for GitHub's v3 API. It is in the EARLY stages of development. Knowing a little about [GitHub's API](http://developer.github.com/) will aid in its use.
6
6
 
7
+ ## Documentation
8
+
9
+ Full documentation for the gem can be found at [rdoc.info/gems/github_api_v3/frames/index](http://rdoc.info/gems/github_api_v3/frames/index).
10
+
7
11
  ## Installation
8
12
 
13
+ To install the gem, issue the following command:
14
+
9
15
  ```bash
10
16
  $ gem install github_api_v3
11
17
  ```
@@ -14,72 +20,169 @@ $ gem install github_api_v3
14
20
 
15
21
  ```ruby
16
22
  require 'github_api_v3'
17
- # => true
18
23
  ```
19
24
 
20
25
  ### Unauthenticated Requests
21
26
 
22
- There are multiple different unauthenticated requests to the API. Examples are shown below.
27
+ There are multiple different unauthenticated requests to the API. These are performed when no credentials are given, and usually start with `GitHub`.
23
28
 
24
- #### User
25
29
 
26
- Returns a Hash containing information about a user.
30
+ ### Authenticated Requests
31
+
32
+ Some methods, such as retrieving private repos or emails, require authentication. To create one of these requests, you'll need to pass in your login and access token. You can create a personal access token on your [account page](https://github.com/settings/applications).
27
33
 
28
34
  ```ruby
35
+ client = GitHub::Client.new(login: 'username', access_token: 'abcdefghijklmnopqrstuvwxyz12345')
36
+ client.emails # => ["email@example.com", "email2@example.com"]
37
+ client.repos # => #<Array:0x007fb8aa0d1a00>
38
+ client.follow('matz') # => true
39
+ client.user # => #<Hash:0x007fb8a9109d70>
40
+ ```
41
+
42
+ Anytime a method is shown below starting with `client`, it is an authenticated method.
43
+
44
+ ### Sample usage
45
+
46
+ #### Users
47
+
48
+ The following are some sample usages of the Users module.
49
+
50
+ ```ruby
51
+ # Retrieve a single user
29
52
  user = GitHub.user('caseyscarborough')
30
53
  user.login # => "caseyscarborough"
31
54
  user.name # => "Casey Scarborough"
32
55
  user.html_url # => "https://github.com/caseyscarborough"
33
56
  user.following # => 23
34
- # etc...
35
- ```
36
- You can find the available attributes [here](http://developer.github.com/v3/users/#get-a-single-user).
37
57
 
38
- #### Events
58
+ # Retrieve an array of all GitHub users
59
+ GitHub.users
39
60
 
40
- Returns an array of events for a particular user.
61
+ # Get emails for authenticated user
62
+ client.emails
41
63
 
42
- ```ruby
43
- events = GitHub.events('caseyscarborough')
44
- events.each { |e| puts e.type }
45
- ```
64
+ # Follow/unfollow a user
65
+ client.follow('caseyscarborough')
66
+ client.unfollow('caseyscarborough')
46
67
 
47
- #### Followers
68
+ # Check if a user follows another user
69
+ GitHub.follows?('caseyscarborough','matz')
48
70
 
49
- Returns an array of followers for a user.
71
+ # Get a list of an unauthenticated user's followers
72
+ GitHub.followers('caseyscarborough')
50
73
 
51
- ```ruby
52
- followers = GitHub.followers('caseyscarborough')
53
- followers.each { |f| puts f.login }
74
+ # Get a list of an authenticated user's followers
75
+ client.followers
76
+
77
+ # Get a list of user's a user is following
78
+ GitHub.following('caseyscarborough')
79
+
80
+ # See if authenticated user is following another user
81
+ client.following?('caseyscarborough')
82
+
83
+ # Get events for a user
84
+ GitHub.events('caseyscarborough')
85
+
86
+ # etc...
54
87
  ```
88
+ You can find the available attributes [here](http://developer.github.com/v3/users/#get-a-single-user). Check the [Users documentation](http://rdoc.info/gems/github_api_v3/GitHub/Client/Users) for the gem for a complete list and more examples.
55
89
 
56
90
  #### Repositories
57
91
 
58
- Returns an array of repositories that belong to a user.
92
+ The following are some sample usages for the Repos module.
59
93
 
60
94
  ```ruby
61
- repos = GitHub.repos('caseyscarborough')
62
- repos.each { |r| puts r.name }
95
+ # Get repos for an unauthenticated/authenticated user
96
+ GitHub.repos('caseyscarborough')
97
+ client.repos
98
+
99
+ # Get all public repos on GitHub
100
+ GitHub.all_repos
101
+
102
+ # Get a specific repo
103
+ GitHub.repo('owner','repo-name')
104
+
105
+ # Create a repo
106
+ client.create_repo('new-repo', description: 'New repository.', private: true)
107
+
108
+ # Delete a repo
109
+ client.delete_repo('repo-name')
110
+
111
+ # Get a repository's contributors/languages/tags/branches/collaborators
112
+ GitHub.contributors('caseyscarborough','github')
113
+ GitHub.languages('caseyscarborough','github')
114
+ GitHub.tags('caseyscarborough','github')
115
+ GitHub.branches('caseyscarborough','github')
116
+ GitHub.collaborators('caseyscarborough','github')
117
+
118
+ # Get a specific branch
119
+ GitHub.branch('caseyscarborough','github','master')
120
+
121
+ # Add/remove collaborator
122
+ client.add_collaborator('owner','repo-name','user-to-add')
123
+ client.remove_collaborator('owner','repo-name','user-to-remove')
63
124
  ```
125
+ For a full list with descriptions, see the [Repos documentation](http://rdoc.info/gems/github_api_v3/GitHub/Client/Repos) for the gem.
64
126
 
65
- ### Authenticated Requests
127
+ #### Gists
66
128
 
67
- Some methods, such as retrieving private repos or emails, require authentication. To create one of these requests, you'll need to pass in your login and access token. You can create a personal access token on your [account page](https://github.com/settings/applications).
129
+ The following are sample uses for the Gists module.
68
130
 
69
131
  ```ruby
70
- client = GitHub::Client.new(login: 'username', access_token: 'abcdefghijklmnopqrstuvwxyz12345')
71
- client.emails # => ["email@example.com", "email2@example.com"]
72
- client.repos # => #<Array:0x007fb8aa0d1a00>
73
- client.follow('matz') # => true
74
- client.user # => #<Hash:0x007fb8a9109d70>
132
+ # Get all gists for a user
133
+ GitHub.gists('caseyscarborough')
134
+
135
+ # Get all gists for authenticated user
136
+ client.gists
137
+
138
+ # Get all public gists
139
+ GitHub.gists
140
+
141
+ # Get a gist by id
142
+ GitHub.gist(1234567)
143
+
144
+ # Create a gist
145
+ client.create_gist(
146
+ files: {"file1.txt" => { content: "File contents" }},
147
+ description: "Gist description",
148
+ public: "false"
149
+ )
150
+
151
+ # Check if a gist is starred
152
+ client.gist_starred?(1234567)
153
+
154
+ # Star/unstar/fork/delete a gist
155
+ client.star_gist(1234567)
156
+ client.unstar_gist(1234567)
157
+ client.fork_gist(1234567)
158
+ client.delete_gist(1234567)
75
159
  ```
160
+ Check out the [Gist documentation](http://rdoc.info/gems/github_api_v3/GitHub/Client/Gists) for more information.
161
+
162
+ ## Running the Test Suite
163
+
164
+ The test suite can be run by issuing the following command from the root of the directory:
76
165
 
77
- More functionality to come.
166
+ ```bash
167
+ $ rspec spec/
168
+ ```
78
169
 
79
170
  ## To Do
80
171
 
81
172
  The better question is... What's not to do? Any functionality of the API listed at [developer.github.com](http://developer.github.com/) that isn't currently in effect.
82
173
 
174
+ Some main missing functionality:
175
+ * A good bit of the [Repos API](http://developer.github.com/v3/repos/), such as:
176
+ * Comments
177
+ * Commits
178
+ * Hooks
179
+ * Forks
180
+ * etc.
181
+ * Markdown
182
+ * Editing Gists
183
+ * Editing Repos
184
+ * Updating User keys
185
+
83
186
  ## Contributing
84
187
 
85
188
  1. Fork it
@@ -1,6 +1,9 @@
1
1
  module GitHub
2
2
  class Client
3
3
 
4
+ # Contains methods for the Gists API.
5
+ #
6
+ # @see http://developer.github.com/v3/gists/
4
7
  module Gists
5
8
 
6
9
  # List gists.
@@ -60,7 +63,7 @@ module GitHub
60
63
  # @return [Boolean] True if it is starred, false if not.
61
64
  # @see http://developer.github.com/v3/gists/#check-if-a-gist-is-starred
62
65
  def gist_starred?(id)
63
- get "/gists/#{id}/star", auth_params, true
66
+ boolean_get "/gists/#{id}/star", auth_params
64
67
  end
65
68
 
66
69
  # Star a gist.
@@ -73,7 +76,7 @@ module GitHub
73
76
  # @example
74
77
  # client.star_gist(5928712)
75
78
  def star_gist(id)
76
- put "/gists/#{id}/star", auth_params, true
79
+ boolean_put "/gists/#{id}/star", auth_params
77
80
  end
78
81
 
79
82
  # Unstar a gist.
@@ -86,7 +89,7 @@ module GitHub
86
89
  # @example
87
90
  # client.unstar_gist(5928712)
88
91
  def unstar_gist(id)
89
- delete "/gists/#{id}/star", auth_params, true
92
+ boolean_delete "/gists/#{id}/star", auth_params
90
93
  end
91
94
 
92
95
  # Fork a gist.
@@ -99,7 +102,7 @@ module GitHub
99
102
  # @example
100
103
  # client.fork_gist(5928712)
101
104
  def fork_gist(id)
102
- post "/gists/#{id}/fork", auth_params, {}, true
105
+ boolean_post "/gists/#{id}/fork", auth_params, {}
103
106
  end
104
107
 
105
108
  # Delete a gist.
@@ -111,8 +114,75 @@ module GitHub
111
114
  # @example
112
115
  # client.delete_gist(5928712)
113
116
  def delete_gist(id)
114
- delete "/gists/#{id}", auth_params, true
117
+ boolean_delete "/gists/#{id}", auth_params
115
118
  end
119
+
120
+ # List comments on a gist.
121
+ #
122
+ # @param id [Integer] The Gist ID.
123
+ # @return [Array] An array of comments.
124
+ # @see http://developer.github.com/v3/gists/comments/#list-comments-on-a-gist
125
+ # @example
126
+ # GitHub.gist_comments(5928712)
127
+ def gist_comments(id)
128
+ get "/gists/#{id}/comments"
129
+ end
130
+
131
+ # Get a single comment on a gist.
132
+ #
133
+ # @param id [Integer] The Gist ID.
134
+ # @param comment_id [Integer] The comment ID.
135
+ # @return [Hash] The comment data.
136
+ # @see http://developer.github.com/v3/gists/comments/#get-a-single-comment
137
+ # @example
138
+ # GitHub.gist_comment(5928712, 889239)
139
+ def gist_comment(id, comment_id)
140
+ get "/gists/#{id}/comments/#{comment_id}"
141
+ end
142
+
143
+ # Create a gist comment.
144
+ #
145
+ # Requires authentication.
146
+ #
147
+ # @param id [Integer] The Gist ID.
148
+ # @param comment [String] The comment text.
149
+ # @return [Hash] The Gist information.
150
+ # @see http://developer.github.com/v3/gists/comments/#create-a-comment
151
+ # @example
152
+ # client.create_gist_comment(5928712, 'Awesome!')
153
+ def create_gist_comment(id, comment)
154
+ post "/gists/#{id}/comments", auth_params, { body: comment }
155
+ end
156
+
157
+ # Edit an existing gist comment.
158
+ #
159
+ # Requires authentication.
160
+ #
161
+ # @param id [Integer] The Gist ID.
162
+ # @param comment_id [Integer] The ID of the comment to edit.
163
+ # @param comment [String] The comment text.
164
+ # @return [Hash] The Gist information.
165
+ # @see http://developer.github.com/v3/gists/comments/#edit-a-comment
166
+ # @example
167
+ # client.edit_gist_comment(5928712, 889239, 'Even more awesome!')
168
+ def edit_gist_comment(id, comment_id, comment)
169
+ patch "/gists/#{id}/comments/#{comment_id}", auth_params, { body: comment }
170
+ end
171
+
172
+ # Delete a gist comment.
173
+ #
174
+ # Requires authentication.
175
+ #
176
+ # @param id [Integer] The Gist ID.
177
+ # @param comment_id [Integer] The ID of the comment to delete.
178
+ # @return [Boolean] True if successful, false if not.
179
+ # @see http://developer.github.com/v3/gists/comments/#delete-a-comment
180
+ # @example
181
+ # client.delete_gist_comment(5928712, 889239)
182
+ def delete_gist_comment(id, comment_id)
183
+ boolean_delete "/gists/#{id}/comments/#{comment_id}", auth_params
184
+ end
185
+
116
186
  end
117
187
 
118
188
  end
@@ -0,0 +1,33 @@
1
+ module GitHub
2
+ class Client
3
+
4
+ # Contains methods for the Gitignore API.
5
+ #
6
+ # @see http://developer.github.com/v3/gitignore/
7
+ module Gitignore
8
+
9
+ # Lists available .gitignore templates.
10
+ #
11
+ # @return [Array] List of template names.
12
+ # @see http://developer.github.com/v3/gitignore/#listing-available-templates
13
+ # @example
14
+ # GitHub.gitignore_list
15
+ def gitignore_list
16
+ get '/gitignore/templates'
17
+ end
18
+
19
+ # Gets a single .gitignore template.
20
+ #
21
+ # @param name [String] The template name.
22
+ # @return [String] The template contents.
23
+ # @see http://developer.github.com/v3/gitignore/#get-a-single-template
24
+ # @example
25
+ # GitHub.gitignore("Ruby")
26
+ def gitignore(name)
27
+ get "/gitignore/templates/#{name}"
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,29 @@
1
+ module GitHub
2
+ class Client
3
+
4
+ # Contains methods for the Markdown API.
5
+ #
6
+ # @see http://developer.github.com/v3/markdown/
7
+ module Markdown
8
+
9
+ # Render a markdown document.
10
+ #
11
+ # @param text [String] The Markdown text to render.
12
+ # @param options [Hash] The optional options.
13
+ # @option options [String] :mode The rendering mode.
14
+ # @option options [String] :context The repository context, only used when in 'gfm' mode.
15
+ # @return [String] The rendered text.
16
+ # @see http://developer.github.com/v3/markdown/#render-an-arbitrary-markdown-document
17
+ # @example
18
+ # GitHub.markdown('# Hello World! ## H2 **yeah**!')
19
+ # @example
20
+ # GitHub.markdown('# GitHub', mode: 'gfm', context: 'caseyscarborough/github')
21
+ def markdown(text, options={mode: 'markdown'})
22
+ options.merge!(text: text)
23
+ post "/markdown", {}, options
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+ end
@@ -1,6 +1,9 @@
1
1
  module GitHub
2
2
  class Client
3
3
 
4
+ # Contains methods for the Repos API.
5
+ #
6
+ # @see http://developer.github.com/v3/repos/
4
7
  module Repos
5
8
 
6
9
  # List all repositories
@@ -77,7 +80,7 @@ module GitHub
77
80
  # @example
78
81
  # client.delete_repo('repo-name')
79
82
  def delete_repo(owner, repo)
80
- delete "/repos/#{owner}/#{repo}", auth_params, true
83
+ boolean_delete "/repos/#{owner}/#{repo}", auth_params
81
84
  end
82
85
 
83
86
  # Get organization repositories.
@@ -135,7 +138,7 @@ module GitHub
135
138
  #
136
139
  # @param owner [String] Owner of repository.
137
140
  # @param repo [String] Repository name.
138
- # @return [Array] List of brances and their information.
141
+ # @return [Array] List of branches and their information.
139
142
  # @see http://developer.github.com/v3/repos/#list-branches
140
143
  # @example
141
144
  # GitHub.branches('caseyscarborough','github')
@@ -177,7 +180,7 @@ module GitHub
177
180
  # @example
178
181
  # GitHub.collaborator?('caseyscarborough','github','caseyscarborough')
179
182
  def collaborator?(owner, repo, user)
180
- get "/repos/#{owner}/#{repo}/collaborators/#{user}", {}, true
183
+ boolean_get "/repos/#{owner}/#{repo}/collaborators/#{user}"
181
184
  end
182
185
 
183
186
  # Add a collaborator to a repository.
@@ -189,7 +192,7 @@ module GitHub
189
192
  # @param user [String] User to add.
190
193
  # @see http://developer.github.com/v3/repos/collaborators/#add-collaborator
191
194
  def add_collaborator(owner, repo, user)
192
- put "/repos/#{owner}/#{repo}/collaborators/#{user}", auth_params, true
195
+ boolean_put "/repos/#{owner}/#{repo}/collaborators/#{user}", auth_params
193
196
  end
194
197
 
195
198
  # Remove a collaborator from a repository.
@@ -201,7 +204,7 @@ module GitHub
201
204
  # @param user [String] User to remove.
202
205
  # @see http://developer.github.com/v3/repos/collaborators/#remove-collaborator
203
206
  def remove_collaborator(owner, repo, user)
204
- delete "/repos/#{owner}/#{repo}/collaborators/#{user}", auth_params, true
207
+ boolean_delete "/repos/#{owner}/#{repo}/collaborators/#{user}", auth_params
205
208
  end
206
209
 
207
210
  end
@@ -54,7 +54,7 @@
54
54
  # @example
55
55
  # client.follow('caseyscarborough')
56
56
  def follow(username)
57
- put "/user/following/#{username}", auth_params, true
57
+ boolean_put "/user/following/#{username}", auth_params
58
58
  end
59
59
 
60
60
  # Checks to see if a user is following another user.
@@ -124,7 +124,7 @@
124
124
  # @example
125
125
  # client.unfollow('matz')
126
126
  def unfollow(username)
127
- delete "/user/following/#{username}", auth_params, true
127
+ boolean_delete "/user/following/#{username}", auth_params
128
128
  end
129
129
 
130
130
  # Get a list of public keys for a user.
@@ -166,7 +166,7 @@
166
166
  # @example
167
167
  # client.delete_key(123)
168
168
  def delete_key(id)
169
- delete "/user/keys/#{id}", auth_params, true
169
+ boolean_delete "/user/keys/#{id}", auth_params
170
170
  end
171
171
 
172
172
  def events(username)
@@ -2,16 +2,26 @@ require 'json'
2
2
  require 'github_api_v3/client/users'
3
3
  require 'github_api_v3/client/repos'
4
4
  require 'github_api_v3/client/gists'
5
+ require 'github_api_v3/client/markdown'
6
+ require 'github_api_v3/client/gitignore'
5
7
 
6
8
  module GitHub
9
+
10
+ # The main client for the API.
11
+ #
12
+ # @see http://developer.github.com/v3/
7
13
  class Client
8
14
 
9
15
  include HTTParty
16
+
17
+ # Default base uri for the API functionality.
10
18
  base_uri Default::API_ENDPOINT
11
19
 
12
20
  include GitHub::Client::Users
13
21
  include GitHub::Client::Repos
14
22
  include GitHub::Client::Gists
23
+ include GitHub::Client::Markdown
24
+ include GitHub::Client::Gitignore
15
25
 
16
26
  attr_reader :login, :access_token
17
27
 
@@ -23,38 +33,120 @@ module GitHub
23
33
 
24
34
  private
25
35
 
26
- def get(url, params={}, boolean=false)
36
+ # Perform a get request.
37
+ #
38
+ # @return [Hash, Array, String]
39
+ def get(url, params={})
27
40
  response = self.class.get url, query: params
28
41
  handle_response(response)
29
- boolean ? response.code == 204 : response.parsed_response
42
+ response.parsed_response
43
+ end
44
+
45
+ # Perform a get request with boolean return type.
46
+ #
47
+ # @return [Boolean]
48
+ def boolean_get(url, params={})
49
+ response = self.class.get url, query: params
50
+ response.code == 204
51
+ rescue GitHub::NotFound
52
+ false
30
53
  end
31
54
 
32
- def put(url, params={}, boolean=false)
55
+ # Perform a put request.
56
+ #
57
+ # @return [Hash, Array, String]
58
+ def put(url, params={})
33
59
  response = self.class.put url, query: params
34
60
  handle_response(response)
35
- boolean ? response.code == 204 : response.parsed_response
61
+ response.parsed_response
36
62
  end
37
63
 
38
- def post(url, params={}, body={}, boolean=false)
64
+ # Perform a put request with boolean return type.
65
+ #
66
+ # @return [Boolean]
67
+ def boolean_put(url, params={})
68
+ response = self.class.put url, query: params
69
+ response.code == 204
70
+ rescue GitHub::NotFound
71
+ false
72
+ end
73
+
74
+ # Perform a post request.
75
+ #
76
+ # @return [Hash, Array, String]
77
+ def post(url, params={}, body={})
39
78
  response = self.class.post url, query: params, body: body.to_json
40
79
  handle_response(response)
41
- boolean ? response.code == 204 : response.parsed_response
80
+ response.parsed_response
42
81
  end
43
82
 
44
- def delete(url, params={}, boolean=false)
83
+ # Perform a post request with boolean return type.
84
+ #
85
+ # @return [Boolean]
86
+ def boolean_post(url, params={}, body={})
87
+ response = self.class.post url, query: params, body: body.to_json
88
+ response.code == 204
89
+ rescue GitHub::NotFound
90
+ false
91
+ end
92
+
93
+ # Perform a patch request.
94
+ #
95
+ # @return [Hash, Array, String]
96
+ def patch(url, params={}, body={})
97
+ response = self.class.patch url, query: params, body: body.to_json
98
+ handle_response(response)
99
+ response.parsed_response
100
+ end
101
+
102
+ # Perform a patch request with boolean return type.
103
+ #
104
+ # @return [Boolean]
105
+ def boolean_patch(url, params={}, body={})
106
+ response = self.class.patch url, query: params, body: body.to_json
107
+ response.code == 204
108
+ rescue GitHub::NotFound
109
+ false
110
+ end
111
+
112
+ # Perform a delete request.
113
+ #
114
+ # @return [Hash, Array, String]
115
+ def delete(url, params={})
45
116
  response = self.class.delete url, query: params
46
117
  handle_response(response)
47
- boolean ? response.code == 204 : response.parsed_response
118
+ response.parsed_response
119
+ end
120
+
121
+ # Perform a delete request with boolean return type.
122
+ #
123
+ # @return [Boolean]
124
+ def boolean_delete(url, params={})
125
+ response = self.class.delete url, query: params
126
+ response.code == 204
127
+ rescue GitHub::NotFound
128
+ false
48
129
  end
49
130
 
131
+ # Return a hash with client's login and password.
132
+ #
133
+ # @return [Hash]
50
134
  def basic_params
51
135
  @password.nil? ? {} : { login: @login, password: @password }
52
136
  end
53
137
 
138
+ # Return a hash with client's login and access token.
139
+ #
140
+ # @return [Hash]
54
141
  def auth_params
55
142
  @login.nil? ? {} : { login: @login, access_token: @access_token }
56
143
  end
57
144
 
145
+ # Handle HTTP responses.
146
+ #
147
+ # Raise proper exceptions based on the response code.
148
+ #
149
+ # @return [HTTParty::Response]
58
150
  def handle_response(response)
59
151
  case response.code
60
152
  when 401 then raise Unauthorized
@@ -1,6 +1,11 @@
1
1
  module GitHub
2
+
3
+ # Default configuration information.
2
4
  module Default
5
+
6
+ # The default API endpoint for GitHub's API.
3
7
  API_ENDPOINT = "https://api.github.com".freeze
8
+
4
9
  end
5
10
  end
6
11