github_api 0.4.11 → 0.5.0.rc1

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 (109) hide show
  1. data/README.md +76 -72
  2. data/features/cassettes/gists/starred.yml +48 -0
  3. data/features/cassettes/pagination/repos/commits/list.yml +193 -0
  4. data/features/cassettes/pagination/repos/commits/next.yml +183 -0
  5. data/features/cassettes/pagination/repos/diff/next.yml +45 -0
  6. data/features/cassettes/pagination/repos/list.yml +176 -0
  7. data/features/cassettes/pagination/repos/list/next.yml +222 -0
  8. data/features/cassettes/pagination/repos/per_page/each_page.yml +45 -0
  9. data/features/cassettes/repos/list.yml +92 -0
  10. data/features/error_codes.feature +1 -1
  11. data/features/gists.feature +12 -3
  12. data/features/gists/comments.feature +3 -3
  13. data/features/github_api.feature +13 -2
  14. data/features/pagination.feature +40 -39
  15. data/features/repos.feature +2 -2
  16. data/features/step_definitions/common_steps.rb +12 -0
  17. data/features/step_definitions/github_api_steps.rb +12 -1
  18. data/lib/github_api.rb +1 -1
  19. data/lib/github_api/api.rb +4 -2
  20. data/lib/github_api/api_factory.rb +11 -5
  21. data/lib/github_api/authorizations.rb +23 -32
  22. data/lib/github_api/client.rb +1 -0
  23. data/lib/github_api/events.rb +38 -38
  24. data/lib/github_api/filter.rb +1 -1
  25. data/lib/github_api/gists.rb +47 -42
  26. data/lib/github_api/gists/comments.rb +77 -84
  27. data/lib/github_api/git_data.rb +25 -6
  28. data/lib/github_api/git_data/blobs.rb +48 -45
  29. data/lib/github_api/git_data/commits.rb +76 -73
  30. data/lib/github_api/git_data/references.rb +137 -118
  31. data/lib/github_api/git_data/tags.rb +74 -70
  32. data/lib/github_api/git_data/trees.rb +88 -85
  33. data/lib/github_api/issues.rb +43 -31
  34. data/lib/github_api/issues/comments.rb +116 -119
  35. data/lib/github_api/issues/events.rb +20 -19
  36. data/lib/github_api/issues/labels.rb +200 -197
  37. data/lib/github_api/issues/milestones.rb +137 -134
  38. data/lib/github_api/orgs.rb +27 -23
  39. data/lib/github_api/orgs/members.rb +105 -108
  40. data/lib/github_api/orgs/teams.rb +236 -237
  41. data/lib/github_api/paged_request.rb +1 -1
  42. data/lib/github_api/pull_requests.rb +40 -42
  43. data/lib/github_api/pull_requests/comments.rb +140 -143
  44. data/lib/github_api/repos.rb +101 -67
  45. data/lib/github_api/repos/collaborators.rb +64 -68
  46. data/lib/github_api/repos/commits.rb +50 -39
  47. data/lib/github_api/repos/downloads.rb +107 -110
  48. data/lib/github_api/repos/forks.rb +38 -39
  49. data/lib/github_api/repos/hooks.rb +161 -167
  50. data/lib/github_api/repos/keys.rb +86 -86
  51. data/lib/github_api/repos/pub_sub_hubbub.rb +99 -87
  52. data/lib/github_api/repos/watching.rb +80 -82
  53. data/lib/github_api/request.rb +5 -9
  54. data/lib/github_api/users.rb +26 -16
  55. data/lib/github_api/users/emails.rb +47 -47
  56. data/lib/github_api/users/followers.rb +85 -86
  57. data/lib/github_api/users/keys.rb +73 -75
  58. data/lib/github_api/validations.rb +25 -0
  59. data/lib/github_api/validations/format.rb +23 -0
  60. data/lib/github_api/validations/presence.rb +25 -0
  61. data/lib/github_api/validations/required.rb +21 -0
  62. data/lib/github_api/validations/token.rb +41 -0
  63. data/lib/github_api/version.rb +3 -3
  64. data/spec/fixtures/repos/commit_comparison.json +112 -0
  65. data/spec/github/api_factory_spec.rb +17 -1
  66. data/spec/github/authorizations_spec.rb +36 -34
  67. data/spec/github/gists/comments_spec.rb +39 -45
  68. data/spec/github/gists_spec.rb +50 -53
  69. data/spec/github/git_data/blobs_spec.rb +27 -20
  70. data/spec/github/git_data/commits_spec.rb +20 -19
  71. data/spec/github/git_data/references_spec.rb +83 -46
  72. data/spec/github/git_data/tags_spec.rb +16 -15
  73. data/spec/github/git_data/trees_spec.rb +20 -19
  74. data/spec/github/git_data_spec.rb +10 -1
  75. data/spec/github/issues/comments_spec.rb +78 -68
  76. data/spec/github/issues/events_spec.rb +42 -34
  77. data/spec/github/issues/labels_spec.rb +89 -101
  78. data/spec/github/issues/milestones_spec.rb +76 -54
  79. data/spec/github/issues_spec.rb +53 -57
  80. data/spec/github/orgs/members_spec.rb +64 -49
  81. data/spec/github/orgs/teams_spec.rb +112 -101
  82. data/spec/github/orgs_spec.rb +41 -31
  83. data/spec/github/paged_request_spec.rb +6 -5
  84. data/spec/github/pull_requests/comments_spec.rb +39 -44
  85. data/spec/github/pull_requests_spec.rb +32 -48
  86. data/spec/github/repos/collaborators_spec.rb +40 -29
  87. data/spec/github/repos/commits_spec.rb +108 -64
  88. data/spec/github/repos/downloads_spec.rb +46 -45
  89. data/spec/github/repos/forks_spec.rb +23 -24
  90. data/spec/github/repos/hooks_spec.rb +69 -71
  91. data/spec/github/repos/keys_spec.rb +39 -34
  92. data/spec/github/repos/pub_sub_hubbub_spec.rb +4 -4
  93. data/spec/github/repos/watching_spec.rb +31 -33
  94. data/spec/github/repos_spec.rb +74 -83
  95. data/spec/github/request_spec.rb +31 -2
  96. data/spec/github/users/emails_spec.rb +19 -17
  97. data/spec/github/users/followers_spec.rb +30 -28
  98. data/spec/github/users/keys_spec.rb +37 -33
  99. data/spec/github/users_spec.rb +124 -125
  100. data/spec/github/validations/format_spec.rb +42 -0
  101. data/spec/github/validations/presence_spec.rb +18 -0
  102. data/spec/github/validations/required_spec.rb +28 -0
  103. data/spec/github/validations/token_spec.rb +19 -0
  104. data/spec/github/validations_spec.rb +23 -0
  105. metadata +33 -10
  106. data/features/cassettes/pagination/repos.yml +0 -177
  107. data/features/cassettes/pagination/repos/next.yml +0 -177
  108. data/lib/github_api/validation.rb +0 -53
  109. data/spec/github/validation_spec.rb +0 -62
@@ -1,55 +1,55 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Github
4
- class Users
5
- module Emails
4
+ class Users::Emails < API
6
5
 
7
- # List email addresses for the authenticated user
8
- #
9
- # = Examples
10
- # @github = Github.new :oauth_token => '...'
11
- # @github.users.emails
12
- # @github.users.emails { |email| ... }
13
- #
14
- def emails(params={})
15
- _normalize_params_keys(params)
16
- response = get("/user/emails", params)
17
- return response unless block_given?
18
- response.each { |el| yield el }
19
- end
6
+ # List email addresses for the authenticated user
7
+ #
8
+ # = Examples
9
+ # github = Github.new :oauth_token => '...'
10
+ # github.users.emails.list
11
+ # github.users.emails.list { |email| ... }
12
+ #
13
+ def list(params={})
14
+ _normalize_params_keys(params)
15
+ response = get_request("/user/emails", params)
16
+ return response unless block_given?
17
+ response.each { |el| yield el }
18
+ end
19
+ alias :all :list
20
20
 
21
- # Add email address(es) for the authenticated user
22
- #
23
- # = Inputs
24
- # You can include a single email address or an array of addresses
25
- #
26
- # = Examples
27
- # @github = Github.new :oauth_token => '...'
28
- # @github.users.add_email "octocat@github.com", "support@github.com"
29
- #
30
- def add_email(*args)
31
- params = _extract_parameters(args)
32
- _normalize_params_keys(params)
33
- params['data'] = [args].flatten if args
34
- post("/user/emails", params)
35
- end
21
+ # Add email address(es) for the authenticated user
22
+ #
23
+ # = Inputs
24
+ # You can include a single email address or an array of addresses
25
+ #
26
+ # = Examples
27
+ # github = Github.new :oauth_token => '...'
28
+ # github.users.emails.add "octocat@github.com", "support@github.com"
29
+ #
30
+ def add(*args)
31
+ params = _extract_parameters(args)
32
+ _normalize_params_keys(params)
33
+ params['data'] = [args].flatten if args
34
+ post_request("/user/emails", params)
35
+ end
36
+ alias :<< :add
36
37
 
37
- # Delete email address(es) for the authenticated user
38
- #
39
- # = Inputs
40
- # You can include a single email address or an array of addresses
41
- #
42
- # = Examples
43
- # @github = Github.new :oauth_token => '...'
44
- # @github.users.delete_email "octocat@github.com", "support@github.com"
45
- #
46
- def delete_email(*args)
47
- params = _extract_parameters(args)
48
- _normalize_params_keys(params)
49
- params['data'] = [args].flatten
50
- delete("/user/emails", params)
51
- end
38
+ # Delete email address(es) for the authenticated user
39
+ #
40
+ # = Inputs
41
+ # You can include a single email address or an array of addresses
42
+ #
43
+ # = Examples
44
+ # github = Github.new :oauth_token => '...'
45
+ # github.users.emails.delete "octocat@github.com", "support@github.com"
46
+ #
47
+ def delete(*args)
48
+ params = _extract_parameters(args)
49
+ _normalize_params_keys(params)
50
+ params['data'] = [args].flatten
51
+ delete_request("/user/emails", params)
52
+ end
52
53
 
53
- end # Emails
54
- end # Users
54
+ end # Users::Emails
55
55
  end # Github
@@ -1,98 +1,97 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Github
4
- class Users
5
- module Followers
4
+ class Users::Followers < API
6
5
 
7
- # List a user's followers
8
- #
9
- # = Examples
10
- # @github = Github.new
11
- # @github.users.followers 'user-name'
12
- # @github.users.followers 'user-name' { |user| ... }
13
- #
14
- # List the authenticated user's followers
15
- #
16
- # = Examples
17
- # @github = Github.new :oauth_token => '...'
18
- # @github.users.followers
19
- # @github.users.followers { |user| ... }
20
- #
21
- def followers(user_name=nil, params={})
22
- _normalize_params_keys(params)
23
- response = if user_name
24
- get("/users/#{user_name}/followers", params)
25
- else
26
- get("/user/followers", params)
27
- end
28
- return response unless block_given?
29
- response.each { |el| yield el }
6
+ # List a user's followers
7
+ #
8
+ # = Examples
9
+ # github = Github.new
10
+ # github.users.followers.list 'user-name'
11
+ # github.users.followers.list 'user-name' { |user| ... }
12
+ #
13
+ # List the authenticated user's followers
14
+ #
15
+ # = Examples
16
+ # github = Github.new :oauth_token => '...'
17
+ # github.users.followers
18
+ # github.users.followers { |user| ... }
19
+ #
20
+ def list(user_name=nil, params={})
21
+ _normalize_params_keys(params)
22
+ response = if user_name
23
+ get_request("/users/#{user_name}/followers", params)
24
+ else
25
+ get_request("/user/followers", params)
30
26
  end
27
+ return response unless block_given?
28
+ response.each { |el| yield el }
29
+ end
30
+ alias :all :list
31
31
 
32
- # List who a user is following
33
- #
34
- # = Examples
35
- # @github = Github.new
36
- # @github.users.following 'user-name'
37
- # @github.users.following 'user-name' { |user| ... }
38
- #
39
- # List who the authenicated user is following
40
- #
41
- # = Examples
42
- #
43
- # @github = Github.new :oauth_token => '...'
44
- # @github.users.following
45
- #
46
- def following(user_name=nil, params={})
47
- _normalize_params_keys(params)
48
- response = if user_name
49
- get("/users/#{user_name}/following", params)
50
- else
51
- get("/user/following", params)
52
- end
53
- return response unless block_given?
54
- response.each { |el| yield el }
32
+ # List who a user is following
33
+ #
34
+ # = Examples
35
+ # github = Github.new
36
+ # github.users.followers.following 'user-name'
37
+ # github.users.followers.following 'user-name' { |user| ... }
38
+ #
39
+ # List who the authenicated user is following
40
+ #
41
+ # = Examples
42
+ #
43
+ # github = Github.new :oauth_token => '...'
44
+ # github.users.followers.following
45
+ #
46
+ def following(user_name=nil, params={})
47
+ _normalize_params_keys(params)
48
+ response = if user_name
49
+ get_request("/users/#{user_name}/following", params)
50
+ else
51
+ get_request("/user/following", params)
55
52
  end
53
+ return response unless block_given?
54
+ response.each { |el| yield el }
55
+ end
56
56
 
57
- # Check if you are following a user
58
- #
59
- # = Examples
60
- # @github = Github.new :oauth_token => '...'
61
- # @github.users.following? 'user-name'
62
- #
63
- def following?(user_name, params={})
64
- _validate_presence_of user_name
65
- _normalize_params_keys(params)
66
- get("/user/following/#{user_name}", params)
67
- true
68
- rescue Github::Error::NotFound
69
- false
70
- end
57
+ # Check if you are following a user
58
+ #
59
+ # = Examples
60
+ # github = Github.new :oauth_token => '...'
61
+ # github.users.followers.following? 'user-name'
62
+ #
63
+ def following?(user_name, params={})
64
+ _validate_presence_of user_name
65
+ _normalize_params_keys(params)
66
+ get_request("/user/following/#{user_name}", params)
67
+ true
68
+ rescue Github::Error::NotFound
69
+ false
70
+ end
71
71
 
72
- # Follow a user
73
- #
74
- # = Examples
75
- # @github = Github.new :oauth_token => '...'
76
- # @github.users.follow 'user-name'
77
- #
78
- def follow(user_name, params={})
79
- _validate_presence_of user_name
80
- _normalize_params_keys(params)
81
- put("/user/following/#{user_name}", params)
82
- end
72
+ # Follow a user
73
+ #
74
+ # = Examples
75
+ # github = Github.new :oauth_token => '...'
76
+ # github.users.followers.follow 'user-name'
77
+ #
78
+ def follow(user_name, params={})
79
+ _validate_presence_of user_name
80
+ _normalize_params_keys(params)
81
+ put_request("/user/following/#{user_name}", params)
82
+ end
83
83
 
84
- # Unfollow a user
85
- #
86
- # = Examples
87
- # @github = Github.new :oauth_token => '...'
88
- # @github.users.unfollow 'user-name'
89
- #
90
- def unfollow(user_name, params={})
91
- _validate_presence_of user_name
92
- _normalize_params_keys(params)
93
- delete("/user/following/#{user_name}", params)
94
- end
84
+ # Unfollow a user
85
+ #
86
+ # = Examples
87
+ # github = Github.new :oauth_token => '...'
88
+ # github.users.followers.unfollow 'user-name'
89
+ #
90
+ def unfollow(user_name, params={})
91
+ _validate_presence_of user_name
92
+ _normalize_params_keys(params)
93
+ delete_request("/user/following/#{user_name}", params)
94
+ end
95
95
 
96
- end # Followers
97
- end # Users
96
+ end # Users::Followers
98
97
  end # Github
@@ -1,86 +1,84 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Github
4
- class Users
5
- module Keys
4
+ class Users::Keys < API
6
5
 
7
- VALID_KEY_PARAM_NAMES = %w[ title key ].freeze
6
+ VALID_KEY_PARAM_NAMES = %w[ title key ].freeze
8
7
 
9
- # List public keys for the authenticated user
10
- #
11
- # = Examples
12
- # @github = Github.new :oauth_token => '...'
13
- # @github.users.public_keys
14
- # @github.users.public_keys { |key| ... }
15
- #
16
- def keys(params={})
17
- _normalize_params_keys(params)
18
- response = get("/user/keys", params)
19
- return response unless block_given?
20
- response.each { |el| yield el }
21
- end
22
- alias :public_keys :keys
8
+ # List public keys for the authenticated user
9
+ #
10
+ # = Examples
11
+ # github = Github.new :oauth_token => '...'
12
+ # github.users.followers.list
13
+ # github.users.followers.list { |key| ... }
14
+ #
15
+ def list(params={})
16
+ _normalize_params_keys(params)
17
+ response = get_request("/user/keys", params)
18
+ return response unless block_given?
19
+ response.each { |el| yield el }
20
+ end
21
+ alias :all :list
23
22
 
24
- # Get a single pulic key for the authenticated user
25
- #
26
- # = Examples
27
- # @github = Github.new :oauth_token => '...'
28
- # @github.users.public_key 'key-id'
29
- #
30
- def key(key_id, params={})
31
- _validate_presence_of key_id
32
- _normalize_params_keys(params)
33
- get("/user/keys/#{key_id}", params)
34
- end
35
- alias :public_key :key
23
+ # Get a single pulic key for the authenticated user
24
+ #
25
+ # = Examples
26
+ # github = Github.new :oauth_token => '...'
27
+ # github.users.followers.get 'key-id'
28
+ #
29
+ def get(key_id, params={})
30
+ _validate_presence_of key_id
31
+ _normalize_params_keys(params)
32
+ get_request("/user/keys/#{key_id}", params)
33
+ end
34
+ alias :find :get
36
35
 
37
- # Create a public key for the authenticated user
38
- #
39
- # = Inputs
40
- # * <tt>:title</tt> - Required string
41
- # * <tt>:key</tt> - Required string. sha key
42
- #
43
- # = Examples
44
- # @github = Github.new :oauth_token => '...'
45
- # @github.users.create_key "title" => "octocat@octomac",
46
- # "key" => "ssh-rsa AAA..."
47
- #
48
- def create_key(params={})
49
- _normalize_params_keys(params)
50
- _filter_params_keys(VALID_KEY_PARAM_NAMES, params)
51
- post("/user/keys", params)
52
- end
36
+ # Create a public key for the authenticated user
37
+ #
38
+ # = Inputs
39
+ # * <tt>:title</tt> - Required string
40
+ # * <tt>:key</tt> - Required string. sha key
41
+ #
42
+ # = Examples
43
+ # github = Github.new :oauth_token => '...'
44
+ # github.users.followers.create "title" => "octocat@octomac",
45
+ # "key" => "ssh-rsa AAA..."
46
+ #
47
+ def create(params={})
48
+ _normalize_params_keys(params)
49
+ _filter_params_keys(VALID_KEY_PARAM_NAMES, params)
50
+ post_request("/user/keys", params)
51
+ end
53
52
 
54
- # Update a public key for the authenticated user
55
- #
56
- # = Inputs
57
- # * <tt>:title</tt> - Required string
58
- # * <tt>:key</tt> - Required string. sha key
59
- #
60
- # = Examples
61
- # @github = Github.new :oauth_token => '...'
62
- # @github.users.update_key 'key-id', "title" => "octocat@octomac",
63
- # "key" => "ssh-rsa AAA..."
64
- #
65
- def update_key(key_id, params={})
66
- _validate_presence_of key_id
67
- _normalize_params_keys(params)
68
- _filter_params_keys(VALID_KEY_PARAM_NAMES, params)
69
- patch("/user/keys/#{key_id}", params)
70
- end
53
+ # Update a public key for the authenticated user
54
+ #
55
+ # = Inputs
56
+ # * <tt>:title</tt> - Required string
57
+ # * <tt>:key</tt> - Required string. sha key
58
+ #
59
+ # = Examples
60
+ # github = Github.new :oauth_token => '...'
61
+ # github.users.followers.update 'key-id', "title" => "octocat@octomac",
62
+ # "key" => "ssh-rsa AAA..."
63
+ #
64
+ def update(key_id, params={})
65
+ _validate_presence_of key_id
66
+ _normalize_params_keys(params)
67
+ _filter_params_keys(VALID_KEY_PARAM_NAMES, params)
68
+ patch_request("/user/keys/#{key_id}", params)
69
+ end
71
70
 
72
- # Delete a public key for the authenticated user
73
- #
74
- # = Examples
75
- # @github = Github.new :oauth_token => '...'
76
- # @github.users.delete_key 'key-id'
77
- #
78
- def delete_key(key_id, params={})
79
- _validate_presence_of key_id
80
- _normalize_params_keys(params)
81
- delete("/user/keys/#{key_id}", params)
82
- end
71
+ # Delete a public key for the authenticated user
72
+ #
73
+ # = Examples
74
+ # github = Github.new :oauth_token => '...'
75
+ # github.users.followers.delete 'key-id'
76
+ #
77
+ def delete(key_id, params={})
78
+ _validate_presence_of key_id
79
+ _normalize_params_keys(params)
80
+ delete_request("/user/keys/#{key_id}", params)
81
+ end
83
82
 
84
- end # Keys
85
- end # Users
83
+ end # Users::Keys
86
84
  end # Github
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ module Validations
5
+ extend AutoloadHelper
6
+
7
+ autoload_all 'github_api/validations',
8
+ :Presence => 'presence',
9
+ :Token => 'token',
10
+ :Format => 'format',
11
+ :Required => 'required'
12
+
13
+ include Presence
14
+ include Format
15
+ include Token
16
+ include Required
17
+
18
+ VALID_API_KEYS = [
19
+ 'page',
20
+ 'per_page',
21
+ 'jsonp_callback'
22
+ ]
23
+
24
+ end # Validation
25
+ end # Github