xn-octokit 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/.document +4 -0
  2. data/.gemtest +0 -0
  3. data/.gitignore +24 -0
  4. data/.rspec +3 -0
  5. data/.travis.yml +6 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +20 -0
  8. data/README.markdown +73 -0
  9. data/Rakefile +8 -0
  10. data/changelog.markdown +42 -0
  11. data/lib/faraday/response/raise_error.rb +33 -0
  12. data/lib/octokit.rb +53 -0
  13. data/lib/octokit/client.rb +40 -0
  14. data/lib/octokit/client/authentication.rb +23 -0
  15. data/lib/octokit/client/commits.rb +16 -0
  16. data/lib/octokit/client/connection.rb +34 -0
  17. data/lib/octokit/client/issues.rb +60 -0
  18. data/lib/octokit/client/network.rb +15 -0
  19. data/lib/octokit/client/objects.rb +33 -0
  20. data/lib/octokit/client/organizations.rb +90 -0
  21. data/lib/octokit/client/pulls.rb +25 -0
  22. data/lib/octokit/client/repositories.rb +138 -0
  23. data/lib/octokit/client/request.rb +41 -0
  24. data/lib/octokit/client/timelines.rb +22 -0
  25. data/lib/octokit/client/users.rb +75 -0
  26. data/lib/octokit/configuration.rb +61 -0
  27. data/lib/octokit/repository.rb +39 -0
  28. data/lib/octokit/version.rb +3 -0
  29. data/octokit.gemspec +33 -0
  30. data/spec/faraday/response_spec.rb +34 -0
  31. data/spec/fixtures/blob.json +1 -0
  32. data/spec/fixtures/blob_metadata.json +1 -0
  33. data/spec/fixtures/blobs.json +1 -0
  34. data/spec/fixtures/branches.json +1 -0
  35. data/spec/fixtures/collaborators.json +1 -0
  36. data/spec/fixtures/comment.json +1 -0
  37. data/spec/fixtures/comments.json +1 -0
  38. data/spec/fixtures/commit.json +1 -0
  39. data/spec/fixtures/commits.json +1 -0
  40. data/spec/fixtures/contributors.json +1 -0
  41. data/spec/fixtures/delete_token.json +1 -0
  42. data/spec/fixtures/emails.json +1 -0
  43. data/spec/fixtures/followers.json +1 -0
  44. data/spec/fixtures/following.json +1 -0
  45. data/spec/fixtures/issue.json +1 -0
  46. data/spec/fixtures/issues.json +1 -0
  47. data/spec/fixtures/labels.json +1 -0
  48. data/spec/fixtures/languages.json +1 -0
  49. data/spec/fixtures/network.json +1 -0
  50. data/spec/fixtures/network_data.json +1 -0
  51. data/spec/fixtures/network_meta.json +1 -0
  52. data/spec/fixtures/organization.json +1 -0
  53. data/spec/fixtures/organizations.json +1 -0
  54. data/spec/fixtures/public_keys.json +1 -0
  55. data/spec/fixtures/pull.json +1 -0
  56. data/spec/fixtures/pulls.json +1 -0
  57. data/spec/fixtures/raw.txt +7 -0
  58. data/spec/fixtures/repositories.json +1 -0
  59. data/spec/fixtures/repository.json +1 -0
  60. data/spec/fixtures/tags.json +1 -0
  61. data/spec/fixtures/team.json +1 -0
  62. data/spec/fixtures/teams.json +1 -0
  63. data/spec/fixtures/timeline.json +1237 -0
  64. data/spec/fixtures/tree.json +1 -0
  65. data/spec/fixtures/tree_metadata.json +1 -0
  66. data/spec/fixtures/user.json +1 -0
  67. data/spec/fixtures/users.json +1 -0
  68. data/spec/fixtures/watchers.json +1 -0
  69. data/spec/helper.rb +64 -0
  70. data/spec/octokit/client/commits_spec.rb +32 -0
  71. data/spec/octokit/client/issues_spec.rb +154 -0
  72. data/spec/octokit/client/network_spec.rb +32 -0
  73. data/spec/octokit/client/objects_spec.rb +81 -0
  74. data/spec/octokit/client/organizations_spec.rb +234 -0
  75. data/spec/octokit/client/pulls_spec.rb +44 -0
  76. data/spec/octokit/client/repositories_spec.rb +331 -0
  77. data/spec/octokit/client/timelines_spec.rb +42 -0
  78. data/spec/octokit/client/users_spec.rb +274 -0
  79. data/spec/octokit/client_spec.rb +12 -0
  80. data/spec/octokit_spec.rb +15 -0
  81. data/spec/repository_spec.rb +54 -0
  82. metadata +336 -0
@@ -0,0 +1,4 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ features/**/*.feature
4
+ LICENSE
File without changes
@@ -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/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=nested
3
+ --backtrace
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - ree
5
+ - rbx
6
+ - jruby
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,73 @@
1
+ Octokit
2
+ =======
3
+ Simple Ruby wrapper for the GitHub v2 API.
4
+
5
+ Installation
6
+ ------------
7
+ gem install octokit
8
+
9
+ Continuous Integration
10
+ ----------------------
11
+ [![Build Status](http://travis-ci.org/pengwynn/octokit.png)](http://travis-ci.org/pengwynn/octokit)
12
+
13
+ Some examples
14
+ -------------
15
+
16
+ ### Show a user
17
+
18
+ Octokit.user('pengwynn')
19
+ => <#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>
20
+
21
+ ### Show who a user follows
22
+
23
+ Octokit.following('pengwynn')
24
+ => ["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"]
25
+
26
+ Working with repositories
27
+ -------------------------
28
+ For convenience, methods that require a repo argument may be passed in any of the following forms
29
+
30
+ * "pengwynn/linked"
31
+ * {:username => 'pengwynn', :name => 'linkedin'}
32
+ * {:username => 'pengwynn', :repo => 'linkedin'}
33
+ * instance of Repository
34
+
35
+ ### Show a repo
36
+
37
+ Octokit.repo("pengwynn/linkedin")
38
+ => <#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>
39
+
40
+ Authenticated requests
41
+ ----------------------
42
+ 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)
43
+
44
+ client = Octokit::Client.new(:login => 'pengwynn', :token => 'OU812')
45
+ client.follow!('adamstac')
46
+
47
+ Read the full [docs](http://rdoc.info/projects/pengwynn/octokit)
48
+
49
+ TODO
50
+ ----
51
+ * Feed parsing
52
+ * More examples
53
+
54
+ Submitting a Pull Request
55
+ -------------------------
56
+ 1. Fork the project.
57
+ 2. Create a topic branch.
58
+ 3. Implement your feature or bug fix.
59
+ 4. Add documentation for your feature or bug fix.
60
+ 5. Run <tt>bundle exec rake doc:yard</tt>. If your changes are not 100% documented, go back to step 4.
61
+ 6. Add specs for your feature or bug fix.
62
+ 7. Run <tt>bundle exec rake spec</tt>. If your changes are not 100% covered, go back to step 6.
63
+ 8. Commit and push your changes.
64
+ 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.)
65
+
66
+ Credits
67
+ -------
68
+ Octokit is inspired by [Octopi](http://github.com/fcoury/octopi) and aims to be a lightweight, less active-resourcey alternative.
69
+
70
+ Copyright
71
+ ---------
72
+ Copyright (c) 2011 [Wynn Netherland](http://wynnnetherland.com), [Adam Stacoviak](http://adamstacoviak.com/), [Erik Michaels-Ober](https://github.com/sferik).
73
+ See [LICENSE](https://github.com/pengwynn/octokit/blob/master/LICENSE) for details.
@@ -0,0 +1,8 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :test => :spec
8
+ task :default => :spec
@@ -0,0 +1,42 @@
1
+ # Changelog
2
+ ## 0.5.0
3
+ * Rewrote all tests in rspec
4
+ * A handful of backwards-incompatible API changes
5
+ ## 0.4.1
6
+ * Patch from [karlfreeman](http://github.com/karlfreeman) to fix user search
7
+ ## 0.4.0
8
+ * Renamed to Ocotokit
9
+ * Switched to Faraday from HTTParty
10
+ ## 0.3.0
11
+ * Added set_repo_info patch from [Scott Bronson](http://github.com/bronson)
12
+ ## 0.2.4
13
+ * Rev'd HTTParty dependency, switched to Bundler
14
+ ## 0.2.3
15
+ * Patch from [Sutto](http://github.com/Sutto) to use authentication with list repos if available
16
+ ## 0.2.2
17
+ * Patch from [abrader](http://github.com/abrader) to add auth_params query to the blob, tree, and repo class methods
18
+ ## 0.2.1
19
+ * Contributors API courtesy of @enricob
20
+ ## 0.2.0
21
+ * Commits API courtesy of @enricob
22
+
23
+ ## 0.1.4
24
+
25
+ * Preserved links array and content for events parsed from feeds
26
+
27
+ ## 0.1.3
28
+
29
+ * Added Download event
30
+
31
+ ## 0.1.2
32
+
33
+ * Added Delete event type
34
+ * Added Public event type
35
+
36
+ ## 0.1.1
37
+
38
+ * Added Comment event type
39
+
40
+ ## 0.0.1 Initial version
41
+
42
+ * GitHub v2 API complete
@@ -0,0 +1,33 @@
1
+ require 'faraday'
2
+
3
+ # @api private
4
+ module Faraday
5
+ class Response::RaiseError < Response::Middleware
6
+ def on_complete(response)
7
+ case response[:status].to_i
8
+ when 400
9
+ raise Octokit::BadRequest, error_message(response)
10
+ when 401
11
+ raise Octokit::Unauthorized, error_message(response)
12
+ when 403
13
+ raise Octokit::Forbidden, error_message(response)
14
+ when 404
15
+ raise Octokit::NotFound, error_message(response)
16
+ when 406
17
+ raise Octokit::NotAcceptable, error_message(response)
18
+ when 500
19
+ raise Octokit::InternalServerError, error_message(response)
20
+ when 501
21
+ raise Octokit::NotImplemented, error_message(response)
22
+ when 502
23
+ raise Octokit::BadGateway, error_message(response)
24
+ when 503
25
+ raise Octokit::ServiceUnavailable, error_message(response)
26
+ end
27
+ end
28
+
29
+ def error_message(response)
30
+ "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{(': ' + response[:body].inspect) if response[:body]}"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,53 @@
1
+ require 'octokit/configuration'
2
+ require 'octokit/client'
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
+ def self.respond_to?(method)
21
+ client.respond_to?(method) || super
22
+ end
23
+
24
+ # Custom error class for rescuing from all GitHub errors
25
+ class Error < StandardError; end
26
+
27
+ # Raised when GitHub returns a 400 HTTP status code
28
+ class BadRequest < Error; end
29
+
30
+ # Raised when GitHub returns a 401 HTTP status code
31
+ class Unauthorized < Error; end
32
+
33
+ # Raised when GitHub returns a 403 HTTP status code
34
+ class Forbidden < Error; end
35
+
36
+ # Raised when GitHub returns a 404 HTTP status code
37
+ class NotFound < Error; end
38
+
39
+ # Raised when GitHub returns a 406 HTTP status code
40
+ class NotAcceptable < Error; end
41
+
42
+ # Raised when GitHub returns a 500 HTTP status code
43
+ class InternalServerError < Error; end
44
+
45
+ # Raised when GitHub returns a 501 HTTP status code
46
+ class NotImplemented < Error; end
47
+
48
+ # Raised when GitHub returns a 502 HTTP status code
49
+ class BadGateway < Error; end
50
+
51
+ # Raised when GitHub returns a 503 HTTP status code
52
+ class ServiceUnavailable < Error; end
53
+ end
@@ -0,0 +1,40 @@
1
+ require 'octokit/repository'
2
+ require 'octokit/client/authentication'
3
+ require 'octokit/client/connection'
4
+ require 'octokit/client/request'
5
+ require 'octokit/client/commits'
6
+ require 'octokit/client/issues'
7
+ require 'octokit/client/network'
8
+ require 'octokit/client/objects'
9
+ require 'octokit/client/organizations'
10
+ require 'octokit/client/pulls'
11
+ require 'octokit/client/repositories'
12
+ require 'octokit/client/timelines'
13
+ require 'octokit/client/users'
14
+
15
+ module Octokit
16
+ class Client
17
+ attr_accessor *Configuration::VALID_OPTIONS_KEYS
18
+
19
+ def initialize(options={})
20
+ options = Octokit.options.merge(options)
21
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
22
+ send("#{key}=", options[key])
23
+ end
24
+ end
25
+
26
+ include Octokit::Client::Authentication
27
+ include Octokit::Client::Connection
28
+ include Octokit::Client::Request
29
+
30
+ include Octokit::Client::Commits
31
+ include Octokit::Client::Issues
32
+ include Octokit::Client::Network
33
+ include Octokit::Client::Objects
34
+ include Octokit::Client::Organizations
35
+ include Octokit::Client::Pulls
36
+ include Octokit::Client::Repositories
37
+ include Octokit::Client::Timelines
38
+ include Octokit::Client::Users
39
+ end
40
+ end
@@ -0,0 +1,23 @@
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
+
18
+ def oauthed?
19
+ !oauth_token.nil?
20
+ end
21
+ end
22
+ end
23
+ 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)['commits']
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,34 @@
1
+ require 'faraday_middleware'
2
+ require 'faraday/response/raise_error'
3
+
4
+ module Octokit
5
+ class Client
6
+ # @private
7
+ module Connection
8
+ private
9
+
10
+ def connection(raw=false, authenticate=true)
11
+ options = {
12
+ :proxy => proxy,
13
+ :ssl => {:verify => false},
14
+ :url => endpoint,
15
+ }
16
+
17
+ options.merge!(:params => { :access_token => oauth_token }) if oauthed? && !authenticated?
18
+
19
+ Faraday::Connection.new(options) do |connection|
20
+ connection.use Faraday::Response::RaiseError
21
+ unless raw
22
+ connection.use Faraday::Response::Mashify
23
+ case format.to_s.downcase
24
+ when 'json' then connection.use Faraday::Response::ParseJson
25
+ when 'xml' then connection.use Faraday::Response::ParseXml
26
+ end
27
+ end
28
+ connection.basic_auth authentication[:login], authentication[:password] if authenticate and authenticated?
29
+ connection.adapter(adapter)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ 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
+ get("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, label, number=nil, options={})
48
+ post(["issues/label/add/#{Repository.new(repo)}/#{label}", number].compact.join('/'), options)['labels']
49
+ end
50
+
51
+ def remove_label(repo, label, number=nil, options={})
52
+ post(["issues/label/remove/#{Repository.new(repo)}/#{label}", number].compact.join('/'), options)['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