github_api 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. data/features/gists/comments.feature +8 -8
  2. data/lib/github_api/gists/comments.rb +15 -15
  3. data/lib/github_api/repos.rb +3 -1
  4. data/lib/github_api/repos/comments.rb +6 -5
  5. data/lib/github_api/requestable.rb +67 -0
  6. data/lib/github_api/version.rb +1 -1
  7. data/spec/github/activity/activity_spec.rb +2 -0
  8. data/spec/github/activity/events/issue_spec.rb +8 -20
  9. data/spec/github/activity/events/network_spec.rb +8 -20
  10. data/spec/github/activity/events/org_spec.rb +8 -18
  11. data/spec/github/activity/events/performed_spec.rb +13 -31
  12. data/spec/github/activity/events/public_spec.rb +7 -18
  13. data/spec/github/activity/events/received_spec.rb +12 -31
  14. data/spec/github/activity/events/repository_spec.rb +8 -20
  15. data/spec/github/activity/events/user_org_spec.rb +8 -20
  16. data/spec/github/activity/notifications/list_spec.rb +4 -11
  17. data/spec/github/activity/starring/list_spec.rb +8 -21
  18. data/spec/github/activity/watching/list_spec.rb +4 -18
  19. data/spec/github/gists/comments_spec.rb +24 -23
  20. data/spec/github/git_data/blobs/create_spec.rb +62 -0
  21. data/spec/github/git_data/blobs/get_spec.rb +49 -0
  22. data/spec/github/git_data/blobs_spec.rb +0 -116
  23. data/spec/github/repos/branch_spec.rb +3 -9
  24. data/spec/github/repos/branches_spec.rb +5 -13
  25. data/spec/github/repos/collaborators/add_spec.rb +37 -0
  26. data/spec/github/repos/collaborators/get_spec.rb +51 -0
  27. data/spec/github/repos/collaborators/list_spec.rb +51 -0
  28. data/spec/github/repos/collaborators/remove_spec.rb +37 -0
  29. data/spec/github/repos/collaborators_spec.rb +1 -176
  30. data/spec/github/repos/comments/create_spec.rb +2 -33
  31. data/spec/github/repos/comments/delete_spec.rb +3 -9
  32. data/spec/github/repos/comments/get_spec.rb +3 -9
  33. data/spec/github/repos/comments/list_spec.rb +16 -40
  34. data/spec/github/repos/comments/update_spec.rb +5 -11
  35. data/spec/github/repos/commits/get_spec.rb +3 -9
  36. data/spec/github/repos/commits/list_spec.rb +9 -20
  37. data/spec/github/repos/contributors_spec.rb +5 -13
  38. data/spec/github/repos/delete_spec.rb +3 -8
  39. data/spec/github/repos/downloads/create_spec.rb +3 -9
  40. data/spec/github/repos/downloads/delete_spec.rb +3 -9
  41. data/spec/github/repos/downloads/get_spec.rb +5 -12
  42. data/spec/github/repos/downloads/list_spec.rb +8 -18
  43. data/spec/github/repos/edit_spec.rb +3 -9
  44. data/spec/github/repos/forks/create_spec.rb +3 -9
  45. data/spec/github/repos/forks/list_spec.rb +8 -21
  46. data/spec/github/repos/get_spec.rb +3 -9
  47. data/spec/github/repos/list_spec.rb +8 -7
  48. data/spec/github/repos_spec.rb +2 -0
  49. data/spec/shared/api_interface_behaviour.rb +15 -0
  50. data/spec/shared/array_of_resources_behaviour.rb +15 -0
  51. data/spec/shared/request_failure_behaviour.rb +16 -0
  52. data/spec/spec_helper.rb +1 -1
  53. metadata +43 -33
@@ -15,11 +15,11 @@ Feature: Accessing Gists Comments API
15
15
  And the response type should be JSON
16
16
  And the response should have 18 items
17
17
 
18
- Scenario: Gets a single gist's comment
19
- When I want to get resource with the following params:
20
- | comment_id |
21
- | 33469 |
22
- And I make request within a cassette named "gists/comments/first"
23
- Then the response status should be 200
24
- And the response type should be JSON
25
- And the response should not be empty
18
+ # Scenario: Gets a single gist's comment
19
+ # When I want to get resource with the following params:
20
+ # | gist_id | comment_id |
21
+ # | 999390 | 33663 |
22
+ # And I make request within a cassette named "gists/comments/first"
23
+ # Then the response status should be 200
24
+ # And the response type should be JSON
25
+ # And the response should not be empty
@@ -3,11 +3,11 @@
3
3
  module Github
4
4
  class Gists::Comments < API
5
5
 
6
- REQUIRED_GIST_COMMENT_INPUTS = %w[
6
+ REQUIRED_GIST_COMMENT_OPTIONS = %w[
7
7
  body
8
8
  ].freeze
9
9
 
10
- ALLOWED_GIST_COMMENT_INPUTS = %w[
10
+ VALID_GIST_COMMENT_OPTIONS = %w[
11
11
  body
12
12
  mime_type
13
13
  resource
@@ -34,14 +34,14 @@ module Github
34
34
  #
35
35
  # = Examples
36
36
  # github = Github.new
37
- # github.gists.comments.get 'comment-id'
37
+ # github.gists.comments.get 'gist-id', 'comment-id'
38
38
  #
39
- def get(comment_id, params={})
39
+ def get(gist_id, comment_id, params={})
40
40
  normalize! params
41
41
  assert_presence_of comment_id
42
42
  # _merge_mime_type(:gist_comment, params)
43
43
 
44
- get_request("/gists/comments/#{comment_id}", params)
44
+ get_request("/gists/#{gist_id}/comments/#{comment_id}", params)
45
45
  end
46
46
  alias :find :get
47
47
 
@@ -54,8 +54,8 @@ module Github
54
54
  def create(gist_id, params={})
55
55
  normalize! params
56
56
  # _merge_mime_type(:gist_comment, params)
57
- filter! ALLOWED_GIST_COMMENT_INPUTS, params
58
- assert_required_keys(REQUIRED_GIST_COMMENT_INPUTS, params)
57
+ filter! VALID_GIST_COMMENT_OPTIONS, params
58
+ assert_required_keys(REQUIRED_GIST_COMMENT_OPTIONS, params)
59
59
 
60
60
  post_request("/gists/#{gist_id}/comments", params)
61
61
  end
@@ -64,30 +64,30 @@ module Github
64
64
  #
65
65
  # = Examples
66
66
  # github = Github.new
67
- # github.gists.comments.edit 'comment-id'
67
+ # github.gists.comments.edit 'gist-id', 'comment-id'
68
68
  #
69
- def edit(comment_id, params={})
69
+ def edit(gist_id, comment_id, params={})
70
70
  normalize! params
71
71
  assert_presence_of comment_id
72
72
  # _merge_mime_type(:gist_comment, params)
73
- filter! ALLOWED_GIST_COMMENT_INPUTS, params
74
- assert_required_keys(REQUIRED_GIST_COMMENT_INPUTS, params)
73
+ filter! VALID_GIST_COMMENT_OPTIONS, params
74
+ assert_required_keys(REQUIRED_GIST_COMMENT_OPTIONS, params)
75
75
 
76
- patch_request("/gists/comments/#{comment_id}", params)
76
+ patch_request("/gists/#{gist_id}/comments/#{comment_id}", params)
77
77
  end
78
78
 
79
79
  # Delete a comment
80
80
  #
81
81
  # = Examples
82
82
  # github = Github.new
83
- # github.gists.comments.delete 'comment-id'
83
+ # github.gists.comments.delete 'gist-id', 'comment-id'
84
84
  #
85
- def delete(comment_id, params={})
85
+ def delete(gist_id, comment_id, params={})
86
86
  normalize! params
87
87
  assert_presence_of comment_id
88
88
  # _merge_mime_type(:gist_comment, params)
89
89
 
90
- delete_request("/gists/comments/#{comment_id}", params)
90
+ delete_request("/gists/#{gist_id}/comments/#{comment_id}", params)
91
91
  end
92
92
 
93
93
  end # Gists::Comments
@@ -35,6 +35,8 @@ module Github
35
35
  has_wiki
36
36
  has_downloads
37
37
  team_id
38
+ auto_init
39
+ gitignore_template
38
40
  ].freeze
39
41
 
40
42
  VALID_REPO_TYPES = %w[ all public private member ].freeze
@@ -193,7 +195,7 @@ module Github
193
195
  assert_presence_of user, repo
194
196
  normalize! params
195
197
 
196
- delete_request("/repos/#{user}/#{repo}")
198
+ delete_request("/repos/#{user}/#{repo}", params)
197
199
  end
198
200
  alias :remove :delete
199
201
 
@@ -3,9 +3,10 @@
3
3
  module Github
4
4
  class Repos::Comments < API
5
5
 
6
- REQUIRED_COMMENT_PARAMS = %w[
6
+ REQUIRED_COMMENT_OPTIONS = %w[ body ].freeze
7
+
8
+ VALID_COMMENT_OPTIONS = %w[
7
9
  body
8
- commit_id
9
10
  line
10
11
  path
11
12
  position
@@ -77,9 +78,9 @@ module Github
77
78
  assert_presence_of user, repo, sha
78
79
 
79
80
  normalize! params
80
- filter! REQUIRED_COMMENT_PARAMS, params
81
+ filter! VALID_COMMENT_OPTIONS, params
81
82
 
82
- assert_required_keys(REQUIRED_COMMENT_PARAMS, params)
83
+ assert_required_keys(REQUIRED_COMMENT_OPTIONS, params)
83
84
 
84
85
  post_request("/repos/#{user}/#{repo}/commits/#{sha}/comments", params)
85
86
  end
@@ -98,7 +99,7 @@ module Github
98
99
  set :user => user_name, :repo => repo_name
99
100
  assert_presence_of user, repo, comment_id
100
101
  normalize! params
101
- assert_required_keys(%w[ body ], params)
102
+ assert_required_keys(REQUIRED_COMMENT_OPTIONS, params)
102
103
 
103
104
  patch_request("/repos/#{user}/#{repo}/comments/#{comment_id}", params)
104
105
  end
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ # Defines HTTP verbs
5
+ module Request
6
+
7
+ METHODS = [:get, :post, :put, :delete, :patch]
8
+ METHODS_WITH_BODIES = [ :post, :put, :patch ]
9
+
10
+ def get_request(path, params={}, options={})
11
+ request(:get, path, params, options)
12
+ end
13
+
14
+ def patch_request(path, params={}, options={})
15
+ request(:patch, path, params, options)
16
+ end
17
+
18
+ def post_request(path, params={}, options={})
19
+ request(:post, path, params, options)
20
+ end
21
+
22
+ def put_request(path, params={}, options={})
23
+ request(:put, path, params, options)
24
+ end
25
+
26
+ def delete_request(path, params={}, options={})
27
+ request(:delete, path, params, options)
28
+ end
29
+
30
+ def request(method, path, params, options)
31
+ if !METHODS.include?(method)
32
+ raise ArgumentError, "unkown http method: #{method}"
33
+ end
34
+ # _extract_mime_type(params, options)
35
+
36
+ puts "EXECUTED: #{method} - #{path} with #{params} and #{options}" if ENV['DEBUG']
37
+
38
+ conn = connection(options)
39
+ path = (conn.path_prefix + path).gsub(/\/\//,'/') if conn.path_prefix != '/'
40
+
41
+ response = conn.send(method) do |request|
42
+ case method.to_sym
43
+ when *(METHODS - METHODS_WITH_BODIES)
44
+ request.body = params.delete('data') if params.has_key?('data')
45
+ request.url(path, params)
46
+ when *METHODS_WITH_BODIES
47
+ request.path = path
48
+ request.body = extract_data_from_params(params) unless params.empty?
49
+ end
50
+ end
51
+ response.body
52
+ end
53
+
54
+ private
55
+
56
+ def extract_data_from_params(params) # :nodoc:
57
+ return params['data'] if params.has_key?('data') and !params['data'].nil?
58
+ return params
59
+ end
60
+
61
+ def _extract_mime_type(params, options) # :nodoc:
62
+ options['resource'] = params['resource'] ? params.delete('resource') : ''
63
+ options['mime_type'] = params['resource'] ? params.delete('mime_type') : ''
64
+ end
65
+
66
+ end # Request
67
+ end # Github
@@ -4,7 +4,7 @@ module Github
4
4
  module VERSION
5
5
  MAJOR = 0
6
6
  MINOR = 8
7
- PATCH = 0
7
+ PATCH = 1
8
8
  BUILD = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.');
@@ -6,6 +6,8 @@ describe Github::Activity, 'integration' do
6
6
 
7
7
  after { reset_authentication_for subject }
8
8
 
9
+ it_should_behave_like 'api interface'
10
+
9
11
  its(:events) { should be_a Github::Activity::Events }
10
12
 
11
13
  its(:notifications) { should be_a Github::Activity::Notifications }
@@ -28,15 +28,8 @@ describe Github::Activity::Events, '#issue' do
28
28
  a_get(request_path).should have_been_made
29
29
  end
30
30
 
31
- it "should return array of resources" do
32
- events = subject.issue user, repo
33
- events.should be_an Array
34
- events.should have(1).items
35
- end
36
-
37
- it "should be a mash type" do
38
- events = subject.issue user, repo
39
- events.first.should be_a Hashie::Mash
31
+ it_should_behave_like 'an array of resources' do
32
+ let(:requestable) { subject.issue user, repo }
40
33
  end
41
34
 
42
35
  it "should get event information" do
@@ -45,19 +38,14 @@ describe Github::Activity::Events, '#issue' do
45
38
  end
46
39
 
47
40
  it "should yield to a block" do
48
- subject.should_receive(:issue).with(user, repo).and_yield('web')
49
- subject.issue(user, repo) { |param| 'web' }
41
+ yielded = []
42
+ result = subject.issue(user, repo) { |obj| yielded << obj }
43
+ yielded.should == result
50
44
  end
51
45
  end
52
46
 
53
- context "resource not found" do
54
- let(:body) { '' }
55
- let(:status) { [404, "Not Found"] }
56
-
57
- it "should return 404 with a message 'Not Found'" do
58
- expect {
59
- subject.issue user, repo
60
- }.to raise_error(Github::Error::NotFound)
61
- end
47
+ it_should_behave_like 'request failure' do
48
+ let(:requestable) { subject.issue user, repo }
62
49
  end
50
+
63
51
  end # issue
@@ -26,15 +26,8 @@ describe Github::Activity::Events, '#network' do
26
26
  a_get(request_path).should have_been_made
27
27
  end
28
28
 
29
- it "should return array of resources" do
30
- events = subject.network user, repo
31
- events.should be_an Array
32
- events.should have(1).items
33
- end
34
-
35
- it "should be a mash type" do
36
- events = subject.network user, repo
37
- events.first.should be_a Hashie::Mash
29
+ it_should_behave_like 'an array of resources' do
30
+ let(:requestable) { subject.network user, repo }
38
31
  end
39
32
 
40
33
  it "should get event information" do
@@ -43,19 +36,14 @@ describe Github::Activity::Events, '#network' do
43
36
  end
44
37
 
45
38
  it "should yield to a block" do
46
- subject.should_receive(:network).with(user, repo).and_yield('web')
47
- subject.network(user, repo) { |param| 'web' }
39
+ yielded = []
40
+ result = subject.network(user, repo) { |obj| yielded << obj }
41
+ yielded.should == result
48
42
  end
49
43
  end
50
44
 
51
- context "resource not found" do
52
- let(:body) { '' }
53
- let(:status) { [404, "Not Found"] }
54
-
55
- it "should return 404 with a message 'Not Found'" do
56
- expect {
57
- subject.network user, repo
58
- }.to raise_error(Github::Error::NotFound)
59
- end
45
+ it_should_behave_like 'request failure' do
46
+ let(:requestable) { subject.network user, repo }
60
47
  end
48
+
61
49
  end # network
@@ -27,15 +27,8 @@ describe Github::Activity::Events, '#org' do
27
27
  a_get(request_path).should have_been_made
28
28
  end
29
29
 
30
- it "should return array of resources" do
31
- events = subject.org org
32
- events.should be_an Array
33
- events.should have(1).items
34
- end
35
-
36
- it "should be a mash type" do
37
- events = subject.org org
38
- events.first.should be_a Hashie::Mash
30
+ it_should_behave_like 'an array of resources' do
31
+ let(:requestable) { subject.org org }
39
32
  end
40
33
 
41
34
  it "should get event information" do
@@ -44,17 +37,14 @@ describe Github::Activity::Events, '#org' do
44
37
  end
45
38
 
46
39
  it "should yield to a block" do
47
- subject.should_receive(:org).with(org).and_yield('web')
48
- subject.org(org) { |param| 'web' }
40
+ yielded = []
41
+ result = subject.org(org) { |obj| yielded << obj }
42
+ yielded.should == result
49
43
  end
50
44
  end
51
45
 
52
- context "resource not found" do
53
- let(:body) { '' }
54
- let(:status) { [404, "Not Found"] }
55
-
56
- it "should return 404 with a message 'Not Found'" do
57
- expect { subject.org org }.to raise_error(Github::Error::NotFound)
58
- end
46
+ it_should_behave_like 'request failure' do
47
+ let(:requestable) { subject.org org }
59
48
  end
49
+
60
50
  end # org
@@ -26,15 +26,8 @@ describe Github::Activity::Events, '#performed' do
26
26
  a_get(request_path).should have_been_made
27
27
  end
28
28
 
29
- it "should return array of resources" do
30
- events = subject.performed user
31
- events.should be_an Array
32
- events.should have(1).items
33
- end
34
-
35
- it "should be a mash type" do
36
- events = subject.performed user
37
- events.first.should be_a Hashie::Mash
29
+ it_should_behave_like 'an array of resources' do
30
+ let(:requestable) { subject.performed user }
38
31
  end
39
32
 
40
33
  it "should get event information" do
@@ -43,8 +36,9 @@ describe Github::Activity::Events, '#performed' do
43
36
  end
44
37
 
45
38
  it "should yield to a block" do
46
- subject.should_receive(:performed).with(user).and_yield('web')
47
- subject.performed(user) { |param| 'web' }
39
+ yielded = []
40
+ result = subject.performed(user) { |obj| yielded << obj }
41
+ yielded.should == result
48
42
  end
49
43
  end
50
44
 
@@ -56,15 +50,8 @@ describe Github::Activity::Events, '#performed' do
56
50
  a_get(request_path).should have_been_made
57
51
  end
58
52
 
59
- it "should return array of resources" do
60
- events = subject.performed user, :public => true
61
- events.should be_an Array
62
- events.should have(1).items
63
- end
64
-
65
- it "should be a mash type" do
66
- events = subject.performed user, :public => true
67
- events.first.should be_a Hashie::Mash
53
+ it_should_behave_like 'an array of resources' do
54
+ let(:requestable) { subject.performed user, :public => true }
68
55
  end
69
56
 
70
57
  it "should get event information" do
@@ -73,19 +60,14 @@ describe Github::Activity::Events, '#performed' do
73
60
  end
74
61
 
75
62
  it "should yield to a block" do
76
- subject.should_receive(:performed).with(user).and_yield('web')
77
- subject.performed(user) { |param| 'web' }
63
+ yielded = []
64
+ result = subject.performed(user, :public => true) { |obj| yielded << obj }
65
+ yielded.should == result
78
66
  end
79
67
  end
80
68
 
81
- context "resource not found" do
82
- let(:body) { '' }
83
- let(:status) { [404, "Not Found"] }
84
-
85
- it "should return 404 with a message 'Not Found'" do
86
- expect {
87
- subject.performed user
88
- }.to raise_error(Github::Error::NotFound)
89
- end
69
+ it_should_behave_like 'request failure' do
70
+ let(:requestable) { subject.performed user }
90
71
  end
72
+
91
73
  end # performed
@@ -21,15 +21,8 @@ describe Github::Activity::Events, '#public' do
21
21
  a_get(request_path).should have_been_made
22
22
  end
23
23
 
24
- it "should return array of resources" do
25
- events = subject.public
26
- events.should be_an Array
27
- events.should have(1).items
28
- end
29
-
30
- it "should be a mash type" do
31
- events = subject.public
32
- events.first.should be_a Hashie::Mash
24
+ it_should_behave_like 'an array of resources' do
25
+ let(:requestable) { subject.public }
33
26
  end
34
27
 
35
28
  it "should get event information" do
@@ -38,18 +31,14 @@ describe Github::Activity::Events, '#public' do
38
31
  end
39
32
 
40
33
  it "should yield to a block" do
41
- subject.should_receive(:public).and_yield('web')
42
- subject.public { |param| 'web' }
34
+ yielded = []
35
+ result = subject.public { |obj| yielded << obj }
36
+ yielded.should == result
43
37
  end
44
38
  end
45
39
 
46
- context "resource not found" do
47
- let(:body) { '' }
48
- let(:status) { [404, "Not Found"] }
49
-
50
- it "should return 404 with a message 'Not Found'" do
51
- expect { subject.public }.to raise_error(Github::Error::NotFound)
52
- end
40
+ it_should_behave_like 'request failure' do
41
+ let(:requestable) { subject.public }
53
42
  end
54
43
 
55
44
  end # public