github_api 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/README.md +11 -0
  2. data/lib/github_api/api.rb +20 -22
  3. data/lib/github_api/core_ext/hash.rb +17 -0
  4. data/lib/github_api/events.rb +3 -3
  5. data/lib/github_api/git_data/blobs.rb +2 -2
  6. data/lib/github_api/git_data/commits.rb +2 -2
  7. data/lib/github_api/git_data/references.rb +5 -5
  8. data/lib/github_api/git_data/tags.rb +2 -2
  9. data/lib/github_api/git_data/trees.rb +2 -2
  10. data/lib/github_api/issues.rb +4 -4
  11. data/lib/github_api/issues/comments.rb +6 -6
  12. data/lib/github_api/issues/events.rb +2 -2
  13. data/lib/github_api/issues/labels.rb +10 -10
  14. data/lib/github_api/issues/milestones.rb +5 -5
  15. data/lib/github_api/page_iterator.rb +4 -3
  16. data/lib/github_api/pull_requests.rb +8 -8
  17. data/lib/github_api/pull_requests/comments.rb +5 -5
  18. data/lib/github_api/repos.rb +15 -8
  19. data/lib/github_api/repos/collaborators.rb +4 -4
  20. data/lib/github_api/repos/comments.rb +121 -0
  21. data/lib/github_api/repos/commits.rb +56 -177
  22. data/lib/github_api/repos/contents.rb +3 -0
  23. data/lib/github_api/repos/downloads.rb +4 -4
  24. data/lib/github_api/repos/forks.rb +2 -2
  25. data/lib/github_api/repos/hooks.rb +6 -6
  26. data/lib/github_api/repos/keys.rb +5 -5
  27. data/lib/github_api/repos/merging.rb +1 -0
  28. data/lib/github_api/repos/starring.rb +3 -1
  29. data/lib/github_api/repos/statuses.rb +2 -2
  30. data/lib/github_api/repos/watching.rb +1 -1
  31. data/lib/github_api/version.rb +1 -1
  32. data/spec/github/api/set_spec.rb +19 -0
  33. data/spec/github/repos/comments/create_spec.rb +86 -0
  34. data/spec/github/repos/comments/delete_spec.rb +47 -0
  35. data/spec/github/repos/comments/get_spec.rb +54 -0
  36. data/spec/github/repos/comments/list_spec.rb +120 -0
  37. data/spec/github/repos/comments/update_spec.rb +54 -0
  38. data/spec/github/repos/commits/compare_spec.rb +37 -0
  39. data/spec/github/repos/commits/get_spec.rb +56 -0
  40. data/spec/github/repos/commits/list_spec.rb +63 -0
  41. data/spec/github/repos/downloads/create_spec.rb +66 -0
  42. data/spec/github/repos/downloads/delete_spec.rb +48 -0
  43. data/spec/github/repos/downloads/get_spec.rb +58 -0
  44. data/spec/github/repos/downloads/list_spec.rb +63 -0
  45. data/spec/github/repos/downloads/upload_spec.rb +32 -0
  46. data/spec/github/repos/downloads_spec.rb +1 -233
  47. data/spec/github/repos_spec.rb +2 -0
  48. data/spec/spec_helper.rb +1 -0
  49. metadata +48 -34
  50. data/spec/github/repos/commits_spec.rb +0 -471
data/README.md CHANGED
@@ -11,6 +11,17 @@ A Ruby wrapper for the GitHub REST API v3.
11
11
 
12
12
  Supports all the API methods(nearly 200). It's build in a modular way, that is, you can either instantiate the whole api wrapper Github.new or use parts of it e.i. Github::Repos.new if working solely with repositories is your main concern.
13
13
 
14
+ ## Features
15
+
16
+ * Intuitive GitHub API interface navigation.
17
+ * Modular design allows for working with parts of API.
18
+ * Fully customizable including advanced middleware stack construction.
19
+ * Requests pagination.
20
+ * Easy error handling.
21
+ * Custom Mime Types specification (TODO)
22
+ * Flexible arguments parsing (In progress).
23
+ * Full tested with test coverage above 90%.
24
+
14
25
  ## Installation
15
26
 
16
27
  Install the gem by issuing
@@ -13,6 +13,7 @@ require 'github_api/api/actions'
13
13
  require 'github_api/api_factory'
14
14
 
15
15
  module Github
16
+ # Core class for api interface operations
16
17
  class API
17
18
  include Constants
18
19
  include Authorization
@@ -86,33 +87,30 @@ module Github
86
87
  end
87
88
  end
88
89
 
89
- def update_settings(options={})
90
- options.each do |key, val|
91
- self.send(:"#{key}", val)
90
+ # Set an option to a given value
91
+ def set(option, value=(not_set = true), &block)
92
+ raise ArgumentError, 'value not set' if block and !not_set
93
+
94
+ if not_set
95
+ set_options option
96
+ return self
97
+ end
98
+
99
+ if respond_to?("#{option}=")
100
+ return __send__("#{option}=", value)
92
101
  end
93
- end
94
102
 
95
- def _update_user_repo_params(user_name, repo_name=nil) # :nodoc:
96
- self.user = user_name || self.user
97
- self.repo = repo_name || self.repo
103
+ self
98
104
  end
99
105
 
100
- # TODO: See whether still needed, consider adding to core_exts
101
- def _hash_traverse(hash, &block)
102
- hash.each do |key, val|
103
- block.call(key)
104
- case val
105
- when Hash
106
- val.keys.each do |k|
107
- _hash_traverse(val, &block)
108
- end
109
- when Array
110
- val.each do |item|
111
- _hash_traverse(item, &block)
112
- end
113
- end
106
+ private
107
+
108
+ # Set multiple options
109
+ def set_options(options)
110
+ unless options.respond_to?(:each)
111
+ raise ArgumentError, 'cannot iterate over value'
114
112
  end
115
- return hash
113
+ options.each { |key, value| set(key, value) }
116
114
  end
117
115
 
118
116
  def _merge_mime_type(resource, params) # :nodoc:
@@ -53,4 +53,21 @@ class Hash # :nodoc:
53
53
  self.all_keys.include? key
54
54
  end unless method_defined?(:has_deep_key?)
55
55
 
56
+ def self.hash_traverse(hash, &block)
57
+ hash.each do |key, val|
58
+ block.call(key)
59
+ case val
60
+ when Hash
61
+ val.keys.each do |k|
62
+ _hash_traverse(val, &block)
63
+ end
64
+ when Array
65
+ val.each do |item|
66
+ _hash_traverse(item, &block)
67
+ end
68
+ end
69
+ end
70
+ return hash
71
+ end
72
+
56
73
  end # Hash
@@ -34,7 +34,7 @@ module Github
34
34
  # github.events.repository 'user-name', 'repo-name' { |event| ... }
35
35
  #
36
36
  def repository(user_name, repo_name, params={})
37
- _update_user_repo_params(user_name, repo_name)
37
+ set :user => user_name, :repo => repo_name
38
38
  assert_presence_of user, repo
39
39
  normalize! params
40
40
 
@@ -55,7 +55,7 @@ module Github
55
55
  # github.events.issue 'user-name', 'repo-name' { |event| ... }
56
56
  #
57
57
  def issue(user_name, repo_name, params={})
58
- _update_user_repo_params(user_name, repo_name)
58
+ set :user => user_name, :repo => repo_name
59
59
  assert_presence_of user, repo
60
60
  normalize! params
61
61
 
@@ -75,7 +75,7 @@ module Github
75
75
  # github.events.network 'user-name', 'repo-name' { |event| ... }
76
76
  #
77
77
  def network(user_name, repo_name, params={})
78
- _update_user_repo_params(user_name, repo_name)
78
+ set :user => user_name, :repo => repo_name
79
79
  assert_presence_of user, repo
80
80
  normalize! params
81
81
 
@@ -20,7 +20,7 @@ module Github
20
20
  # github.git_data.blobs.get 'user-name', 'repo-name', 'sha'
21
21
  #
22
22
  def get(user_name, repo_name, sha, params={})
23
- _update_user_repo_params(user_name, repo_name)
23
+ set :user => user_name, :repo => repo_name
24
24
  assert_presence_of user, repo, sha
25
25
  normalize! params
26
26
 
@@ -40,7 +40,7 @@ module Github
40
40
  # "encoding" => "utf-8"
41
41
  #
42
42
  def create(user_name, repo_name, params={})
43
- _update_user_repo_params(user_name, repo_name)
43
+ set :user => user_name, :repo => repo_name
44
44
  assert_presence_of user, repo
45
45
 
46
46
  normalize! params
@@ -32,7 +32,7 @@ module Github
32
32
  # github.git_data.commits.get 'user-name', 'repo-name', 'sha'
33
33
  #
34
34
  def get(user_name, repo_name, sha, params={})
35
- _update_user_repo_params(user_name, repo_name)
35
+ set :user => user_name, :repo => repo_name
36
36
  assert_presence_of user, repo, sha
37
37
  normalize! params
38
38
 
@@ -73,7 +73,7 @@ module Github
73
73
  # "tree": "827efc6d56897b048c772eb4087f854f46256132"]
74
74
  #
75
75
  def create(user_name, repo_name, params={})
76
- _update_user_repo_params(user_name, repo_name)
76
+ set :user => user_name, :repo => repo_name
77
77
  assert_presence_of user, repo
78
78
  normalize! params
79
79
  filter! VALID_COMMIT_PARAM_NAMES, params
@@ -28,7 +28,7 @@ module Github
28
28
  # github.git_data.references.list 'user-name', 'repo-name', ref:'tags'
29
29
  #
30
30
  def list(user_name, repo_name, params={})
31
- _update_user_repo_params(user_name, repo_name)
31
+ set :user => user_name, :repo => repo_name
32
32
  assert_presence_of user, repo
33
33
  normalize! params
34
34
 
@@ -56,7 +56,7 @@ module Github
56
56
  # github.git_data.references.get 'user-name', 'repo-name', 'heads/branch'
57
57
  #
58
58
  def get(user_name, repo_name, ref, params={})
59
- _update_user_repo_params(user_name, repo_name)
59
+ set :user => user_name, :repo => repo_name
60
60
  assert_presence_of user, repo, ref
61
61
  validate_reference ref
62
62
  normalize! params
@@ -79,7 +79,7 @@ module Github
79
79
  # "sha" => "827efc6d56897b048c772eb4087f854f46256132"
80
80
  #
81
81
  def create(user_name, repo_name, params={})
82
- _update_user_repo_params(user_name, repo_name)
82
+ set :user => user_name, :repo => repo_name
83
83
  normalize! params
84
84
  filter! VALID_REF_PARAM_NAMES, params
85
85
  assert_presence_of user, repo, params['ref']
@@ -102,7 +102,7 @@ module Github
102
102
  # "force" => true
103
103
  #
104
104
  def update(user_name, repo_name, ref, params={})
105
- _update_user_repo_params(user_name, repo_name)
105
+ set :user => user_name, :repo => repo_name
106
106
  assert_presence_of user, repo, ref
107
107
  validate_reference ref
108
108
  normalize! params
@@ -120,7 +120,7 @@ module Github
120
120
  # "ref" => "refs/heads/master",
121
121
  #
122
122
  def delete(user_name, repo_name, ref, params={})
123
- _update_user_repo_params(user_name, repo_name)
123
+ set :user => user_name, :repo => repo_name
124
124
  assert_presence_of user, repo, ref
125
125
  normalize! params
126
126
 
@@ -34,7 +34,7 @@ module Github
34
34
  # github.git_data.tags.get 'user-name', 'repo-name', 'sha'
35
35
  #
36
36
  def get(user_name, repo_name, sha, params={})
37
- _update_user_repo_params(user_name, repo_name)
37
+ set :user => user_name, :repo => repo_name
38
38
  assert_presence_of user, repo, sha
39
39
  normalize! params
40
40
 
@@ -71,7 +71,7 @@ module Github
71
71
  # }
72
72
  #
73
73
  def create(user_name, repo_name, params={})
74
- _update_user_repo_params(user_name, repo_name)
74
+ set :user => user_name, :repo => repo_name
75
75
  assert_presence_of user, repo
76
76
  normalize! params
77
77
 
@@ -40,7 +40,7 @@ module Github
40
40
  # github.git_data.trees.get 'user-name', 'repo-name', 'sha', 'recursive' => true
41
41
  #
42
42
  def get(user_name, repo_name, sha, params={})
43
- _update_user_repo_params(user_name, repo_name)
43
+ set :user => user_name, :repo => repo_name
44
44
  assert_presence_of user, repo, sha
45
45
  normalize! params
46
46
 
@@ -85,7 +85,7 @@ module Github
85
85
  # ]
86
86
  #
87
87
  def create(user_name, repo_name, params={})
88
- _update_user_repo_params(user_name, repo_name)
88
+ set :user => user_name, :repo => repo_name
89
89
  assert_presence_of user, repo
90
90
  normalize! params
91
91
  assert_required_keys(%w[ tree ], params)
@@ -132,7 +132,7 @@ module Github
132
132
  # :direction => 'asc'
133
133
  #
134
134
  def list_repo(user_name, repo_name, params={})
135
- _update_user_repo_params(user_name, repo_name)
135
+ set :user => user_name, :repo => repo_name
136
136
  assert_presence_of user, repo
137
137
 
138
138
  normalize! params
@@ -153,7 +153,7 @@ module Github
153
153
  # github.issues.get 'user-name', 'repo-name', 'issue-id'
154
154
  #
155
155
  def get(user_name, repo_name, issue_id, params={})
156
- _update_user_repo_params(user_name, repo_name)
156
+ set :user => user_name, :repo => repo_name
157
157
  assert_presence_of user, repo, issue_id
158
158
 
159
159
  normalize! params
@@ -184,7 +184,7 @@ module Github
184
184
  # ]
185
185
  #
186
186
  def create(user_name, repo_name, params={})
187
- _update_user_repo_params(user_name, repo_name)
187
+ set :user => user_name, :repo => repo_name
188
188
  assert_presence_of user, repo
189
189
 
190
190
  normalize! params
@@ -218,7 +218,7 @@ module Github
218
218
  # ]
219
219
  #
220
220
  def edit(user_name, repo_name, issue_id, params={})
221
- _update_user_repo_params(user_name, repo_name)
221
+ set :user => user_name, :repo => repo_name
222
222
  assert_presence_of user, repo, issue_id
223
223
 
224
224
  normalize! params
@@ -22,7 +22,7 @@ module Github
22
22
  # github.issues.comments.all 'user-name', 'repo-name', 'issue-id' {|com| .. }
23
23
  #
24
24
  def list(user_name, repo_name, issue_id, params={})
25
- _update_user_repo_params(user_name, repo_name)
25
+ set :user => user_name, :repo => repo_name
26
26
  assert_presence_of user, repo, issue_id
27
27
 
28
28
  normalize! params
@@ -41,7 +41,7 @@ module Github
41
41
  # github.issues.comments.find 'user-name', 'repo-name', 'comment-id'
42
42
  #
43
43
  def get(user_name, repo_name, comment_id, params={})
44
- _update_user_repo_params(user_name, repo_name)
44
+ set :user => user_name, :repo => repo_name
45
45
  assert_presence_of user, repo, comment_id
46
46
 
47
47
  normalize! params
@@ -62,7 +62,7 @@ module Github
62
62
  # "body" => 'a new comment'
63
63
  #
64
64
  def create(user_name, repo_name, issue_id, params={})
65
- _update_user_repo_params(user_name, repo_name)
65
+ set :user => user_name, :repo => repo_name
66
66
  assert_presence_of user, repo, issue_id
67
67
 
68
68
  normalize! params
@@ -84,7 +84,7 @@ module Github
84
84
  # "body" => 'a new comment'
85
85
  #
86
86
  def edit(user_name, repo_name, comment_id, params={})
87
- _update_user_repo_params(user_name, repo_name)
87
+ set :user => user_name, :repo => repo_name
88
88
  assert_presence_of user, repo, comment_id
89
89
 
90
90
  normalize! params
@@ -92,7 +92,7 @@ module Github
92
92
  filter! VALID_ISSUE_COMMENT_PARAM_NAME, params
93
93
  assert_required_keys(%w[ body ], params)
94
94
 
95
- patch_request("/repos/#{user}/#{repo}/issues/comments/#{comment_id}")
95
+ patch_request("/repos/#{user}/#{repo}/issues/comments/#{comment_id}", params)
96
96
  end
97
97
 
98
98
  # Delete a comment
@@ -102,7 +102,7 @@ module Github
102
102
  # github.issues.comments.delete 'user-name', 'repo-name', 'comment-id'
103
103
  #
104
104
  def delete(user_name, repo_name, comment_id, params={})
105
- _update_user_repo_params(user_name, repo_name)
105
+ set :user => user_name, :repo => repo_name
106
106
  assert_presence_of user, repo, comment_id
107
107
 
108
108
  normalize! params
@@ -21,7 +21,7 @@ module Github
21
21
  # github.issues.events.list 'user-name', 'repo-name'
22
22
  #
23
23
  def list(user_name, repo_name, issue_id=nil, params={})
24
- _update_user_repo_params(user_name, repo_name)
24
+ set :user => user_name, :repo => repo_name
25
25
  assert_presence_of user, repo
26
26
  normalize! params
27
27
 
@@ -42,7 +42,7 @@ module Github
42
42
  # github.issues.events.get 'user-name', 'repo-name', 'event-id'
43
43
  #
44
44
  def get(user_name, repo_name, event_id, params={})
45
- _update_user_repo_params(user_name, repo_name)
45
+ set :user => user_name, :repo => repo_name
46
46
  assert_presence_of user, repo, event_id
47
47
  normalize! params
48
48
 
@@ -18,7 +18,7 @@ module Github
18
18
  # github.issues.labels.list { |label| ... }
19
19
  #
20
20
  def list(user_name, repo_name, params={})
21
- _update_user_repo_params(user_name, repo_name)
21
+ set :user => user_name, :repo => repo_name
22
22
  assert_presence_of user, repo
23
23
  normalize! params
24
24
 
@@ -35,7 +35,7 @@ module Github
35
35
  # github.issues.labels.find 'user-name', 'repo-name', 'label-id'
36
36
  #
37
37
  def get(user_name, repo_name, label_id, params={})
38
- _update_user_repo_params(user_name, repo_name)
38
+ set :user => user_name, :repo => repo_name
39
39
  assert_presence_of user, repo, label_id
40
40
  normalize! params
41
41
 
@@ -54,7 +54,7 @@ module Github
54
54
  # github.issues.labels.create :name => 'API', :color => 'FFFFFF'
55
55
  #
56
56
  def create(user_name, repo_name, params={})
57
- _update_user_repo_params(user_name, repo_name)
57
+ set :user => user_name, :repo => repo_name
58
58
  assert_presence_of user, repo
59
59
 
60
60
  normalize! params
@@ -76,7 +76,7 @@ module Github
76
76
  # :name => 'API', :color => "FFFFFF"
77
77
  #
78
78
  def update(user_name, repo_name, label_id, params={})
79
- _update_user_repo_params(user_name, repo_name)
79
+ set :user => user_name, :repo => repo_name
80
80
  assert_presence_of user, repo, label_id
81
81
 
82
82
  normalize! params
@@ -94,7 +94,7 @@ module Github
94
94
  # github.issues.labels.delete 'user-name', 'repo-name', 'label-id'
95
95
  #
96
96
  def delete(user_name, repo_name, label_id, params={})
97
- _update_user_repo_params(user_name, repo_name)
97
+ set :user => user_name, :repo => repo_name
98
98
  assert_presence_of user, repo
99
99
 
100
100
  assert_presence_of label_id
@@ -110,7 +110,7 @@ module Github
110
110
  # @github.issues.labels.issue 'user-name', 'repo-name', 'issue-id'
111
111
  #
112
112
  def issue(user_name, repo_name, issue_id, params={})
113
- _update_user_repo_params(user_name, repo_name)
113
+ set :user => user_name, :repo => repo_name
114
114
  assert_presence_of user, repo, issue_id
115
115
  normalize! params
116
116
 
@@ -127,7 +127,7 @@ module Github
127
127
  params = args.extract_options!
128
128
  params['data'] = args unless args.empty?
129
129
 
130
- _update_user_repo_params(user_name, repo_name)
130
+ set :user => user_name, :repo => repo_name
131
131
  assert_presence_of user, repo, issue_id
132
132
  normalize! params
133
133
 
@@ -147,7 +147,7 @@ module Github
147
147
  # github.issues.labels.remove 'user-name', 'repo-name', 'issue-id'
148
148
  #
149
149
  def remove(user_name, repo_name, issue_id, label_id=nil, params={})
150
- _update_user_repo_params(user_name, repo_name)
150
+ set :user => user_name, :repo => repo_name
151
151
  assert_presence_of user, repo, issue_id
152
152
  normalize! params
153
153
 
@@ -170,7 +170,7 @@ module Github
170
170
  params = args.extract_options!
171
171
  params['data'] = args unless args.empty?
172
172
 
173
- _update_user_repo_params(user_name, repo_name)
173
+ set :user => user_name, :repo => repo_name
174
174
  assert_presence_of user, repo, issue_id
175
175
  normalize! params
176
176
 
@@ -184,7 +184,7 @@ module Github
184
184
  # github.issues.labels. 'user-name', 'repo-name', 'milestone-id'
185
185
  #
186
186
  def milestone(user_name, repo_name, milestone_id, params={})
187
- _update_user_repo_params(user_name, repo_name)
187
+ set :user => user_name, :repo => repo_name
188
188
  assert_presence_of user, repo, milestone_id
189
189
  normalize! params
190
190
 
@@ -39,7 +39,7 @@ module Github
39
39
  # :direction => 'asc'
40
40
  #
41
41
  def list(user_name, repo_name, params={})
42
- _update_user_repo_params(user_name, repo_name)
42
+ set :user => user_name, :repo => repo_name
43
43
  assert_presence_of user, repo
44
44
 
45
45
  normalize! params
@@ -59,7 +59,7 @@ module Github
59
59
  # github.issues.milestones.get 'user-name', 'repo-name', 'milestone-id'
60
60
  #
61
61
  def get(user_name, repo_name, milestone_id, params={})
62
- _update_user_repo_params(user_name, repo_name)
62
+ set :user => user_name, :repo => repo_name
63
63
  assert_presence_of user, repo, milestone_id
64
64
  normalize! params
65
65
 
@@ -83,7 +83,7 @@ module Github
83
83
  # :due_on => "Time"
84
84
  #
85
85
  def create(user_name, repo_name, params={})
86
- _update_user_repo_params(user_name, repo_name)
86
+ set :user => user_name, :repo => repo_name
87
87
  assert_presence_of user, repo
88
88
 
89
89
  normalize! params
@@ -110,7 +110,7 @@ module Github
110
110
  # :due_on => "Time"
111
111
  #
112
112
  def update(user_name, repo_name, milestone_id, params={})
113
- _update_user_repo_params(user_name, repo_name)
113
+ set :user => user_name, :repo => repo_name
114
114
  assert_presence_of user, repo, milestone_id
115
115
 
116
116
  normalize! params
@@ -127,7 +127,7 @@ module Github
127
127
  # github.issues.milestones.delete 'user-name', 'repo-name', 'milestone-id'
128
128
  #
129
129
  def delete(user_name, repo_name, milestone_id, params={})
130
- _update_user_repo_params(user_name, repo_name)
130
+ set :user => user_name, :repo => repo_name
131
131
  assert_presence_of user, repo, milestone_id
132
132
  normalize! params
133
133