ghee 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/.autotest ADDED
@@ -0,0 +1 @@
1
+ require "autotest/growl"
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ README (Autosaved)
2
+ Gemfile.lock
3
+ spec/.access_token
4
+ spec/responses/
5
+ spec/settings.yml
data/.rspec ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) Jonathan Hoyt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,353 @@
1
+ Ghee
2
+ ==================
3
+
4
+ This is an unofficial ruby client for the [GitHub API](http://developer.github.com/v3/). The end goal is a complete, simple, and intuitive ruby API for all things Github.
5
+
6
+ Usage
7
+ -----
8
+
9
+ Instantiate the client:
10
+
11
+ access_token = "abcd1234"
12
+ gh = Ghee.new(access_token)
13
+
14
+ ### Gists
15
+
16
+ List a user's gists:
17
+
18
+ gh.user('jonmagic').gists
19
+
20
+ List authenticated users gists:
21
+
22
+ gh.gists
23
+
24
+ List all public gists:
25
+
26
+ gh.gists.public
27
+
28
+ List the authenticated user's starred gists:
29
+
30
+ gh.gists.starred
31
+
32
+ Get a single gist:
33
+
34
+ gist_id = "1393990"
35
+ gh.gists(gist_id)
36
+
37
+ Create a gist ([see docs for all possible params](http://developer.github.com/v3/gists/#create-a-gist)):
38
+
39
+ gh.gists.create({
40
+ :description => 'Ghee'
41
+ :public => true,
42
+ :files => {
43
+ 'file1.txt' => {
44
+ :content => 'buttah yo bread'
45
+ }
46
+ }
47
+ })
48
+
49
+ Edit a gist:
50
+
51
+ gh.gists("1393990").patch({
52
+ :files => {
53
+ 'gistfile1.md' => {
54
+ :content => 'clarified I say'
55
+ }
56
+ }
57
+ })
58
+
59
+ Star a gist:
60
+
61
+ gh.gists("1393990").star
62
+
63
+ Unstar a gist:
64
+
65
+ gh.gists("1393990").unstar
66
+
67
+ Check if a gist is starred:
68
+
69
+ gh.gists("1393990").starred?
70
+
71
+ Delete a gist:
72
+
73
+ gh.gists("1393990").destroy
74
+
75
+ ### Repos
76
+
77
+ Get a single repo:
78
+
79
+ gh.repos("rauhryan", "ghee")
80
+
81
+ Get the hooks for a repo:
82
+
83
+ gh.repos("rauhryan", "ghee").hooks
84
+
85
+ Get a single hook for a repo:
86
+
87
+ gh.repos("rauhryan", "ghee").hooks(12)
88
+
89
+ Create a hook for a repo: ([see docs for all possible params](http://developer.github.com/v3/hooks/#create-an-hook)):
90
+
91
+ gh.repos("rauhryan", "ghee").hooks.create({
92
+ :name => "web",
93
+ :config => {:url => "http://huboard.com/webhook"}
94
+ })
95
+
96
+ Update a hook for a repo: ([see docs for all possible params](http://developer.github.com/v3/hooks/#edit-an-hook)):
97
+
98
+ gh.repos("rauhryan", "ghee").hooks(12).patch({
99
+ :name => "web",
100
+ :config => {:url => "http://huboard.com/webhook"}
101
+ })
102
+
103
+ Destroy a hook for a repo:
104
+
105
+ gh.repos("rauhryan", "ghee").hooks(1).destory
106
+
107
+ Get the milestones for a repo:
108
+
109
+ gh.repos("rauhryan", "ghee").milestones
110
+
111
+ Get a single milestone for a repo:
112
+
113
+ gh.repos("rauhryan", "ghee").milestones(12)
114
+
115
+ Create a milestone for a repo: ([see docs for all possible params](http://developer.github.com/v3/milestones/#create-an-milestone)):
116
+
117
+ gh.repos("rauhryan", "ghee").milestones.create({
118
+ :title => "Remove the suck!",
119
+ :description => "I found this suck, remove it please"
120
+ })
121
+
122
+ Update a milestone for a repo: ([see docs for all possible params](http://developer.github.com/v3/milestones/#edit-an-milestone)):
123
+
124
+ gh.repos("rauhryan", "ghee").milestones(12).patch({
125
+ :description => "I found this suck, remove it please"
126
+ })
127
+
128
+ Destroy a milestone for a repo:
129
+
130
+ gh.repos("rauhryan", "ghee").milestones(1).destory
131
+
132
+ Get the issues for a repo:
133
+
134
+ gh.repos("rauhryan", "ghee").issues
135
+
136
+ Get a single issue for a repo:
137
+
138
+ gh.repos("rauhryan", "ghee").issues(12)
139
+
140
+ Create an issue for a repo: ([see docs for all possible params](http://developer.github.com/v3/issues/#create-an-issue)):
141
+
142
+ gh.repos("rauhryan", "ghee").issues.create({
143
+ :title => "Remove the suck!",
144
+ :body => "I found this suck, remove it please"
145
+ })
146
+
147
+ Update an issue for a repo: ([see docs for all possible params](http://developer.github.com/v3/issues/#edit-an-issue)):
148
+
149
+ gh.repos("rauhryan", "ghee").issues(12).patch({
150
+ :body => "I found this suck, remove it please"
151
+ })
152
+
153
+ Close an issue for a repo:
154
+
155
+ gh.repos("rauhryan", "ghee").issues(12).close
156
+
157
+ Get the closed issues for a repo:
158
+
159
+ gh.repos("rauhryan", "ghee").issues(12).closed
160
+
161
+ Get the comments for an issue:
162
+
163
+ gh.repos("rauhryan", "ghee").issues(12).comments
164
+
165
+ Get a single comment for an issue
166
+
167
+ gh.repos("rauhryan", "ghee").issues.comments(482910)
168
+
169
+ Create a comment for an issue:
170
+
171
+ gh.repos("rauhryan", "ghee").issues(12).comments.create({:body => "hey i'll help fix that suck"})
172
+
173
+ Update a single comment for an issue
174
+
175
+ gh.repos("rauhryan", "ghee").issues.comments(482910).patch({:body =>
176
+ "nevermind I can't figure it out"})
177
+
178
+ Destroy a comment for an issue
179
+
180
+ gh.repos("rauhryan", "ghee").issues.comments(482910).destroy
181
+
182
+ ### Orgs
183
+
184
+ Get a list of orgs for the current user:
185
+
186
+ gh.orgs
187
+
188
+ Get a specific org:
189
+
190
+ gh.orgs("huboard")
191
+
192
+ Patch an organization:([see docs for all possible params](http://developer.github.com/v3/orgs#edit)):
193
+
194
+ gh.orgs("huboard").patch({ :company => "awesome company" })
195
+
196
+ Get a list of repos for an org:
197
+
198
+ gh.orgs("huboard").repos
199
+
200
+ > Notes: see above for all the available api methods for repos
201
+
202
+ Get a list of teams for an org:
203
+
204
+ gh.orgs("huboard").teams
205
+
206
+ Get a single team for an org:
207
+
208
+ gh.orgs("huboard").teams(110234)
209
+
210
+ Create team for an org:
211
+
212
+ gh.orgs("huboard").teams.create :name => "awesome_developers"
213
+
214
+ Patch a team for an org:
215
+
216
+ gh.orgs("huboard").teams(110234).patch :name => "junior_developers"
217
+
218
+ Delete a team for an org:
219
+
220
+ gh.orgs("huboard").teams(110234).delete
221
+
222
+ Get a list of members for a team:
223
+
224
+ gh.orgs("huboard").teams(110234).members
225
+
226
+ Add a member to a team:
227
+
228
+ gh.orgs("huboard").teams(110234).members.add("rauhryan")
229
+
230
+ Remove a member from a team:
231
+
232
+ gh.orgs("huboard").teams(110234).members.remove("rauhryan")
233
+
234
+ ### Teams
235
+
236
+ Get a single team:
237
+
238
+ gh.team(110234)
239
+
240
+ Create a team:
241
+
242
+ gh.team.create :name => "awesome_developers"
243
+
244
+ Patch a team:
245
+
246
+ gh.team(110234).patch :name => "junior_developers"
247
+
248
+ Delete a team:
249
+
250
+ gh.team(110234).delete
251
+
252
+ Get a list of members for a team:
253
+
254
+ gh.team(110234).members
255
+
256
+ Add a member to a team:
257
+
258
+ gh.team(110234).members.add("rauhryan")
259
+
260
+ Remove a member from a team:
261
+
262
+ gh.team(110234).members.remove("rauhryan")
263
+
264
+ ### Users
265
+
266
+ Get a single user:
267
+
268
+ gh.users('jonmagic')
269
+
270
+
271
+ Get the authenticated user:
272
+
273
+ gh.user
274
+
275
+ Update authenticated user ([see docs for all possible params](http://developer.github.com/v3/users/#update-the-authenticated-user)):
276
+
277
+ gh.user.patch({
278
+ :name => 'Jon Hoyt',
279
+ :email => 'jonmagic@gmail.com',
280
+ # …etc
281
+ })
282
+
283
+ Get a list of repos for the current user:
284
+
285
+ gh.user.repos
286
+
287
+ Get a list of repos for a specific user:
288
+
289
+ gh.users("rauhryan").repos
290
+
291
+ Get a single repos for the current user:
292
+
293
+ gh.user.repos("ghee")
294
+
295
+ Get a single repos for a specific user:
296
+
297
+ gh.users("rauhryan").repos("ghee")
298
+
299
+ > Notes: see above for all the available api methods for repos
300
+
301
+ Get a list of orgs for the current user:
302
+
303
+ gh.user.orgs
304
+
305
+ Get a list of orgs for a specific user:
306
+
307
+ gh.users("rauhryan").orgs
308
+
309
+ > Notes: see above for all the available api methods for orgs
310
+
311
+ ### Events
312
+
313
+ List public events:
314
+
315
+ gh.events
316
+
317
+ Testing
318
+ -------
319
+
320
+ The test suite uses [VCR](https://github.com/myronmarston/vcr) to cache actual requests to the Github API in a directory called responses in the spec directory.
321
+
322
+ In order for VCR to make and cache the actual calls to the Github API you will need to copy spec/settings.yml.sample to spec/settings.yml and configure it with your GitHub username, either a GitHub access token or your GitHub password, a test repo for it to hit against (which you should setup ahead of time), and finally an organization you belong to (for the entire suite of tests to pass you have to belong to an org).
323
+
324
+ This file is ignored by git (see .gitignore) so you can commit any changes you make to the gem without having to worry about your user/token/pass/org being released into the wild.
325
+
326
+ Now run the test suite:
327
+
328
+ bundle
329
+ bundle exec rake
330
+
331
+ CONTRIBUTE
332
+ ----------
333
+
334
+ If you'd like to hack on Ghee, start by forking the repo on GitHub:
335
+
336
+ https://github.com/jonmagic/ghee
337
+
338
+ The best way to get your changes merged back into core is as follows:
339
+
340
+ 1. Clone down your fork
341
+ 1. Create a thoughtfully named topic branch to contain your change
342
+ 1. Hack away
343
+ 1. Add tests and make sure everything still passes by running `bundle exec rake`
344
+ 1. If you are adding new functionality, document it in the README
345
+ 1. Do not change the version number, we will do that on our end
346
+ 1. If necessary, rebase your commits into logical chunks, without errors
347
+ 1. Push the branch up to GitHub
348
+ 1. Send a pull request for your branch
349
+
350
+ Contributors
351
+ ------------
352
+ * Jonathan Hoyt
353
+ * [Ryan Rauh](https://github.com/rauhryan)
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "rspec/core/rake_task"
4
+ desc "Run the specs"
5
+ RSpec::Core::RakeTask.new do |t|
6
+ t.rspec_opts = %w(-fs --color)
7
+ end
8
+
9
+ task :default => :spec
10
+ task :test => :spec
11
+
12
+ desc "Open an irb session with library"
13
+ task :console do
14
+ sh "irb -I lib -r ghee"
15
+ end
data/ghee.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ghee/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ghee"
7
+ s.version = Ghee::VERSION
8
+ s.authors = ["Jonathan Hoyt"]
9
+ s.email = ["jonmagic@gmail.com"]
10
+ s.homepage = "http://github.com/jonmagic/ghee"
11
+ s.summary = %q{Access Github in ruby.}
12
+ s.description = %q{A complete, simple, and intuitive ruby API for all things Github.}
13
+
14
+ s.rubyforge_project = "ghee"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency 'faraday'
22
+ s.add_runtime_dependency 'faraday_middleware'
23
+ s.add_runtime_dependency 'multi_json'
24
+ s.add_runtime_dependency 'yajl-ruby'
25
+ s.add_development_dependency 'rake'
26
+ s.add_development_dependency 'rspec', '~>2.0'
27
+ s.add_development_dependency 'webmock'
28
+ s.add_development_dependency 'vcr'
29
+ s.add_development_dependency 'ZenTest'
30
+ s.add_development_dependency 'autotest-growl'
31
+ end
data/lib/ghee.rb ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: UTF-8
2
+ require 'ghee/version'
3
+ require 'ghee/connection'
4
+ require 'ghee/resource_proxy'
5
+ require 'ghee/state_methods'
6
+ require 'ghee/api/authorizations'
7
+ require 'ghee/api/gists'
8
+ require 'ghee/api/users'
9
+ require 'ghee/api/events'
10
+ require 'ghee/api/repos'
11
+ require 'ghee/api/issues'
12
+ require 'ghee/api/milestones'
13
+ require 'ghee/api/orgs'
14
+
15
+ class Ghee
16
+ attr_reader :connection
17
+
18
+ include Ghee::API::Authorizations
19
+ include Ghee::API::Gists
20
+ include Ghee::API::Users
21
+ include Ghee::API::Events
22
+ include Ghee::API::Repos
23
+ include Ghee::API::Issues
24
+ include Ghee::API::Milestones
25
+ include Ghee::API::Orgs
26
+
27
+ # Instantiates Ghee, accepts an access_token
28
+ # for authenticated access
29
+ #
30
+ # Access_token - String of the access_token
31
+ #
32
+ def initialize(options = {})
33
+ @connection = Ghee::Connection.new(options)
34
+ end
35
+
36
+ def self.basic_auth(user_name, password)
37
+ Ghee.new :basic_auth => {:user_name => user_name, :password => password}
38
+ end
39
+
40
+ def self.access_token(token)
41
+ Ghee.new :access_token => token
42
+ end
43
+
44
+ def self.create_token(user_name, password, scopes)
45
+ auth = Ghee.basic_auth(user_name, password).authorizations.create({
46
+ :scopes => scopes})
47
+ auth["token"]
48
+ end
49
+ end