octokit 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/.document +4 -0
  2. data/.gitignore +24 -0
  3. data/Gemfile +3 -0
  4. data/LICENSE +20 -0
  5. data/README.markdown +69 -0
  6. data/Rakefile +14 -0
  7. data/changelog.markdown +34 -0
  8. data/lib/faraday/raise_error.rb +41 -0
  9. data/lib/octokit.rb +49 -0
  10. data/lib/octokit/client.rb +30 -0
  11. data/lib/octokit/client/authentication.rb +19 -0
  12. data/lib/octokit/client/commits.rb +16 -0
  13. data/lib/octokit/client/connection.rb +32 -0
  14. data/lib/octokit/client/issues.rb +60 -0
  15. data/lib/octokit/client/network.rb +15 -0
  16. data/lib/octokit/client/objects.rb +33 -0
  17. data/lib/octokit/client/organizations.rb +89 -0
  18. data/lib/octokit/client/pulls.rb +19 -0
  19. data/lib/octokit/client/repositories.rb +130 -0
  20. data/lib/octokit/client/request.rb +41 -0
  21. data/lib/octokit/client/timelines.rb +20 -0
  22. data/lib/octokit/client/users.rb +77 -0
  23. data/lib/octokit/configuration.rb +45 -0
  24. data/lib/octokit/event.rb +76 -0
  25. data/lib/octokit/repository.rb +39 -0
  26. data/lib/octokit/version.rb +3 -0
  27. data/octokit.gemspec +33 -0
  28. data/test/fixtures/blob.json +10 -0
  29. data/test/fixtures/branch_commits.json +48 -0
  30. data/test/fixtures/branches.json +6 -0
  31. data/test/fixtures/close_issue.json +1 -0
  32. data/test/fixtures/collaborators.json +1 -0
  33. data/test/fixtures/comment.json +1 -0
  34. data/test/fixtures/commits.json +824 -0
  35. data/test/fixtures/contributors.json +6 -0
  36. data/test/fixtures/emails.json +1 -0
  37. data/test/fixtures/followers.json +3 -0
  38. data/test/fixtures/full_user.json +27 -0
  39. data/test/fixtures/issue.json +14 -0
  40. data/test/fixtures/issues.json +50 -0
  41. data/test/fixtures/keys.json +1 -0
  42. data/test/fixtures/labels.json +1 -0
  43. data/test/fixtures/languages.json +1 -0
  44. data/test/fixtures/network.json +26 -0
  45. data/test/fixtures/network_data.json +1 -0
  46. data/test/fixtures/network_meta.json +109 -0
  47. data/test/fixtures/open_issue.json +1 -0
  48. data/test/fixtures/raw_git_data.yaml +7 -0
  49. data/test/fixtures/reopen_issue.json +1 -0
  50. data/test/fixtures/repo.json +14 -0
  51. data/test/fixtures/repo_search.json +452 -0
  52. data/test/fixtures/repos.json +830 -0
  53. data/test/fixtures/search.json +44 -0
  54. data/test/fixtures/show_commit.json +37 -0
  55. data/test/fixtures/tags.json +8 -0
  56. data/test/fixtures/timeline.json +1018 -0
  57. data/test/fixtures/trees.json +140 -0
  58. data/test/fixtures/user.json +16 -0
  59. data/test/helper.rb +57 -0
  60. data/test/octokit_test.rb +765 -0
  61. data/test/repository_test.rb +45 -0
  62. metadata +377 -0
@@ -0,0 +1,4 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ features/**/*.feature
4
+ LICENSE
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ *.swp
4
+ *.tmproj
5
+ *~
6
+ .DS_Store
7
+ .\#*
8
+ .bundle
9
+ .config
10
+ .yardoc
11
+ Gemfile.lock
12
+ InstalledFiles
13
+ \#*
14
+ _yardoc
15
+ coverage
16
+ doc/
17
+ lib/bundler/man
18
+ pkg
19
+ rdoc
20
+ spec/reports
21
+ test/tmp
22
+ test/version_tmp
23
+ tmp
24
+ tmtags
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Wynn Netherland, Adam Stacoviak, Erik Michaels-Ober
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,69 @@
1
+ Octokit
2
+ =======
3
+ Simple Ruby wrapper for the GitHub v2 API.
4
+
5
+ Installation
6
+ ------------
7
+ gem install octokit
8
+
9
+ Some examples
10
+ -------------
11
+
12
+ ### Show a user
13
+
14
+ Octokit.user('pengwynn')
15
+ => <#Hashie::Mash blog="http://wynnnetherland.com" company="Orrka" created_at="2008/02/25 10:24:19 -0800" email="wynn.netherland@gmail.com" followers_count=21 following_count=55 id=865 location="Dallas, TX" login="pengwynn" name="Wynn Netherland" public_gist_count=4 public_repo_count=16>
16
+
17
+ ### Show who a user follows
18
+
19
+ Octokit.following('pengwynn')
20
+ => ["cglee", "bryansray", "rails", "zachinglis", "wycats", "obie", "mully", "squeejee", "jderrett", "Shopify", "ReinH", "technoweenie", "errfree", "defunkt", "joshsusser", "hashrocket", "newbamboo", "bigtiger", "github", "jamis", "jeresig", "thoughtbot", "therealadam", "jnunemaker", "seaofclouds", "choan", "llimllib", "kwhinnery", "marshall", "handcrafted", "adamstac", "jashkenas", "dan", "remy", "hayesdavis", "documentcloud", "imathis", "mdeiters", "njonsson", "asenchi", "mattsa", "marclove", "webiest", "brogers", "polomasta", "stephp", "mchelen", "piyush", "davidnorth", "rmetzler", "jferris", "madrobby", "zh", "erikvold", "desandro"]
21
+
22
+ Working with repositories
23
+ -------------------------
24
+ For convenience, methods that require a repo argument may be passed in any of the following forms
25
+
26
+ * "pengwynn/linked"
27
+ * {:username => 'pengwynn', :name => 'linkedin'}
28
+ * {:username => 'pengwynn', :repo => 'linkedin'}
29
+ * instance of Repository
30
+
31
+ ### Show a repo
32
+
33
+ Octokit.repo("pengwynn/linkedin")
34
+ => <#Hashie::Mash description="Ruby wrapper for the LinkedIn API" fork=false forks=1 homepage="http://bit.ly/ruby-linkedin" name="linkedin" open_issues=2 owner="pengwynn" private=false url="http://github.com/pengwynn/linkedin" watchers=36>
35
+
36
+ Authenticated requests
37
+ ----------------------
38
+ Some methods require authentication so you'll need to pass a login and an api_token. You can find your GitHub API token on your [account page](https://github.com/account)
39
+
40
+ client = Octokit::Client.new(:login => 'pengwynn', :token => 'OU812')
41
+ client.follow!('adamstac')
42
+
43
+ Read the full [docs](http://rdoc.info/projects/pengwynn/octokit)
44
+
45
+ TODO
46
+ ----
47
+ * Feed parsing
48
+ * More examples
49
+
50
+ Submitting a Pull Request
51
+ -------------------------
52
+ 1. Fork the project.
53
+ 2. Create a topic branch.
54
+ 3. Implement your feature or bug fix.
55
+ 4. Add documentation for your feature or bug fix.
56
+ 5. Run <tt>bundle exec rake doc:yard</tt>. If your changes are not 100% documented, go back to step 4.
57
+ 6. Add specs for your feature or bug fix.
58
+ 7. Run <tt>bundle exec rake spec</tt>. If your changes are not 100% covered, go back to step 6.
59
+ 8. Commit and push your changes.
60
+ 9. Submit a pull request. Please do not include changes to the version or gemspec. (If you want to create your own version for some reason, please do so in a separate commit.)
61
+
62
+ Credits
63
+ -------
64
+ Octokit is inspired by [Octopi](http://github.com/fcoury/octopi) and aims to be a lightweight, less active-resourcey alternative.
65
+
66
+ Copyright
67
+ ---------
68
+ Copyright (c) 2011 [Wynn Netherland](http://wynnnetherland.com), [Adam Stacoviak](http://adamstacoviak.com/), [Erik Michaels-Ober](https://github.com/sferik).
69
+ See [LICENSE](https://github.com/pengwynn/octokit/blob/master/LICENSE) for details.
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
+ require 'bundler'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ require 'shoulda/tasks'
6
+
7
+ require 'rake/testtask'
8
+ Rake::TestTask.new(:test) do |test|
9
+ test.ruby_opts = ["-rubygems"] if defined? Gem
10
+ test.libs << "lib" << "test"
11
+ test.pattern = "test/**/*_test.rb"
12
+ end
13
+
14
+ task :default => :test
@@ -0,0 +1,34 @@
1
+ # Changelog
2
+ ## 0.3.0
3
+ * Added set_repo_info patch from [Scott Bronson](http://github.com/bronson)
4
+ ## 0.2.4
5
+ * Rev'd HTTParty dependency, switched to Bundler
6
+ ## 0.2.3
7
+ * Patch from [Sutto](http://github.com/Sutto) to use authentication with list repos if available
8
+ ## 0.2.2
9
+ * Patch from [abrader](http://github.com/abrader) to add auth_params query to the blob, tree, and repo class methods
10
+ ## 0.2.1
11
+ * Contributors API courtesy of @enricob
12
+ ## 0.2.0
13
+ * Commits API courtesy of @enricob
14
+
15
+ ## 0.1.4
16
+
17
+ * Preserved links array and content for events parsed from feeds
18
+
19
+ ## 0.1.3
20
+
21
+ * Added Download event
22
+
23
+ ## 0.1.2
24
+
25
+ * Added Delete event type
26
+ * Added Public event type
27
+
28
+ ## 0.1.1
29
+
30
+ * Added Comment event type
31
+
32
+ ## 0.0.1 Initial version
33
+
34
+ * GitHub v2 API complete
@@ -0,0 +1,41 @@
1
+ require 'faraday'
2
+
3
+ # @api private
4
+ module Faraday
5
+ class Response::RaiseError < Response::Middleware
6
+ def self.register_on_complete(env)
7
+ env[:response].on_complete do |response|
8
+ case response[:status].to_i
9
+ when 400
10
+ raise Octokit::BadRequest, error_message(response)
11
+ when 401
12
+ raise Octokit::Unauthorized, error_message(response)
13
+ when 403
14
+ raise Octokit::Forbidden, error_message(response)
15
+ when 404
16
+ raise Octokit::NotFound, error_message(response)
17
+ when 406
18
+ raise Octokit::NotAcceptable, error_message(response)
19
+ when 500
20
+ raise Octokit::InternalServerError, error_message(response)
21
+ when 501
22
+ raise Octokit::NotImplemented, error_message(response)
23
+ when 502
24
+ raise Octokit::BadGateway, error_message(response)
25
+ when 503
26
+ raise Octokit::ServiceUnavailable, error_message(response)
27
+ end
28
+ end
29
+ end
30
+
31
+ def initialize(app)
32
+ super
33
+ end
34
+
35
+ private
36
+
37
+ def self.error_message(response)
38
+ "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{(': ' + response[:body]) if response[:body]}"
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,49 @@
1
+ require File.expand_path('../octokit/configuration', __FILE__)
2
+ require File.expand_path('../octokit/client', __FILE__)
3
+
4
+ module Octokit
5
+ extend Configuration
6
+
7
+ # Alias for Octokit::Client.new
8
+ #
9
+ # @return [Octokit::Client]
10
+ def self.client(options={})
11
+ Octokit::Client.new(options)
12
+ end
13
+
14
+ # Delegate to Octokit::Client.new
15
+ def self.method_missing(method, *args, &block)
16
+ return super unless client.respond_to?(method)
17
+ client.send(method, *args, &block)
18
+ end
19
+
20
+ # Custom error class for rescuing from all GitHub errors
21
+ class Error < StandardError; end
22
+
23
+ # Raised when GitHub returns a 400 HTTP status code
24
+ class BadRequest < Error; end
25
+
26
+ # Raised when GitHub returns a 401 HTTP status code
27
+ class Unauthorized < Error; end
28
+
29
+ # Raised when GitHub returns a 403 HTTP status code
30
+ class Forbidden < Error; end
31
+
32
+ # Raised when GitHub returns a 404 HTTP status code
33
+ class NotFound < Error; end
34
+
35
+ # Raised when GitHub returns a 406 HTTP status code
36
+ class NotAcceptable < Error; end
37
+
38
+ # Raised when GitHub returns a 500 HTTP status code
39
+ class InternalServerError < Error; end
40
+
41
+ # Raised when GitHub returns a 501 HTTP status code
42
+ class NotImplemented < Error; end
43
+
44
+ # Raised when GitHub returns a 502 HTTP status code
45
+ class BadGateway < Error; end
46
+
47
+ # Raised when GitHub returns a 503 HTTP status code
48
+ class ServiceUnavailable < Error; end
49
+ end
@@ -0,0 +1,30 @@
1
+ require File.expand_path('../event', __FILE__)
2
+ require File.expand_path('../repository', __FILE__)
3
+ Dir[File.expand_path('../client/*.rb', __FILE__)].each{|file| require file}
4
+
5
+ module Octokit
6
+ class Client
7
+ attr_accessor *Configuration::VALID_OPTIONS_KEYS
8
+
9
+ def initialize(options={})
10
+ options = Octokit.options.merge(options)
11
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
12
+ send("#{key}=", options[key])
13
+ end
14
+ end
15
+
16
+ include Octokit::Client::Authentication
17
+ include Octokit::Client::Connection
18
+ include Octokit::Client::Request
19
+
20
+ include Octokit::Client::Commits
21
+ include Octokit::Client::Issues
22
+ include Octokit::Client::Network
23
+ include Octokit::Client::Objects
24
+ include Octokit::Client::Organizations
25
+ include Octokit::Client::Pulls
26
+ include Octokit::Client::Repositories
27
+ include Octokit::Client::Timelines
28
+ include Octokit::Client::Users
29
+ end
30
+ end
@@ -0,0 +1,19 @@
1
+ module Octokit
2
+ class Client
3
+ module Authentication
4
+ def authentication
5
+ if login && token
6
+ {:login => "#{login}/token", :password => token}
7
+ elsif login && password
8
+ {:login => login, :password => password}
9
+ else
10
+ {}
11
+ end
12
+ end
13
+
14
+ def authenticated?
15
+ !authentication.empty?
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ module Octokit
2
+ class Client
3
+ module Commits
4
+
5
+ def commits(repo, branch="master", options={})
6
+ get("commits/list/#{Repository.new(repo)}/#{branch}", options)['commits']
7
+ end
8
+ alias :list_commits :commits
9
+
10
+ def commit(repo, sha, options={})
11
+ get("commits/show/#{Repository.new(repo)}/#{sha}", options)['commit']
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,32 @@
1
+ require 'faraday_middleware'
2
+ Dir[File.expand_path('../../../faraday/*.rb', __FILE__)].each{|file| require file}
3
+
4
+ module Octokit
5
+ class Client
6
+ # @private
7
+ module Connection
8
+ private
9
+
10
+ def connection(raw=false)
11
+ options = {
12
+ :proxy => proxy,
13
+ :ssl => {:verify => false},
14
+ :url => endpoint,
15
+ }
16
+
17
+ Faraday::Connection.new(options) do |connection|
18
+ connection.adapter(adapter)
19
+ connection.basic_auth authentication[:login], authentication[:password] if authenticated?
20
+ connection.use Faraday::Response::RaiseError
21
+ unless raw
22
+ case format.to_s.downcase
23
+ when 'json' then connection.use Faraday::Response::ParseJson
24
+ when 'xml' then connection.use Faraday::Response::ParseXml
25
+ end
26
+ connection.use Faraday::Response::Mashify
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,60 @@
1
+ module Octokit
2
+ class Client
3
+ module Issues
4
+
5
+ def search_issues(repo, search_term, state='open', options={})
6
+ get("issues/search/#{Repository.new(repo)}/#{state}/#{search_term}", options)['issues']
7
+ end
8
+
9
+ def issues(repo, state='open', options={})
10
+ get("issues/list/#{Repository.new(repo)}/#{state}", options)['issues']
11
+ end
12
+ alias :list_issues :issues
13
+
14
+ def issues_labeled(repo, label, options={})
15
+ get("issues/list/#{Repository.new(repo)}/label/#{label}", options)['issues']
16
+ end
17
+
18
+ def issue(repo, number, options={})
19
+ get("issues/show/#{Repository.new(repo)}/#{number}", options)['issue']
20
+ end
21
+
22
+ def issue_comments(repo, number, options={})
23
+ post("issues/comments/#{Repository.new(repo)}/#{number}", options)['comments']
24
+ end
25
+
26
+ def create_issue(repo, title, body, options={})
27
+ post("issues/open/#{Repository.new(repo)}", options.merge({:title => title, :body => body}))['issue']
28
+ end
29
+ alias :open_issue :create_issue
30
+
31
+ def close_issue(repo, number, options={})
32
+ post("issues/close/#{Repository.new(repo)}/#{number}", options)['issue']
33
+ end
34
+
35
+ def reopen_issue(repo, number, options={})
36
+ post("issues/reopen/#{Repository.new(repo)}/#{number}", options)['issue']
37
+ end
38
+
39
+ def update_issue(repo, number, title, body, options={})
40
+ post("issues/edit/#{Repository.new(repo)}/#{number}", options.merge({:title => title, :body => body}))['issue']
41
+ end
42
+
43
+ def labels(repo, options={})
44
+ get("issues/labels/#{Repository.new(repo)}", options)['labels']
45
+ end
46
+
47
+ def add_label(repo, number, label, options={})
48
+ post("issues/label/add/#{Repository.new(repo)}/#{label}/#{number}", options)['labels']
49
+ end
50
+
51
+ def remove_label(repo, number, label, options={})
52
+ post("issues/label/remove/#{Repository.new(repo)}/#{label}/#{number}")['labels']
53
+ end
54
+
55
+ def add_comment(repo, number, comment, options={})
56
+ post("issues/comment/#{Repository.new(repo)}/#{number}", options.merge({:comment => comment}))['comment']
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,15 @@
1
+ module Octokit
2
+ class Client
3
+ module Network
4
+
5
+ def network_meta(repo, options={})
6
+ get("#{Repository.new(repo)}/network_meta", options, false, false)
7
+ end
8
+
9
+ def network_data(repo, nethash, options={})
10
+ get("#{Repository.new(repo)}/network_data_chunk", options.merge({:nethash => nethash}), false, false)['commits']
11
+ end
12
+
13
+ end
14
+ end
15
+ end