github_api 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,64 +2,165 @@
2
2
 
3
3
  module Github
4
4
  class Repos
5
+ # The Repository Hooks API manages the post-receive web and service hooks for a repository.
5
6
  module Hooks
6
7
 
7
- REQUIRED_PARAMS = %w[ name config ]
8
+ VALID_HOOK_PARAM_NAMES = %w[
9
+ name
10
+ config
11
+ active
12
+ events
13
+ add_events
14
+ remove_events
15
+ ].freeze
16
+
17
+ # Active hooks can be configured to trigger for one or more events. The default event is push.
18
+ # The available events are:
19
+ VALID_HOOK_PARAM_VALUES = {
20
+ 'events' => %w[
21
+ push
22
+ issues
23
+ issue_comment
24
+ commit_comment
25
+ pull_request
26
+ gollum
27
+ watch
28
+ download
29
+ fork
30
+ fork_apply
31
+ member
32
+ public
33
+ ]
34
+ }.freeze
35
+
36
+ REQUIRED_PARAMS = %w[ name config ].freeze
8
37
 
9
38
  # List repository hooks
10
- #
11
- # GET /repos/:user/:repo/hooks
12
39
  #
13
- def hooks(user, repo)
14
- get("/repos/#{user}/#{repo}/hooks")
40
+ # = Examples
41
+ # @github = Github.new
42
+ # @github.repos.hooks 'user-name', 'repo-name'
43
+ # @github.repos.hooks 'user-name', 'repo-name' { |hook| ... }
44
+ #
45
+ def hooks(user_name=nil, repo_name=nil, params={})
46
+ _update_user_repo_params(user_name, repo_name)
47
+ _validate_user_repo_params(user, repo) unless user? && repo?
48
+ _normalize_params_keys(params)
49
+
50
+ response = get("/repos/#{user}/#{repo}/hooks", params)
51
+ return response unless block_given?
52
+ response.each { |el| yield el }
15
53
  end
16
54
 
17
- # Get a single hook
55
+ # Get a single hook
18
56
  #
19
- # GET /repos/:user/:repo/hooks/:id
57
+ # = Examples
58
+ # @github = Github.new
59
+ # @github.repos.hook 'user-name', 'repo-name'
20
60
  #
21
- def get_hook(user, repo, hook_id)
22
- get("/repos/#{user}/#{repo}/hooks/#{hook_id}")
61
+ def hook(user_name, repo_name, hook_id, params={})
62
+ _update_user_repo_params(user_name, repo_name)
63
+ _validate_user_repo_params(user, repo) unless user? && repo?
64
+ _validate_presence_of hook_id
65
+ _normalize_params_keys(params)
66
+
67
+ get("/repos/#{user}/#{repo}/hooks/#{hook_id}", params)
23
68
  end
24
69
 
25
70
  # Create a hook
26
71
  #
27
- # POST /repos/:user/:repo/hooks
72
+ # = Inputs
73
+ # * <tt>:name</tt> - Required string - the name of the service that is being called.
74
+ # * <tt>:config</tt> - Required hash - A Hash containing key/value pairs to provide settings for this hook.
75
+ # * <tt>:events</tt> - Optional array - Determines what events the hook is triggered for. Default: ["push"]
76
+ # * <tt>:active</tt> - Optional boolean - Determines whether the hook is actually triggered on pushes.
77
+ #
78
+ # = Examples
79
+ # @github = Github.new
80
+ # @github.repos.create_hook 'user-name', 'repo-name',
81
+ # "name" => "web",
82
+ # "active" => true,
83
+ # "config" => {
84
+ # "url" => "http://something.com/webhook"
85
+ # }
86
+ # }
28
87
  #
29
- def create_hook(user, repo, params)
88
+ def create_hook(user_name=nil, repo_name=nil, params={})
89
+ _update_user_repo_params(user_name, repo_name)
90
+ _validate_user_repo_params(user, repo) unless user? && repo?
91
+
30
92
  _normalize_params_keys(params)
31
- _filter_params_keys(%w[ name config active ], params)
32
- raise ArgumentError, "Required parameters are: #{REQUIRED_PARAMS.join(', ')}" unless _validate_inputs(REQUIRED_PARAMS, params)
93
+ _filter_params_keys(VALID_HOOK_PARAM_NAMES, params)
94
+
95
+ raise ArgumentError, "Required parameters are: name, config" unless _validate_inputs(REQUIRED_PARAMS, params)
33
96
 
34
97
  post("/repos/#{user}/#{repo}/hooks", params)
35
98
  end
36
99
 
37
100
  # Edit a hook
38
101
  #
39
- # PATCH /repos/:user/:repo/hooks/:id
40
- #
41
- def edit_hook(user, repo, hook_id, params)
102
+ # = Inputs
103
+ # * <tt>:name</tt> - Required string - the name of the service that is being called.
104
+ # * <tt>:config</tt> - Required hash - A Hash containing key/value pairs to provide settings for this hook.
105
+ # * <tt>:events</tt> - Optional array - Determines what events the hook is triggered for. This replaces the entire array of events. Default: ["push"].
106
+ # * <tt>:add_events</tt> - Optional array - Determines a list of events to be added to the list of events that the Hook triggers for.
107
+ # * <tt>:remove_events</tt> - Optional array - Determines a list of events to be removed from the list of events that the Hook triggers for.
108
+ # * <tt>:active</tt> - Optional boolean - Determines whether the hook is actually triggered on pushes.
109
+ #
110
+ # = Examples
111
+ # @github = Github.new
112
+ # @github.repos.edit_hook 'user-name', 'repo-name',
113
+ # "name" => "campfire",
114
+ # "active" => true,
115
+ # "config" => {
116
+ # "subdomain" => "github",
117
+ # "room" => "Commits",
118
+ # "token" => "abc123"
119
+ # }
120
+ #
121
+ def edit_hook(user_name, repo_name, hook_id, params={})
122
+ _update_user_repo_params(user_name, repo_name)
123
+ _validate_user_repo_params(user, repo) unless user? && repo?
124
+ _validate_presence_of hook_id
125
+
42
126
  _normalize_params_keys(params)
43
- _filter_params_keys(%w[ name config active ], params)
44
- raise ArgumentError, "Required parameters are: #{REQUIRED_PARAMS.join(', ')}" unless _validate_inputs(REQUIRED_PARAMS, params)
127
+ _filter_params_keys(VALID_HOOK_PARAM_NAMES, params)
45
128
 
46
- patch("/repos/#{user}/#{repo}/hooks/#{hook_id}")
129
+ raise ArgumentError, "Required parameters are: name, config" unless _validate_inputs(REQUIRED_PARAMS, params)
130
+
131
+ patch("/repos/#{user}/#{repo}/hooks/#{hook_id}", params)
47
132
  end
48
133
 
49
134
  # Test a hook
50
135
  #
51
- # POST /repos/:user/:repo/hooks/:id/test
136
+ # This will trigger the hook with the latest push to the current repository.
137
+ #
138
+ # = Examples
139
+ # @github = Github.new
140
+ # @github.repos.test_hook 'user-name', 'repo-name', 'hook-id'
52
141
  #
53
- def test_hook(user, repo, hook_id)
54
- post("/repos/#{user}/#{repo}/hooks/#{hook_id}/test")
142
+ def test_hook(user_name, repo_name, hook_id, params={})
143
+ _update_user_repo_params(user_name, repo_name)
144
+ _validate_user_repo_params(user, repo) unless user? && repo?
145
+ _validate_presence_of hook_id
146
+ _normalize_params_keys(params)
147
+
148
+ post("/repos/#{user}/#{repo}/hooks/#{hook_id}/test", params)
55
149
  end
56
150
 
57
151
  # Delete a hook
58
152
  #
59
- # DELETE /repos/:user/:repo/hooks/:id
153
+ # = Examples
154
+ # @github = Github.new
155
+ # @github.repos.delete_hook 'user-name', 'repo-name', 'hook-id'
60
156
  #
61
- def delete_hook(user, repo, hook_id)
62
- delete("/repos/#{user}/#{repo}/hooks/#{hook_id}")
157
+ def delete_hook(user_name, repo_name, hook_id, params={})
158
+ _update_user_repo_params(user_name, repo_name)
159
+ _validate_user_repo_params(user, repo) unless user? && repo?
160
+ _validate_presence_of hook_id
161
+ _normalize_params_keys(params)
162
+
163
+ delete("/repos/#{user}/#{repo}/hooks/#{hook_id}", params)
63
164
  end
64
165
 
65
166
  end # Hooks
@@ -35,7 +35,7 @@ module Github
35
35
  _validate_presence_of key_id
36
36
  _normalize_params_keys(params)
37
37
 
38
- get("/repos/#{user}/#{repo}/keys/#{key_id}")
38
+ get("/repos/#{user}/#{repo}/keys/#{key_id}", params)
39
39
  end
40
40
 
41
41
  # Create a key
@@ -81,7 +81,7 @@ module Github
81
81
  _normalize_params_keys(params)
82
82
  _filter_params_keys(VALID_KEY_PARAM_NAMES, params)
83
83
 
84
- patch("/repos/#{user}/#{repo}/keys/#{key_id}")
84
+ patch("/repos/#{user}/#{repo}/keys/#{key_id}", params)
85
85
  end
86
86
 
87
87
  # Delete key
@@ -96,7 +96,7 @@ module Github
96
96
  _validate_presence_of key_id
97
97
  _normalize_params_keys(params)
98
98
 
99
- delete("/repos/#{user}/#{repo}/keys/#{key_id}")
99
+ delete("/repos/#{user}/#{repo}/keys/#{key_id}", params)
100
100
  end
101
101
 
102
102
  end # Keys
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class Repos
5
+ module PubSubHubbub
6
+
7
+ def subscribe(topic, callback)
8
+ post("/hub")
9
+ end
10
+ end # PubSubHubbub
11
+ end # Repos
12
+ end # Github
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ require 'faraday'
4
+ require 'base64'
5
+
6
+ module Github
7
+ module Request
8
+ class BasicAuth < Faraday::Middleware
9
+ dependency 'base64'
10
+
11
+ def call(env)
12
+ # puts "BASIC: #{@auth}"
13
+ env[:request_headers].merge!('Authorization' => "Basic #{@auth}\"")
14
+
15
+ @app.call env
16
+ end
17
+
18
+ def initialize(app, *args)
19
+ @app = app
20
+ login, password = args.shift, args.shift
21
+ @auth = Base64.encode64("#{login}:#{password}")
22
+ @auth.gsub!("\n", "")
23
+ end
24
+ end # BasicAuth
25
+ end # Request
26
+ end # Github
@@ -28,6 +28,6 @@ module Github
28
28
  @app = app
29
29
  @token = args.shift
30
30
  end
31
- end
32
- end
31
+ end # OAuth2
32
+ end # Request
33
33
  end # Github
@@ -4,7 +4,7 @@ module Github
4
4
  module VERSION
5
5
  MAJOR = 0
6
6
  MINOR = 1
7
- PATCH = 1
7
+ PATCH = 2
8
8
  BUILD = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.');
@@ -0,0 +1,9 @@
1
+ [
2
+ {
3
+ "name": "master",
4
+ "commit": {
5
+ "sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
6
+ "url": "https://api.github.com/octocat/Hello-World/commits/c5b97d5ae6c19d5c5df71a34c7fbeeda2479ccbc"
7
+ }
8
+ }
9
+ ]
@@ -0,0 +1,8 @@
1
+ [
2
+ {
3
+ "login": "octocat",
4
+ "id": 1,
5
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
6
+ "url": "https://api.github.com/users/octocat"
7
+ }
8
+ ]
@@ -0,0 +1,15 @@
1
+ {
2
+ "url": "https://api.github.com/repos/octocat/Hello-World/hooks/1",
3
+ "updated_at": "2011-09-06T20:39:23Z",
4
+ "created_at": "2011-09-06T17:26:27Z",
5
+ "name": "web",
6
+ "events": [
7
+ "push"
8
+ ],
9
+ "active": true,
10
+ "config": {
11
+ "url": "http://example.com",
12
+ "content_type": "json"
13
+ },
14
+ "id": 1
15
+ }
@@ -0,0 +1,10 @@
1
+ [
2
+ {
3
+ "url": "https://api.github.com/repos/octocat/Hello-World/hooks/1",
4
+ "updated_at": "2011-09-06T20:39:23Z",
5
+ "created_at": "2011-09-06T17:26:27Z",
6
+ "name": "web",
7
+ "active": true,
8
+ "id": 1
9
+ }
10
+ ]
@@ -0,0 +1,4 @@
1
+ {
2
+ "Ruby": 78769,
3
+ "Python": 7769
4
+ }
@@ -0,0 +1,90 @@
1
+ {
2
+ "url": "https://api.github.com/repos/octocat/Hello-World",
3
+ "html_url": "https://github.com/octocat/Hello-World",
4
+ "clone_url": "https://github.com/octocat/Hello-World.git",
5
+ "git_url": "git://github.com/octocat/Hello-World.git",
6
+ "ssh_url": "git@github.com:octocat/Hello-World.git",
7
+ "svn_url": "https://svn.github.com/octocat/Hello-World",
8
+ "owner": {
9
+ "login": "octocat",
10
+ "id": 1,
11
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
12
+ "url": "https://api.github.com/users/octocat"
13
+ },
14
+ "name": "Hello-World",
15
+ "description": "This your first repo!",
16
+ "homepage": "https://github.com",
17
+ "language": null,
18
+ "private": false,
19
+ "fork": false,
20
+ "forks": 9,
21
+ "watchers": 80,
22
+ "size": 108,
23
+ "master_branch": "master",
24
+ "open_issues": 0,
25
+ "pushed_at": "2011-01-26T19:06:43Z",
26
+ "created_at": "2011-01-26T19:01:12Z",
27
+ "organization": {
28
+ "login": "octocat",
29
+ "id": 1,
30
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
31
+ "url": "https://api.github.com/users/octocat",
32
+ "type": "Organization"
33
+ },
34
+ "parent": {
35
+ "url": "https://api.github.com/repos/octocat/Hello-World",
36
+ "html_url": "https://github.com/octocat/Hello-World",
37
+ "clone_url": "https://github.com/octocat/Hello-World.git",
38
+ "git_url": "git://github.com/octocat/Hello-World.git",
39
+ "svn_url": "https://svn.github.com/octocat/Hello-World",
40
+ "owner": {
41
+ "login": "octocat",
42
+ "id": 1,
43
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
44
+ "url": "https://api.github.com/users/octocat"
45
+ },
46
+ "name": "Hello-World",
47
+ "description": "This your first repo!",
48
+ "homepage": "https://github.com",
49
+ "language": null,
50
+ "private": false,
51
+ "fork": false,
52
+ "forks": 9,
53
+ "watchers": 80,
54
+ "size": 108,
55
+ "master_branch": "master",
56
+ "open_issues": 0,
57
+ "pushed_at": "2011-01-26T19:06:43Z",
58
+ "created_at": "2011-01-26T19:01:12Z"
59
+ },
60
+ "source": {
61
+ "url": "https://api.github.com/repos/octocat/Hello-World",
62
+ "html_url": "https://github.com/octocat/Hello-World",
63
+ "clone_url": "https://github.com/octocat/Hello-World.git",
64
+ "git_url": "git://github.com/octocat/Hello-World.git",
65
+ "ssh_url": "git@github.com:octocat/Hello-World.git",
66
+ "svn_url": "https://svn.github.com/octocat/Hello-World",
67
+ "owner": {
68
+ "login": "octocat",
69
+ "id": 1,
70
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
71
+ "url": "https://api.github.com/users/octocat"
72
+ },
73
+ "name": "Hello-World",
74
+ "description": "This your first repo!",
75
+ "homepage": "https://github.com",
76
+ "language": null,
77
+ "private": false,
78
+ "fork": false,
79
+ "forks": 9,
80
+ "watchers": 80,
81
+ "size": 108,
82
+ "master_branch": "master",
83
+ "open_issues": 0,
84
+ "pushed_at": "2011-01-26T19:06:43Z",
85
+ "created_at": "2011-01-26T19:01:12Z"
86
+ },
87
+ "has_issues": true,
88
+ "has_wiki": true,
89
+ "has_downloads": true
90
+ }
@@ -0,0 +1,29 @@
1
+ [
2
+ {
3
+ "url": "https://api.github.com/repos/octocat/Hello-World",
4
+ "html_url": "https://github.com/octocat/Hello-World",
5
+ "clone_url": "https://github.com/octocat/Hello-World.git",
6
+ "git_url": "git://github.com/octocat/Hello-World.git",
7
+ "ssh_url": "git@github.com:octocat/Hello-World.git",
8
+ "svn_url": "https://svn.github.com/octocat/Hello-World",
9
+ "owner": {
10
+ "login": "octocat",
11
+ "id": 1,
12
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
13
+ "url": "https://api.github.com/users/octocat"
14
+ },
15
+ "name": "Hello-World",
16
+ "description": "This your first repo!",
17
+ "homepage": "https://github.com",
18
+ "language": null,
19
+ "private": false,
20
+ "fork": false,
21
+ "forks": 9,
22
+ "watchers": 80,
23
+ "size": 108,
24
+ "master_branch": "master",
25
+ "open_issues": 0,
26
+ "pushed_at": "2011-01-26T19:06:43Z",
27
+ "created_at": "2011-01-26T19:01:12Z"
28
+ }
29
+ ]