github_api 0.1.0.pre → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -8,11 +8,11 @@ Supports all the API methods(nearly 200). It's build in a modular way, that is,
8
8
 
9
9
  Grab the gem by issuing
10
10
 
11
- gem install github-api
11
+ gem install github_api --pre
12
12
 
13
13
  or in your Gemfile
14
14
 
15
- gem 'github-api'
15
+ gem "github_api", "~> 0.1.0.pre"
16
16
 
17
17
  == Usage
18
18
 
@@ -69,7 +69,7 @@ Main API methods are grouped into the following classes that can be instantiated
69
69
  Github::Repos
70
70
  Github::Users
71
71
 
72
- Some parts of GitHub API v3 require you to be autheticated, for instance the following are examples of API only for the authenticated user
72
+ Some parts of GitHub API v3 require you to be autheticated, for instance the following are examples of APIs only for the authenticated user
73
73
 
74
74
  Github::Users::Emails
75
75
  Github::Users::Keys
@@ -83,6 +83,22 @@ All method calls form ruby like sentences and allow for intuitive api navigation
83
83
  For specification on all available methods go to http://developer.github.com/v3/ or
84
84
  read the rdoc, all methods are documented there with examples of usage.
85
85
 
86
+ == Inputs
87
+
88
+ Some API methods apart from required parameters such as username, repository name
89
+ or organisation name, allow you to switch the way the data is returned to you, for instance
90
+
91
+ @github = Github.new
92
+ @github.git_data.tree 'peter-murach', 'github', 'c18647b75d72f19c1e0cc8af031e5d833b7f12ea' # => gets a tree
93
+
94
+ @github.git_data.tree 'peter-murach', 'github', 'c18647b75d72f19c1e0cc8af031e5d833b7f12ea', :recursive => true # => gets a whole tree recursively
95
+
96
+ by passing a block you can iterate over the file tree
97
+
98
+ @github.git_data.tree 'peter-murach', 'github', 'c18647b75d72f19c1e0cc8af031e5d833b7f12ea', :recursive => true do |file|
99
+ puts file.path
100
+ end
101
+
86
102
  == MIME Types
87
103
 
88
104
  Provides support for the following mime types
@@ -133,6 +149,8 @@ Query requests instead of http responses return boolean values
133
149
 
134
150
  == Caching
135
151
 
152
+ Each call by default is not going to be cached. In order to set the inmemory cache do...
153
+
136
154
  == TODO
137
155
 
138
156
  * Add support for mime types
@@ -78,6 +78,7 @@ module Github
78
78
  { 'user' => self.user, 'repo' => self.repo }.merge!(params)
79
79
  end
80
80
 
81
+ # Turns any keys from nested hashes including nested arrays into strings
81
82
  def _normalize_params_keys(params)
82
83
  case params
83
84
  when Hash
@@ -86,9 +87,11 @@ module Github
86
87
  _normalize_params_keys(params[k.to_s])
87
88
  end
88
89
  when Array
89
- params.map! { |el| el.to_s }
90
+ params.map! do |el|
91
+ _normalize_params_keys(el)
92
+ end
90
93
  else
91
- params
94
+ params.to_s
92
95
  end
93
96
  return params
94
97
  end
@@ -97,6 +100,23 @@ module Github
97
100
  params.reject! { |k,v| !keys.include? k }
98
101
  end
99
102
 
103
+ def _hash_traverse(hash, &block)
104
+ hash.each do |key, val|
105
+ block.call(key)
106
+ case val
107
+ when Hash
108
+ val.keys.each do |k|
109
+ _hash_traverse(val, &block)
110
+ end
111
+ when Array
112
+ val.each do |item|
113
+ _hash_traverse(item, &block)
114
+ end
115
+ end
116
+ end
117
+ return hash
118
+ end
119
+
100
120
  def _validate_params_values(options, params)
101
121
  params.each do |k, v|
102
122
  next unless options.keys.include?(k)
@@ -7,7 +7,10 @@ module Github
7
7
  @gists ||= Github::Gists.new(options)
8
8
  end
9
9
 
10
- def git_data(options)
10
+ # The Git Database API gives you access to read and write raw Git objects
11
+ # to your Git database on GitHub and to list and update your references
12
+ # (branch heads and tags).
13
+ def git_data(options = {})
11
14
  @git_data ||= Github::GitData.new(options)
12
15
  end
13
16
 
@@ -27,6 +30,8 @@ module Github
27
30
  @repos ||= Github::Repos.new(options)
28
31
  end
29
32
 
33
+ # Many of the resources on the users API provide a shortcut for getting
34
+ # information about the currently authenticated user.
30
35
  def users(options = {})
31
36
  @users ||= Github::Users.new(options)
32
37
  end
@@ -30,7 +30,7 @@ module Github
30
30
  DEFAULT_OAUTH_TOKEN = nil
31
31
 
32
32
  # The endpoint used to connect to GitHub if none is set
33
- DEFAULT_ENDPOINT = 'https://api.github.com/'.freeze
33
+ DEFAULT_ENDPOINT = 'https://api.github.com'.freeze
34
34
 
35
35
  # The value sent in the http header for 'User-Agent' if none is set
36
36
  DEFAULT_USER_AGENT = "Github Ruby Gem #{Github::VERSION::STRING}".freeze
@@ -2,8 +2,50 @@
2
2
 
3
3
  module Github
4
4
  class GitData
5
+ # Since blobs can be any arbitrary binary data, the input and responses for
6
+ # the blob api takes an encoding parameter that can be either utf-8 or base64.
7
+ # If your data cannot be losslessly sent as a UTF-8 string, you can base64 encode it.
5
8
  module Blobs
6
9
 
10
+ VALID_BLOB_PARAM_NAMES = %w[ content encoding ].freeze
11
+
12
+ # Get a blob
13
+ #
14
+ # = Examples
15
+ # @github = Github.new
16
+ # @github.git_data.blob 'user-name', 'repo-name', 'sha'
17
+ #
18
+ def blob(user_name, repo_name, sha, params={})
19
+ _update_user_repo_params(user_name, repo_name)
20
+ _validate_user_repo_params(user, repo) unless user? && repo?
21
+ _validate_presence_of sha
22
+ _normalize_params_keys(params)
23
+
24
+ get("/repos/#{user}/#{repo}/git/blobs/#{sha}", params)
25
+ end
26
+
27
+ # Create a blob
28
+ #
29
+ # = Inputs
30
+ # * <tt>:content</tt> - String of content
31
+ # * <tt>:encoding</tt> - String containing encoding<tt>utf-8</tt> or <tt>base64</tt>
32
+ # = Examples
33
+ # @github = Github.new
34
+ # @github.git_data.create_blob 'user-name', 'repo-name',
35
+ # "content" => "Content of the blob",
36
+ # "encoding" => "utf-8"
37
+ #
38
+ def create_blob(user_name, repo_name=nil, params={})
39
+ _update_user_repo_params(user_name, repo_name)
40
+ _validate_user_repo_params(user, repo) unless user? && repo?
41
+ _normalize_params_keys(params)
42
+ _filter_params_keys(VALID_BLOB_PARAM_NAMES, params)
43
+
44
+ raise ArgumentError, "Required params are: #{VALID_BLOB_PARAM_NAMES.join(', ')}" unless _validate_inputs(VALID_BLOB_PARAM_NAMES, params)
45
+
46
+ post("/repos/#{user}/#{repo}/git/blobs", params)
47
+ end
48
+
7
49
  end # Blobs
8
50
  end # GitData
9
51
  end # Github
@@ -4,6 +4,75 @@ module Github
4
4
  class GitData
5
5
  module Commits
6
6
 
7
+ VALID_COMMIT_PARAM_NAMES = %w[
8
+ message
9
+ tree
10
+ parents
11
+ author
12
+ committer
13
+ name
14
+ email
15
+ date
16
+ ].freeze
17
+
18
+ # Get a commit
19
+ #
20
+ # = Examples
21
+ # @github = Github.new
22
+ # @github.git_data.commit 'user-name', 'repo-name', 'sha'
23
+ #
24
+ def commit(user_name, repo_name, sha, params={})
25
+ _update_user_repo_params(user_name, repo_name)
26
+ _validate_user_repo_params(user, repo) unless user? && repo?
27
+ _validate_presence_of sha
28
+ _normalize_params_keys(params)
29
+
30
+ get("/repos/#{user}/#{repo}/git/commits/#{sha}", params)
31
+ end
32
+
33
+ # Create a commit
34
+ #
35
+ # = Parameters
36
+ # * <tt>message</tt> - String of the commit message
37
+ # * <tt>tree</tt> - String of the SHA of the tree object this commit points to
38
+ # * <tt>parents</tt> - Array of the SHAs of the commits that were the parents of this commit. If omitted or empty, the commit will be written as a root commit. For a single parent, an array of one SHA should be provided, for a merge commit, an array of more than one should be provided.
39
+ #
40
+ # = Optional Parameters
41
+ #
42
+ # The committer section is optional and will be filled with the author data if omitted. If the author section is omitted, it will be filled in with the authenticated users information and the current date.
43
+ #
44
+ # * author.name:: String of the name of the author of the commit
45
+ # * author.email:: String of the email of the author of the commit
46
+ # * author.date:: Timestamp of when this commit was authored
47
+ # * committer.name:: String of the name of the committer of the commit
48
+ # * committer.email:: String of the email of the committer of the commit
49
+ # * committer.date:: Timestamp of when this commit was committed
50
+ #
51
+ # = Examples
52
+ # @github = Github.new
53
+ # @github.git_data.create_commit 'user-name', 'repo-name',
54
+ # "message": "my commit message",
55
+ # "author": {
56
+ # "name": "Scott Chacon",
57
+ # "email": "schacon@gmail.com",
58
+ # "date": "2008-07-09T16:13:30+12:00"
59
+ # },
60
+ # "parents": [
61
+ # "7d1b31e74ee336d15cbd21741bc88a537ed063a0"
62
+ # ],
63
+ # "tree": "827efc6d56897b048c772eb4087f854f46256132"]
64
+ #
65
+ def create_commit(user_name=nil, repo_name=nil, params={})
66
+ _update_user_repo_params(user_name, repo_name)
67
+ _validate_user_repo_params(user, repo) unless user? && repo?
68
+ _normalize_params_keys(params)
69
+ _filter_params_keys(VALID_COMMIT_PARAM_NAMES, params)
70
+
71
+ raise ArgumentError, "Required params are: message, tree, parents" unless _validate_inputs(%w[ message tree parents ], params)
72
+
73
+ post("/repos/#{user}/#{repo}/git/commits", params)
74
+ end
75
+
7
76
  end # Commits
8
77
  end # GitData
9
78
  end # Github
@@ -4,6 +4,110 @@ module Github
4
4
  class GitData
5
5
  module References
6
6
 
7
+ VALID_REF_PARAM_NAMES = %w[ ref sha force ].freeze
8
+
9
+ VALID_REF_PARAM_VALUES = {
10
+ 'ref' => %r{^refs\/\w+\/\w+(\/\w+)*} # test fully qualified reference
11
+ }
12
+
13
+ # Get a reference
14
+ #
15
+ # The ref in the URL must be formatted as <tt>heads/branch</tt>,
16
+ # not just branch. For example, the call to get the data for a
17
+ # branch named <tt>sc/featureA</tt> would be formatted as
18
+ # <tt>heads/sc/featureA</tt>
19
+ #
20
+ # = Examples
21
+ # @github = Github.new
22
+ # @github.git_data.reference 'user-name', 'repo-name', 'reference'
23
+ #
24
+ def reference(user_name, repo_name, ref, params={})
25
+ _update_user_repo_params(user_name, repo_name)
26
+ _validate_user_repo_params(user, repo) unless user? && repo?
27
+ _validate_presence_of ref
28
+ _normalize_params_keys(params)
29
+
30
+ get("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
31
+ end
32
+
33
+ # Get all references
34
+ #
35
+ # This will return an array of all the references on the system,
36
+ # including things like notes and stashes if they exist on the server.
37
+ # Anything in the namespace, not just <tt>heads</tt> and <tt>tags</tt>,
38
+ # though that would be the most common.
39
+ #
40
+ # = Examples
41
+ # @github = Github.new
42
+ # @github.git_data.references 'user-name', 'repo-name'
43
+ #
44
+ # @github.git_data.references 'user-name', 'repo-name', 'tags'
45
+ #
46
+ def references(user_name, repo_name, ref=nil, params={})
47
+ _update_user_repo_params(user_name, repo_name)
48
+ _validate_user_repo_params(user, repo) unless user? && repo?
49
+ _normalize_params_keys(params)
50
+
51
+ response = if ref
52
+ get("/repos/#{user}/#{repo}/git/refs/#{ref}")
53
+ else
54
+ get("/repos/#{user}/#{repo}/git/refs")
55
+ end
56
+ return response unless block_given?
57
+ response.each { |el| yield el }
58
+ end
59
+
60
+ # Create a reference
61
+ #
62
+ # = Inputs
63
+ # * <tt>:ref</tt> - String of the name of the fully qualified reference (ie: refs/heads/master). If it doesn’t start with ‘refs’ and have at least two slashes, it will be rejected.
64
+ # * <tt>:sha</tt> - String of the SHA1 value to set this reference to
65
+ #
66
+ # = Examples
67
+ # @github = Github.new
68
+ # @github.git_data.create_reference 'user-name', 'repo-name',
69
+ # "ref" => "refs/heads/master",
70
+ # "sha" => "827efc6d56897b048c772eb4087f854f46256132"
71
+ #
72
+ def create_reference(user_name, repo_name, params={})
73
+ _update_user_repo_params(user_name, repo_name)
74
+ _validate_user_repo_params(user, repo) unless user? && repo?
75
+ _normalize_params_keys(params)
76
+
77
+ raise ArgumentError, "Required params are: ref, sha" unless _validate_inputs(%w[ ref sha ], params)
78
+
79
+ _filter_params_keys(VALID_REF_PARAM_NAMES, params)
80
+ _validate_params_values(VALID_REF_PARAM_VALUES, params)
81
+
82
+ post("/repos/#{user}/#{repo}/git/refs", params)
83
+ end
84
+
85
+ # Update a reference
86
+ #
87
+ # = Inputs
88
+ # * <tt>:sha</tt> - String of the SHA1 value to set this reference to
89
+ # * <tt>:force</tt> - Boolean indicating whether to force the update or to make sure the update is a fast-forward update. The default is <tt>false</tt>, so leaving this out or setting it to false will make sure you’re not overwriting work.
90
+ #
91
+ # = Examples
92
+ # @github = Github.new
93
+ # @github.git_data.create_reference 'user-name', 'repo-name',
94
+ # "sha" => "827efc6d56897b048c772eb4087f854f46256132",
95
+ # "force" => true
96
+ #
97
+ def update_reference(user_name, repo_name, ref, params={})
98
+ _update_user_repo_params(user_name, repo_name)
99
+ _validate_user_repo_params(user, repo) unless user? && repo?
100
+ _validate_presence_of ref
101
+ _normalize_params_keys(params)
102
+
103
+ raise ArgumentError, "Required params are: sha" unless _validate_inputs(%w[ sha ], params)
104
+
105
+ _filter_params_keys(VALID_REF_PARAM_NAMES, params)
106
+ _validate_params_values(VALID_REF_PARAM_VALUES, params)
107
+
108
+ patch("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
109
+ end
110
+
7
111
  end # References
8
112
  end # GitData
9
113
  end # Github
@@ -2,8 +2,77 @@
2
2
 
3
3
  module Github
4
4
  class GitData
5
+ # This tags api only deals with tag objects - so only annotated tags, not lightweight tags.
5
6
  module Tags
6
7
 
8
+ VALID_TAG_PARAM_NAMES = %w[
9
+ tag
10
+ message
11
+ object
12
+ type
13
+ name
14
+ email
15
+ date
16
+ ]
17
+
18
+ VALID_TAG_PARAM_VALUES = {
19
+ 'type' => %w[ blob tree commit ]
20
+ }
21
+
22
+ # Get a tag
23
+ #
24
+ # = Examples
25
+ # @github = Github.new
26
+ # @github.git_data.tag 'user-name', 'repo-name', 'sha'
27
+ #
28
+ def tag(user_name, repo_name, sha, params={})
29
+ _update_user_repo_params(user_name, repo_name)
30
+ _validate_user_repo_params(user, repo) unless user? && repo?
31
+ _validate_presence_of sha
32
+ _normalize_params_keys(params)
33
+
34
+ get("/repos/#{user}/#{repo}/git/tags/#{sha}", params)
35
+ end
36
+
37
+ # Create a tag object
38
+ # Note that creating a tag object does not create the reference that
39
+ # makes a tag in Git. If you want to create an annotated tag in Git,
40
+ # you have to do this call to create the tag object, and then create
41
+ # the <tt>refs/tags/[tag]</tt> reference. If you want to create a lightweight tag, you simply have to create the reference - this call would be unnecessary.
42
+ #
43
+ # = Parameters
44
+ # * <tt>:tag</tt> - String of the tag
45
+ # * <tt>:message</tt> - String of the tag message
46
+ # * <tt>:object</tt> - String of the SHA of the git object this is tagging
47
+ # * <tt>:type</tt> - String of the type of the object we're tagging. Normally this is a <tt>commit</tt> but it can also be a <tt>tree</tt> or a <tt>blob</tt>
48
+ # * tagger.name:: String of the name of the author of the tag
49
+ # * tagger.email:: String of the email of the author of the tag
50
+ # * tagger.date:: Timestamp of when this object was tagged
51
+ #
52
+ # = Examples
53
+ # @github = Github.new
54
+ # @github.git_data.create_tag 'user-name', 'repo-name',
55
+ # "tag" => "v0.0.1",
56
+ # "message" => "initial version\n",
57
+ # "type": "commit",
58
+ # "object": "c3d0be41ecbe669545ee3e94d31ed9a4bc91ee3c",
59
+ # "tagger" => {
60
+ # "name" => "Scott Chacon",
61
+ # "email" => "schacon@gmail.com",
62
+ # "date" => "2011-06-17T14:53:3"
63
+ # }
64
+ #
65
+ def create_tag(user_name, repo_name, params={})
66
+ _update_user_repo_params(user_name, repo_name)
67
+ _validate_user_repo_params(user, repo) unless user? && repo?
68
+ _normalize_params_keys(params)
69
+
70
+ _filter_params_keys(VALID_TAG_PARAM_NAMES, params)
71
+ _validate_params_values(VALID_TAG_PARAM_VALUES, params)
72
+
73
+ post("/repos/#{user}/#{repo}/git/tags", params)
74
+ end
75
+
7
76
  end # Tags
8
77
  end # GitData
9
78
  end # Github
@@ -4,6 +4,86 @@ module Github
4
4
  class GitData
5
5
  module Trees
6
6
 
7
+ VALID_TREE_PARAM_NAMES = %w[
8
+ base_tree
9
+ tree
10
+ path
11
+ mode
12
+ type
13
+ sha
14
+ content
15
+ ].freeze
16
+
17
+ VALID_TREE_PARAM_VALUES = {
18
+ 'mode' => %w[ 100644 100755 040000 160000 120000 ],
19
+ 'type' => %w[ blob tree commit ]
20
+ }
21
+
22
+ # Get a tree
23
+ #
24
+ # = Examples
25
+ # @github = Github.new
26
+ # @github.git_data.tree 'user-name', 'repo-name', 'sha'
27
+ # @github.git_data.tree 'user-name', 'repo-name', 'sha' do |file|
28
+ # file.path
29
+ # end
30
+ #
31
+ def tree(user_name, repo_name, sha, params={})
32
+ _update_user_repo_params(user_name, repo_name)
33
+ _validate_user_repo_params(user, repo) unless user? && repo?
34
+ _validate_presence_of sha
35
+ _normalize_params_keys(params)
36
+
37
+ response = if params['recursive']
38
+ params['recursive'] = 1
39
+ get("/repos/#{user}/#{repo}/git/trees/#{sha}", params)
40
+ else
41
+ get("/repos/#{user}/#{repo}/git/trees/#{sha.to_s}", params)
42
+ end
43
+ return response unless block_given?
44
+ response.tree.each { |el| yield el }
45
+ end
46
+
47
+ # Create a tree
48
+ #
49
+ # The tree creation API will take nested entries as well.
50
+ # If both a tree and a nested path modifying that tree are specified,
51
+ # it will overwrite the contents of that tree with the new path contents
52
+ # and write a new tree out.
53
+ #
54
+ # = Parameters
55
+ # * <tt>:base_tree</tt> - optional string of the SHA1 of the tree you want to update with new data
56
+ # * <tt>:tree</tt> - array of hash objects(of <tt>:path</tt>, <tt>:mode</tt>, <tt>:type</tt> and <tt>sha</tt>)
57
+ # * tree.path:: String of the file referenced in the tree
58
+ # * tree.mode:: String of the file mode - one of <tt>100644</tt> for file(blob), <tt>100755</tt> for executable (blob), <tt>040000</tt> for subdirectory (tree), <tt>160000</tt> for submodule (commit) or <tt>120000</tt> for a blob that specifies the path of a symlink
59
+ # * tree.type:: String of <tt>blob</tt>, <tt>tree</tt>, <tt>commit</tt>
60
+ # * tree.sha:: String of SHA1 checksum ID of the object in the tree
61
+ # * tree.content:: String of content you want this file to have - GitHub will write this blob out and use the SHA for this entry. Use either this or <tt>tree.sha</tt>
62
+ #
63
+ # = Examples
64
+ # @github = Github.new
65
+ # @github.git_data.create_tree 'user-name', 'repo-name',
66
+ # "tree" => [
67
+ # {
68
+ # "path" => "file.rb",
69
+ # "mode" => "100644",
70
+ # "type" => "blob",
71
+ # "sha" => "44b4fc6d56897b048c772eb4087f854f46256132"
72
+ # },
73
+ # ...
74
+ # ]
75
+ #
76
+ def create_tree(user_name=nil, repo_name=nil, params={})
77
+ _update_user_repo_params(user_name, repo_name)
78
+ _validate_user_repo_params(user, repo) unless user? && repo?
79
+ _normalize_params_keys(params)
80
+
81
+ _filter_params_keys(VALID_TREE_PARAM_NAMES, params['tree'])
82
+ _validate_params_values(VALID_TREE_PARAM_VALUES, params['tree'])
83
+
84
+ post("/repos/#{user}/#{repo}/git/trees", params)
85
+ end
86
+
7
87
  end # Trees
8
88
  end # GitData
9
89
  end # Github
@@ -15,6 +15,7 @@ module Github
15
15
  def issue_comments(user_name, repo_name, issue_id, params={})
16
16
  _update_user_repo_params(user_name, repo_name)
17
17
  _validate_user_repo_params(user, repo) unless user? && repo?
18
+ _validate_presence_of issue_id
18
19
  _normalize_params_keys(params)
19
20
 
20
21
  get("/repos/#{user}/#{repo}/issues/#{issue_id}/comments", params)
@@ -5,6 +5,7 @@ module Github
5
5
  module Members
6
6
 
7
7
  # List members
8
+ #
8
9
  # List all users who are members of an organization. A member is a user
9
10
  # that belongs to at least 1 team in the organization.
10
11
  # If the authenticated user is also a member of this organization then
@@ -3,48 +3,99 @@
3
3
  module Github
4
4
  class Repos
5
5
  module Keys
6
-
7
- # List keys
6
+
7
+ VALID_KEY_PARAM_NAMES = %w[ title key ].freeze
8
+
9
+ # List deploy keys
8
10
  #
9
- # GET /repos/:user/:repo/keys
11
+ # = Examples
12
+ # @github = Github.new
13
+ # @github.repos.keys 'user-name', 'repo-name'
14
+ # @github.repos.keys 'user-name', 'repo-name' { |key| ... }
10
15
  #
11
- def keys(user, repo)
12
- get("/repos/#{user}/#{repo}/keys")
16
+ def keys(user_name=nil, repo_name=nil, params={})
17
+ _update_user_repo_params(user_name, repo_name)
18
+ _validate_user_repo_params(user, repo) unless user? && repo?
19
+ _normalize_params_keys(params)
20
+
21
+ response = get("/repos/#{user}/#{repo}/keys")
22
+ return response unless block_given?
23
+ response.each { |el| yield el }
13
24
  end
14
25
 
15
26
  # Get a key
16
27
  #
17
- # GET /repos/:user/:repo/keys/:id
28
+ # = Examples
29
+ # @github = Github.new
30
+ # @github.repos.get_key 'user-name', 'repo-name', 'key-id'
18
31
  #
19
- def get_key(user, repo, key_id)
32
+ def get_key(user_name, repo_name, key_id, params={})
33
+ _update_user_repo_params(user_name, repo_name)
34
+ _validate_user_repo_params(user, repo) unless user? && repo?
35
+ _validate_presence_of key_id
36
+ _normalize_params_keys(params)
37
+
20
38
  get("/repos/#{user}/#{repo}/keys/#{key_id}")
21
39
  end
22
40
 
23
41
  # Create a key
24
42
  #
25
- # POST /repos/:user/:repo/keys
26
- def create_key(user, repo, params={})
43
+ # = Inputs
44
+ # * <tt>:title</tt> - Required string.
45
+ # * <tt>:key</tt> - Required string.
46
+ #
47
+ # = Examples
48
+ # @github = Github.new
49
+ # @github.repos.create_key 'user-name', 'repo-name',
50
+ # "title" => "octocat@octomac",
51
+ # "key" => "ssh-rsa AAA..."
52
+ #
53
+ def create_key(user_name=nil, repo_name=nil, params={})
54
+ _update_user_repo_params(user_name, repo_name)
55
+ _validate_user_repo_params(user, repo) unless user? && repo?
27
56
  _normalize_params_keys(params)
28
- _filter_params_keys(%w[ title key ], params)
57
+ _filter_params_keys(VALID_KEY_PARAM_NAMES, params)
58
+
59
+ raise ArgumentError, "Required params are: #{VALID_KEY_PARAM_NAMES.join(', ')}" unless _validate_inputs(VALID_KEY_PARAM_NAMES, params)
29
60
 
30
61
  post("/repos/#{user}/#{repo}/keys", params)
31
62
  end
32
63
 
33
- # Edit key
64
+ # Edit a key
65
+ #
66
+ # = Inputs
67
+ # * <tt>:title</tt> - Required string.
68
+ # * <tt>:key</tt> - Required string.
34
69
  #
35
- # PATCH /repos/:user/:repo/keys/:id
70
+ # = Examples
71
+ # @github = Github.new
72
+ # @github.repos.create_key 'user-name', 'repo-name',
73
+ # "title" => "octocat@octomac",
74
+ # "key" => "ssh-rsa AAA..."
36
75
  #
37
- def edit_key(user, repo, key_id)
76
+ def edit_key(user_name, repo_name, key_id, params={})
77
+ _update_user_repo_params(user_name, repo_name)
78
+ _validate_user_repo_params(user, repo) unless user? && repo?
79
+ _validate_presence_of key_id
80
+
38
81
  _normalize_params_keys(params)
39
- _filter_params_keys(%w[ title key ], params)
82
+ _filter_params_keys(VALID_KEY_PARAM_NAMES, params)
40
83
 
41
84
  patch("/repos/#{user}/#{repo}/keys/#{key_id}")
42
85
  end
43
-
86
+
44
87
  # Delete key
45
88
  #
46
- # DELETE /repos/:user/:repo/keys/:id
47
- def delete_key(user, repo, key_id)
89
+ # = Examples
90
+ # @github = Github.new
91
+ # @github.repos.delete_key 'user-name', 'repo-name', 'key-id'
92
+ #
93
+ def delete_key(user_name, repo_name, key_id, params={})
94
+ _update_user_repo_params(user_name, repo_name)
95
+ _validate_user_repo_params(user, repo) unless user? && repo?
96
+ _validate_presence_of key_id
97
+ _normalize_params_keys(params)
98
+
48
99
  delete("/repos/#{user}/#{repo}/keys/#{key_id}")
49
100
  end
50
101