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,33 @@
1
+ module Octokit
2
+ class Client
3
+ module Objects
4
+
5
+ def tree(repo, tree_sha, options={})
6
+ get("tree/show/#{Repository.new(repo)}/#{tree_sha}", options)['tree']
7
+ end
8
+
9
+ def blob(repo, tree_sha, path, options={})
10
+ get("blob/show/#{Repository.new(repo)}/#{tree_sha}/#{path}", options)['blob']
11
+ end
12
+
13
+ def blobs(repo, tree_sha, options={})
14
+ get("blob/all/#{Repository.new(repo)}/#{tree_sha}", options)['blobs']
15
+ end
16
+
17
+ def blob_metadata(repo, tree_sha, options={})
18
+ get("blob/full/#{Repository.new(repo)}/#{tree_sha}", options)['blobs']
19
+ end
20
+ alias :blob_meta :blob_metadata
21
+
22
+ def tree_metadata(repo, tree_sha, options={})
23
+ get("tree/full/#{Repository.new(repo)}/#{tree_sha}", options)['blobs']
24
+ end
25
+ alias :tree_meta :tree_metadata
26
+
27
+ def raw(repo, sha, options={})
28
+ get("blob/show/#{Repository.new(repo)}/#{sha}", options)
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,89 @@
1
+ module Octokit
2
+ class Client
3
+ module Organizations
4
+
5
+ def organization(org, options={})
6
+ get("organizations/#{org}", options)['organization']
7
+ end
8
+ alias :org :organization
9
+
10
+ def update_organization(org, values, options={})
11
+ put("organizations/#{org}", options.merge({:organization => values}))['organization']
12
+ end
13
+ alias :update_org :update_organization
14
+
15
+ def organizations(user=nil, options={})
16
+ if user
17
+ get("user/show/#{user}/organizations", options)
18
+ else
19
+ get("organizations", options)
20
+ end['organizations']
21
+ end
22
+ alias :list_organizations :organizations
23
+ alias :list_orgs :organizations
24
+ alias :orgs :organizations
25
+
26
+ def organization_repositories(org, options={})
27
+ if org
28
+ get("organizations/#{org}/public_repositories", options)
29
+ else
30
+ get("organizations/repositories", options)
31
+ end['repositories']
32
+ end
33
+ alias :org_repositories :organization_repositories
34
+ alias :org_repos :organization_repositories
35
+
36
+ def organization_members(org, options={})
37
+ get("organizations/#{org}/public_members", options)['users']
38
+ end
39
+ alias :org_members :organization_members
40
+
41
+ def teams(org, options={})
42
+ get("organizations/#{org}/teams", options)['teams']
43
+ end
44
+
45
+ def create_team(org, values, options={})
46
+ post("organizations/#{org}/teams", options.merge({:team => values}))['team']
47
+ end
48
+
49
+ def team(team_id, options={})
50
+ get("teams/#{team_id}", options)['team']
51
+ end
52
+
53
+ def update_team(team_id, values, options={})
54
+ put("teams/#{team_id}", options.merge({:team => values}))['team']
55
+ end
56
+
57
+ def delete_team(team_id, options={})
58
+ delete("teams/#{team_id}", options)['team']
59
+ end
60
+
61
+ def team_members(team_id, options={})
62
+ get("teams/#{team_id}/members", options)['users']
63
+ end
64
+
65
+ def add_team_member(team_id, user, options={})
66
+ post("teams/#{team_id}/members", options.merge({:name => user}))['user']
67
+ end
68
+
69
+ def remove_team_member(team_id, user, options={})
70
+ delete("teams/#{team_id}/members", options.merge({:name => user}))['user']
71
+ end
72
+
73
+ def team_repositories(team_id, options={})
74
+ get("teams/#{team_id}/repositories", options)['repositories']
75
+ end
76
+ alias :team_repos :team_repositories
77
+
78
+ def add_team_repository(team_id, repo, options={})
79
+ post("teams/#{team_id}/repositories", options.merge(:name => Repository.new(repo)))['repositories']
80
+ end
81
+ alias :add_team_repo :add_team_repository
82
+
83
+ def remove_team_repository(team_id, repo, options={})
84
+ delete("teams/#{team_id}/repositories", options.merge(:name => Repository.new(repo)))['repositories']
85
+ end
86
+ alias :remove_team_repo :remove_team_repository
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,19 @@
1
+ module Octokit
2
+ class Client
3
+ module Pulls
4
+ def create_pull_request(repo, options={})
5
+ post("pulls/#{Repository.new(repo)}", options)['pulls']
6
+ end
7
+
8
+ def pull_requests(repo, state='open', options={})
9
+ get("pulls/#{Repository.new(repo)}/#{state}", options)['pulls']
10
+ end
11
+ alias :pulls :pull_requests
12
+
13
+ def pull_request(repo, number, options={})
14
+ get("pulls/#{Repository.new(repo)}/#{number}", options)['pulls']
15
+ end
16
+ alias :pull :pull_request
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,130 @@
1
+ module Octokit
2
+ class Client
3
+ module Repositories
4
+
5
+ def search_repositories(q, options={})
6
+ get("repos/search/#{q}", options)['repositories']
7
+ end
8
+ alias :search_repos :search_repositories
9
+
10
+ def repository(repo, options={})
11
+ get("repos/show/#{Repository.new(repo)}", options)['repository']
12
+ end
13
+ alias :repo :repository
14
+
15
+ def update_repository(repo, values, options={})
16
+ post("repos/show/#{Repository.new(repo)}", options.merge({:values => values}))['repository']
17
+ end
18
+ alias :update_repo :update_repository
19
+
20
+ def repositories(username=nil, options={})
21
+ get(["repos/show", username].compact.join('/'), options)['repositories']
22
+ end
23
+ alias :list_repositories :repositories
24
+ alias :list_repos :repositories
25
+ alias :repos :repositories
26
+
27
+ def watch!(repo, options={})
28
+ post("repos/watch/#{Repository.new(repo)}", options)['repository']
29
+ end
30
+ alias :watch :watch!
31
+
32
+ def unwatch!(repo, options={})
33
+ post("repos/unwatch/#{Repository.new(repo)}", options)['repository']
34
+ end
35
+ alias :unwatch :unwatch!
36
+
37
+ def fork!(repo, options={})
38
+ post("repos/fork/#{Repository.new(repo)}", options)['repository']
39
+ end
40
+ alias :fork :fork!
41
+
42
+ def create_repository(options={})
43
+ post("repos/create", options)['repository']
44
+ end
45
+ alias :create_repo :create_repository
46
+ alias :create :create_repository
47
+
48
+ def delete_repository(repo, options={})
49
+ post("repos/delete/#{Repository.new(repo)}", options)['repository']
50
+ end
51
+ alias :delete_repo :delete_repository
52
+
53
+ def set_private!(repo, options={})
54
+ post("repos/set/private/#{Repository.new(repo)}", options)['repository']
55
+ end
56
+ alias :set_private :set_private!
57
+
58
+ def set_public!(repo, options={})
59
+ post("repos/set/public/#{Repository.new(repo)}", options)['repository']
60
+ end
61
+ alias :set_public :set_public!
62
+
63
+ def deploy_keys(repo, options={})
64
+ get("repos/keys/#{Repository.new(repo)}", options)['public_keys']
65
+ end
66
+ alias :list_deploy_keys :deploy_keys
67
+
68
+ def add_deploy_key(repo, options={})
69
+ post("repos/key/#{Repository.new(repo)}/add", options)['public_keys']
70
+ end
71
+
72
+ def remove_deploy_key(repo, id, options={})
73
+ post("repos/key/#{Repository.new(repo)}/remove", options.merge(:id => id))['public_keys']
74
+ end
75
+
76
+ def collaborators(repo, options={})
77
+ get("repos/show/#{Repository.new(repo)}/collaborators", options)['collaborators']
78
+ end
79
+ alias :collabs :collaborators
80
+
81
+ def add_collaborator(repo, collaborator, options={})
82
+ post("repos/collaborators/#{Repository.new(repo)}/add/#{collaborator}")['collaborators']
83
+ end
84
+ alias :add_collab :add_collaborator
85
+
86
+ def remove_collaborator(repo, collaborator, options={})
87
+ post("repos/collaborators/#{Repository.new(repo)}/remove/#{collaborator}")['collaborators']
88
+ end
89
+ alias :remove_collab :remove_collaborator
90
+
91
+ def pushable(options={})
92
+ get("repos/pushable", options)['repositories']
93
+ end
94
+
95
+ def teams(repo, options={})
96
+ get("repos/show/#{Repository.new(repo)}/teams", options)['repositories']
97
+ end
98
+
99
+ def contributors(repo, anon=true, options={})
100
+ if anon
101
+ get("repos/show/#{Repository.new(repo)}/contributors", options)
102
+ else
103
+ get("repos/show/#{Repository.new(repo)}/contributors/anon", options)
104
+ end['contributors']
105
+ end
106
+ alias :contribs :contributors
107
+
108
+ def watchers(repo, options={})
109
+ get("repos/show/#{Repository.new(repo)}/watchers", options)['watchers']
110
+ end
111
+
112
+ def network(repo, options={})
113
+ get("repos/show/#{Repository.new(repo)}/network", options)['network']
114
+ end
115
+
116
+ def languages(repo, options={})
117
+ get("repos/show/#{Repository.new(repo)}/languages", options)['languages']
118
+ end
119
+
120
+ def tags(repo, options={})
121
+ get("repos/show/#{Repository.new(repo)}/tags", options)['tags']
122
+ end
123
+
124
+ def branches(repo, options={})
125
+ get("repos/show/#{Repository.new(repo)}/branches", options)['branches']
126
+ end
127
+
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,41 @@
1
+ module Octokit
2
+ class Client
3
+ module Request
4
+ def get(path, options={}, raw=false, format_path=true)
5
+ request(:get, path, options, raw, format_path)
6
+ end
7
+
8
+ def post(path, options={}, raw=false, format_path=true)
9
+ request(:post, path, options, raw, format_path)
10
+ end
11
+
12
+ def put(path, options={}, raw=false, format_path=true)
13
+ request(:put, path, options, raw, format_path)
14
+ end
15
+
16
+ def delete(path, options={}, raw=false, format_path=true)
17
+ request(:delete, path, options, raw, format_path)
18
+ end
19
+
20
+ private
21
+
22
+ def request(method, path, options, raw, format_path)
23
+ response = connection(raw).send(method) do |request|
24
+ path = formatted_path(path) if format_path
25
+ case method
26
+ when :get, :delete
27
+ request.url(path, options)
28
+ when :post, :put
29
+ request.path = path
30
+ request.body = options unless options.empty?
31
+ end
32
+ end
33
+ raw ? response : response.body
34
+ end
35
+
36
+ def formatted_path(path)
37
+ ['api', ['v', version].join, format, path].compact.join('/')
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,20 @@
1
+ module Octokit
2
+ class Client
3
+ module Timelines
4
+
5
+ def public_timeline(username=login, options={})
6
+ if username.nil?
7
+ path = "timeline.json"
8
+ else
9
+ path = "#{username}.json"
10
+ end
11
+ get(path, options, false, false)
12
+ end
13
+
14
+ def timeline(options={})
15
+ get("#{login}.private.json", options, false, false)
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,77 @@
1
+ module Octokit
2
+ class Client
3
+ module Users
4
+ EMAIL_RE = /[\w.!#\$%+-]+@[\w-]+(?:\.[\w-]+)+/
5
+
6
+ def search_users(search, options={})
7
+ if search.match(EMAIL_RE)
8
+ get("user/email/#{search}", options)
9
+ else
10
+ get("user/search/#{search}", options)
11
+ end['users']
12
+ end
13
+
14
+ def user(username=nil, options={})
15
+ get(["user/show", username].compact.join('/'), options)['user']
16
+ end
17
+
18
+ def update_user(values, options={})
19
+ post("user/show/#{login}", options.merge({:values => values}))['user']
20
+ end
21
+
22
+ def followers(user=login, options={})
23
+ get("user/show/#{user}/followers", options)['users']
24
+ end
25
+
26
+ def following(user=login, options={})
27
+ get("user/show/#{user}/following", options)['users']
28
+ end
29
+
30
+ def follows?(*args)
31
+ target = args.pop
32
+ user = args.first
33
+ user ||= login
34
+ return if user.nil?
35
+ following(user).include?(target)
36
+ end
37
+
38
+ def follow!(user, options={})
39
+ post("user/follow/#{user}", options)['users']
40
+ end
41
+ alias :follow :follow!
42
+
43
+ def unfollow!(user, options={})
44
+ post("user/unfollow/#{user}", options)['users']
45
+ end
46
+ alias :unfollow :unfollow!
47
+
48
+ def watched(user=login, options={})
49
+ get("repos/watched/#{user}", options)['repositories']
50
+ end
51
+
52
+ def keys(options={})
53
+ get("user/keys", options)['public_keys']
54
+ end
55
+
56
+ def add_key(title, key, options={})
57
+ post("user/key/add", options.merge({:title => title, :key => key}))['public_keys']
58
+ end
59
+
60
+ def remove_key(id, options={})
61
+ post("user/key/remove", options.merge({:id => id}))['public_keys']
62
+ end
63
+
64
+ def emails(options={})
65
+ get("user/emails", options)['emails']
66
+ end
67
+
68
+ def add_email(email, options={})
69
+ post("user/email/add", options.merge({:email => email}))['emails']
70
+ end
71
+
72
+ def remove_email(email, options={})
73
+ post("user/email/remove", options.merge({:email => email}))['emails']
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,45 @@
1
+ require 'faraday'
2
+ require File.expand_path('../version', __FILE__)
3
+
4
+ module Octokit
5
+ module Configuration
6
+ VALID_OPTIONS_KEYS = [:adapter, :endpoint, :format, :login, :password, :proxy, :token, :user_agent, :version].freeze
7
+ VALID_FORMATS = [:json, :xml, :yaml].freeze
8
+
9
+ DEFAULT_ADAPTER = Faraday.default_adapter.freeze
10
+ DEFAULT_ENDPOINT = 'https://github.com/'.freeze
11
+ DEFAULT_FORMAT = :json.freeze
12
+ DEFAULT_LOGIN = nil.freeze
13
+ DEFAULT_PASSWORD = nil.freeze
14
+ DEFAULT_PROXY = nil.freeze
15
+ DEFAULT_TOKEN = nil.freeze
16
+ DEFAULT_USER_AGENT = "Octokit Ruby Gem #{Octokit::VERSION}".freeze
17
+ DEFAULT_VERSION = 2
18
+
19
+ attr_accessor *VALID_OPTIONS_KEYS
20
+
21
+ def self.extended(base)
22
+ base.reset
23
+ end
24
+
25
+ def configure
26
+ yield self
27
+ end
28
+
29
+ def options
30
+ VALID_OPTIONS_KEYS.inject({}){|o,k| o.merge!(k => send(k)) }
31
+ end
32
+
33
+ def reset
34
+ self.adapter = DEFAULT_ADAPTER
35
+ self.endpoint = DEFAULT_ENDPOINT
36
+ self.format = DEFAULT_FORMAT
37
+ self.login = DEFAULT_LOGIN
38
+ self.password = DEFAULT_PASSWORD
39
+ self.proxy = DEFAULT_PROXY
40
+ self.token = DEFAULT_TOKEN
41
+ self.user_agent = DEFAULT_USER_AGENT
42
+ self.version = DEFAULT_VERSION
43
+ end
44
+ end
45
+ end