github_api 0.9.0 → 0.9.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 (163) hide show
  1. data/README.md +50 -5
  2. data/features/cassettes/git_data/commits/get.yml +69 -0
  3. data/features/git_data/commmits.feature +14 -0
  4. data/lib/github_api.rb +1 -0
  5. data/lib/github_api/activity/events.rb +42 -33
  6. data/lib/github_api/activity/notifications.rb +22 -22
  7. data/lib/github_api/activity/starring.rb +16 -21
  8. data/lib/github_api/activity/watching.rb +16 -19
  9. data/lib/github_api/api.rb +51 -8
  10. data/lib/github_api/arguments.rb +155 -0
  11. data/lib/github_api/authorizations.rb +19 -20
  12. data/lib/github_api/configuration.rb +5 -0
  13. data/lib/github_api/emojis.rb +3 -3
  14. data/lib/github_api/error/validations.rb +2 -2
  15. data/lib/github_api/gists.rb +32 -42
  16. data/lib/github_api/gists/comments.rb +21 -23
  17. data/lib/github_api/git_data/blobs.rb +13 -16
  18. data/lib/github_api/git_data/commits.rb +12 -10
  19. data/lib/github_api/git_data/references.rb +24 -28
  20. data/lib/github_api/git_data/tags.rb +9 -11
  21. data/lib/github_api/git_data/trees.rb +10 -13
  22. data/lib/github_api/gitignore.rb +4 -6
  23. data/lib/github_api/issues.rb +24 -32
  24. data/lib/github_api/issues/assignees.rb +11 -8
  25. data/lib/github_api/issues/comments.rb +21 -26
  26. data/lib/github_api/issues/events.rb +7 -9
  27. data/lib/github_api/issues/labels.rb +39 -53
  28. data/lib/github_api/issues/milestones.rb +26 -33
  29. data/lib/github_api/markdown.rb +5 -6
  30. data/lib/github_api/meta.rb +3 -3
  31. data/lib/github_api/orgs.rb +10 -11
  32. data/lib/github_api/orgs/members.rb +18 -20
  33. data/lib/github_api/orgs/teams.rb +54 -58
  34. data/lib/github_api/pull_requests.rb +40 -54
  35. data/lib/github_api/pull_requests/comments.rb +19 -26
  36. data/lib/github_api/repos.rb +146 -101
  37. data/lib/github_api/repos/collaborators.rb +29 -30
  38. data/lib/github_api/repos/comments.rb +20 -25
  39. data/lib/github_api/repos/commits.rb +12 -14
  40. data/lib/github_api/repos/contents.rb +22 -14
  41. data/lib/github_api/repos/downloads.rb +19 -23
  42. data/lib/github_api/repos/forks.rb +6 -11
  43. data/lib/github_api/repos/hooks.rb +25 -34
  44. data/lib/github_api/repos/keys.rb +25 -27
  45. data/lib/github_api/repos/merging.rb +7 -6
  46. data/lib/github_api/repos/pub_sub_hubbub.rb +14 -18
  47. data/lib/github_api/repos/statuses.rb +13 -14
  48. data/lib/github_api/say.rb +1 -3
  49. data/lib/github_api/search.rb +12 -21
  50. data/lib/github_api/users.rb +10 -9
  51. data/lib/github_api/users/emails.rb +11 -9
  52. data/lib/github_api/users/followers.rb +25 -23
  53. data/lib/github_api/users/keys.rb +27 -29
  54. data/lib/github_api/version.rb +1 -1
  55. data/spec/github/activity/events/org_spec.rb +6 -6
  56. data/spec/github/activity/events/performed_spec.rb +1 -1
  57. data/spec/github/activity/events/received_spec.rb +1 -1
  58. data/spec/github/activity/events/user_org_spec.rb +4 -2
  59. data/spec/github/activity/notifications/create_spec.rb +1 -1
  60. data/spec/github/activity/notifications/delete_spec.rb +1 -1
  61. data/spec/github/activity/notifications/get_spec.rb +1 -1
  62. data/spec/github/activity/notifications/subscribed_spec.rb +1 -1
  63. data/spec/github/activity/starring/list_spec.rb +2 -0
  64. data/spec/github/activity/starring/starring_spec.rb +1 -1
  65. data/spec/github/activity/watching/list_spec.rb +2 -0
  66. data/spec/github/activity/watching/watching_spec.rb +1 -3
  67. data/spec/github/api/set_spec.rb +18 -4
  68. data/spec/github/api/with_spec.rb +28 -0
  69. data/spec/github/api_spec.rb +11 -33
  70. data/spec/github/arguments/parse_spec.rb +68 -0
  71. data/spec/github/authorizations/delete_spec.rb +1 -1
  72. data/spec/github/authorizations/get_spec.rb +1 -1
  73. data/spec/github/error/validations_spec.rb +3 -3
  74. data/spec/github/gists/comments/list_spec.rb +1 -1
  75. data/spec/github/gists/delete_spec.rb +1 -1
  76. data/spec/github/gists/fork_spec.rb +1 -1
  77. data/spec/github/gists/get_spec.rb +1 -1
  78. data/spec/github/gists/is_starred_spec.rb +2 -0
  79. data/spec/github/gists/star_spec.rb +1 -1
  80. data/spec/github/gists/unstar_spec.rb +1 -1
  81. data/spec/github/git_data/blobs/create_spec.rb +2 -0
  82. data/spec/github/git_data/blobs/get_spec.rb +1 -1
  83. data/spec/github/git_data/commits/create_spec.rb +2 -0
  84. data/spec/github/git_data/commits/get_spec.rb +3 -3
  85. data/spec/github/git_data/references/create_spec.rb +1 -1
  86. data/spec/github/git_data/references/delete_spec.rb +3 -1
  87. data/spec/github/git_data/tags/create_spec.rb +2 -0
  88. data/spec/github/gitignore/get_spec.rb +1 -1
  89. data/spec/github/issues/events/get_spec.rb +3 -1
  90. data/spec/github/issues/events/list_spec.rb +3 -1
  91. data/spec/github/issues/labels/add_spec.rb +6 -6
  92. data/spec/github/issues/labels/list_spec.rb +3 -1
  93. data/spec/github/issues/labels/replace_spec.rb +6 -7
  94. data/spec/github/issues/milestones/get_spec.rb +2 -0
  95. data/spec/github/normalizer_spec.rb +18 -6
  96. data/spec/github/orgs/members/conceal_spec.rb +6 -4
  97. data/spec/github/orgs/members/delete_spec.rb +2 -0
  98. data/spec/github/orgs/members/list_spec.rb +1 -1
  99. data/spec/github/orgs/members/member_spec.rb +3 -1
  100. data/spec/github/orgs/members/publicize_spec.rb +2 -0
  101. data/spec/github/orgs/teams/add_member_spec.rb +2 -0
  102. data/spec/github/orgs/teams/create_spec.rb +1 -1
  103. data/spec/github/orgs/teams/delete_spec.rb +1 -1
  104. data/spec/github/orgs/teams/edit_spec.rb +1 -1
  105. data/spec/github/orgs/teams/get_spec.rb +1 -1
  106. data/spec/github/orgs/teams/list_spec.rb +1 -1
  107. data/spec/github/orgs/teams/team_member_spec.rb +3 -1
  108. data/spec/github/parameter_filter_spec.rb +19 -58
  109. data/spec/github/pull_requests/comments/create_spec.rb +3 -1
  110. data/spec/github/pull_requests/comments/delete_spec.rb +1 -1
  111. data/spec/github/pull_requests/comments/edit_spec.rb +2 -0
  112. data/spec/github/pull_requests/comments/get_spec.rb +3 -1
  113. data/spec/github/pull_requests/comments/list_spec.rb +3 -1
  114. data/spec/github/pull_requests/commits_spec.rb +3 -3
  115. data/spec/github/pull_requests/create_spec.rb +4 -0
  116. data/spec/github/pull_requests/files_spec.rb +4 -0
  117. data/spec/github/pull_requests/get_spec.rb +3 -3
  118. data/spec/github/pull_requests/list_spec.rb +3 -3
  119. data/spec/github/pull_requests/merge_spec.rb +2 -0
  120. data/spec/github/pull_requests/merged_spec.rb +3 -1
  121. data/spec/github/pull_requests/update_spec.rb +4 -0
  122. data/spec/github/repos/collaborators/add_spec.rb +3 -1
  123. data/spec/github/repos/collaborators/get_spec.rb +1 -3
  124. data/spec/github/repos/collaborators/list_spec.rb +5 -1
  125. data/spec/github/repos/collaborators/remove_spec.rb +3 -1
  126. data/spec/github/repos/comments/create_spec.rb +4 -0
  127. data/spec/github/repos/comments/delete_spec.rb +2 -2
  128. data/spec/github/repos/comments/get_spec.rb +6 -2
  129. data/spec/github/repos/commits/compare_spec.rb +3 -3
  130. data/spec/github/repos/commits/get_spec.rb +3 -3
  131. data/spec/github/repos/commits/list_spec.rb +3 -3
  132. data/spec/github/repos/contents/archive_spec.rb +12 -0
  133. data/spec/github/repos/contents/get_spec.rb +5 -0
  134. data/spec/github/repos/contributors_spec.rb +7 -2
  135. data/spec/github/repos/downloads/create_spec.rb +4 -0
  136. data/spec/github/repos/downloads/delete_spec.rb +5 -1
  137. data/spec/github/repos/downloads/get_spec.rb +3 -1
  138. data/spec/github/repos/downloads/list_spec.rb +3 -1
  139. data/spec/github/repos/forks/create_spec.rb +2 -0
  140. data/spec/github/repos/forks/list_spec.rb +3 -1
  141. data/spec/github/repos/hooks/edit_spec.rb +1 -1
  142. data/spec/github/repos/keys/delete_spec.rb +1 -1
  143. data/spec/github/repos/keys/edit_spec.rb +2 -0
  144. data/spec/github/repos/keys/get_spec.rb +3 -1
  145. data/spec/github/repos/keys/list_spec.rb +4 -2
  146. data/spec/github/repos/list_spec.rb +6 -1
  147. data/spec/github/repos/pub_sub_hubbub/subscribe_service_spec.rb +27 -0
  148. data/spec/github/repos/pub_sub_hubbub/subscribe_spec.rb +51 -0
  149. data/spec/github/repos/pub_sub_hubbub/unsubscribe_service_spec.rb +21 -0
  150. data/spec/github/repos/pub_sub_hubbub/unsubscribe_spec.rb +58 -0
  151. data/spec/github/repos/statuses/create_spec.rb +2 -0
  152. data/spec/github/search_spec.rb +25 -10
  153. data/spec/github/users/followers/follow_spec.rb +1 -1
  154. data/spec/github/users/followers/is_following_spec.rb +1 -1
  155. data/spec/github/users/followers/unfollow_spec.rb +1 -1
  156. data/spec/github/users/keys/delete_spec.rb +1 -1
  157. data/spec/github/users/keys/get_spec.rb +1 -1
  158. data/spec/github/users/keys/update_spec.rb +1 -1
  159. data/spec/github/users/update_spec.rb +1 -1
  160. data/spec/integration/arguments_spec.rb +76 -0
  161. data/spec/{github → integration}/authorizations_spec.rb +0 -0
  162. metadata +44 -35
  163. data/spec/github/repos/pub_sub_hubbub_spec.rb +0 -78
@@ -12,10 +12,12 @@ module Github
12
12
  # github.repos.keys.list 'user-name', 'repo-name'
13
13
  # github.repos.keys.list 'user-name', 'repo-name' { |key| ... }
14
14
  #
15
- def list(user_name, repo_name, params={})
16
- set :user => user_name, :repo => repo_name
17
- assert_presence_of user, repo
18
- normalize! params
15
+ # keys = Github::Repos::Keys.new user: 'user-name', repo: 'repo-name'
16
+ # keys.list
17
+ #
18
+ def list(*args)
19
+ arguments(args, :required => [:user, :repo])
20
+ params = arguments.params
19
21
 
20
22
  response = get_request("/repos/#{user}/#{repo}/keys", params)
21
23
  return response unless block_given?
@@ -29,10 +31,9 @@ module Github
29
31
  # github = Github.new
30
32
  # github.repos.keys.get 'user-name', 'repo-name', 'key-id'
31
33
  #
32
- def get(user_name, repo_name, key_id, params={})
33
- set :user => user_name, :repo => repo_name
34
- assert_presence_of user, repo, key_id
35
- normalize! params
34
+ def get(*args)
35
+ arguments(args, :required => [:user, :repo, :key_id])
36
+ params = arguments.params
36
37
 
37
38
  get_request("/repos/#{user}/#{repo}/keys/#{key_id}", params)
38
39
  end
@@ -50,14 +51,13 @@ module Github
50
51
  # "title" => "octocat@octomac",
51
52
  # "key" => "ssh-rsa AAA..."
52
53
  #
53
- def create(user_name, repo_name, params={})
54
- set :user => user_name, :repo => repo_name
55
- assert_presence_of user, repo
56
- normalize! params
57
- filter! VALID_KEY_OPTIONS, params
58
- assert_required_keys(VALID_KEY_OPTIONS, params)
54
+ def create(*args)
55
+ arguments(args, :required => [:user, :repo]) do
56
+ sift VALID_KEY_OPTIONS
57
+ assert_required VALID_KEY_OPTIONS
58
+ end
59
59
 
60
- post_request("/repos/#{user}/#{repo}/keys", params)
60
+ post_request("/repos/#{user}/#{repo}/keys", arguments.params)
61
61
  end
62
62
 
63
63
  # Edit a key
@@ -72,12 +72,11 @@ module Github
72
72
  # "title" => "octocat@octomac",
73
73
  # "key" => "ssh-rsa AAA..."
74
74
  #
75
- def edit(user_name, repo_name, key_id, params={})
76
- set :user => user_name, :repo => repo_name
77
- assert_presence_of user, repo, key_id
78
-
79
- normalize! params
80
- filter! VALID_KEY_OPTIONS, params
75
+ def edit(*args)
76
+ arguments(args, :required => [:user, :repo, :key_id]) do
77
+ sift VALID_KEY_OPTIONS
78
+ end
79
+ params = arguments.params
81
80
 
82
81
  patch_request("/repos/#{user}/#{repo}/keys/#{key_id}", params)
83
82
  end
@@ -85,13 +84,12 @@ module Github
85
84
  # Delete key
86
85
  #
87
86
  # = Examples
88
- # @github = Github.new
89
- # @github.repos.keys.delete 'user-name', 'repo-name', 'key-id'
87
+ # github = Github.new
88
+ # github.repos.keys.delete 'user-name', 'repo-name', 'key-id'
90
89
  #
91
- def delete(user_name, repo_name, key_id, params={})
92
- set :user => user_name, :repo => repo_name
93
- assert_presence_of user, repo, key_id
94
- normalize! params
90
+ def delete(*args)
91
+ arguments(args, :required => [:user, :repo, :key_id])
92
+ params = arguments.params
95
93
 
96
94
  delete_request("/repos/#{user}/#{repo}/keys/#{key_id}", params)
97
95
  end
@@ -28,13 +28,14 @@ module Github
28
28
  # "head": "cool_feature",
29
29
  # "commit_message": "Shipped cool_feature!"
30
30
  #
31
- def merge(user_name, repo_name, params={})
32
- set :user => user_name, :repo => repo_name
33
- normalize! params
34
- filter! VALID_MERGE_PARAM_NAMES, params
35
- assert_required_keys REQUIRED_MERGE_PARAMS, params
31
+ def merge(*args)
32
+ arguments(args, :required => [:user, :repo]) do
33
+ sift VALID_MERGE_PARAM_NAMES
34
+ assert_required REQUIRED_MERGE_PARAMS
35
+ end
36
+ params = arguments.params
36
37
 
37
- post_request("/repos/#{user_name}/#{repo_name}/merges", params)
38
+ post_request("/repos/#{user}/#{repo}/merges", params)
38
39
  end
39
40
 
40
41
  end # Repos::Merging
@@ -22,9 +22,8 @@ module Github
22
22
  # :verify => 'sync',
23
23
  # :secret => '...'
24
24
  #
25
- def subscribe(topic, callback, params={})
26
- assert_presence_of topic, callback
27
- normalize! params
25
+ def subscribe(*args)
26
+ params = arguments(args, :required => [:topic, :callback]).params
28
27
  _merge_action!("subscribe", topic, callback, params)
29
28
 
30
29
  post_request("/hub", params, OPTIONS)
@@ -44,9 +43,8 @@ module Github
44
43
  # :verify => 'sync',
45
44
  # :secret => '...'
46
45
  #
47
- def unsubscribe(topic, callback, params={})
48
- assert_presence_of topic, callback
49
- normalize! params
46
+ def unsubscribe(*args)
47
+ params = arguments(args, :required => [:topic, :callback]).params
50
48
  _merge_action!("unsubscribe", topic, callback, params)
51
49
 
52
50
  post_request("/hub", params, OPTIONS)
@@ -67,12 +65,11 @@ module Github
67
65
  # :token => 'abc123',
68
66
  # :event => 'watch'
69
67
  #
70
- def subscribe_service(user_name, repo_name, service_name, params={})
71
- assert_presence_of user_name, repo_name, service_name
72
- normalize! params
73
- event = params.delete('event') || 'push'
74
- topic = "https://github.com/#{user_name}/#{repo_name}/events/#{event}"
75
- callback = "github://#{service_name}?#{params.serialize}"
68
+ def subscribe_service(*args)
69
+ params = arguments(args, :required => [:user, :repo, :service]).params
70
+ event = params.delete('event') || 'push'
71
+ topic = "#{site}/#{user}/#{repo}/events/#{event}"
72
+ callback = "github://#{service}?#{params.serialize}"
76
73
 
77
74
  subscribe(topic, callback)
78
75
  end
@@ -90,12 +87,11 @@ module Github
90
87
  # github = Github.new :oauth_token => '...'
91
88
  # github.repos.pubsubhubbub.unsubscribe_service 'user-name', 'repo-name', 'campfire'
92
89
  #
93
- def unsubscribe_service(user_name, repo_name, service_name, params={})
94
- assert_presence_of user_name, repo_name, service_name
95
- normalize! params
96
- event = params.delete('event') || 'push'
97
- topic = "https://github.com/#{user_name}/#{repo_name}/events/#{event}"
98
- callback = "github://#{service_name}"
90
+ def unsubscribe_service(*args)
91
+ params = arguments(args, :required => [:user, :repo, :service]).params
92
+ event = params.delete('event') || 'push'
93
+ topic = "#{site}/#{user}/#{repo}/events/#{event}"
94
+ callback = "github://#{service}"
99
95
 
100
96
  unsubscribe(topic, callback)
101
97
  end
@@ -1,10 +1,11 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Github
4
+
5
+ # The Status API allows external services to mark commits with a success,
6
+ # failure, error, or pending state, which is then reflected in pull requests
7
+ # involving those commits.
4
8
  class Repos::Statuses < API
5
- # The Status API allows external services to mark commits with a success,
6
- # failure, error, or pending state, which is then reflected in pull requests
7
- # involving those commits.
8
9
 
9
10
  VALID_STATUS_PARAM_NAMES = %w[
10
11
  state
@@ -21,10 +22,9 @@ module Github
21
22
  # github.repos.statuses.list 'user-name', 'repo-name', 'sha'
22
23
  # github.repos.statuses.list 'user-name', 'repo-name', 'sha' { |status| ... }
23
24
  #
24
- def list(user_name, repo_name, sha, params={})
25
- set :user => user_name, :repo => repo_name
26
- assert_presence_of user, repo
27
- normalize! params
25
+ def list(*args)
26
+ arguments(args, :required => [:user, :repo, :sha])
27
+ params = arguments.params
28
28
 
29
29
  response = get_request("/repos/#{user}/#{repo}/statuses/#{sha}", params)
30
30
  return response unless block_given?
@@ -49,13 +49,12 @@ module Github
49
49
  # "target_url" => "http://ci.example.com/johndoe/my-repo/builds/sha",
50
50
  # "description" => "Successful build #3 from origin/master"
51
51
  #
52
- def create(user_name, repo_name, sha, params={})
53
- set :user => user_name, :repo => repo_name
54
- assert_presence_of user, repo
55
-
56
- normalize! params
57
- filter! VALID_STATUS_PARAM_NAMES, params, :recursive => false
58
- assert_required_keys(REQUIRED_PARAMS, params)
52
+ def create(*args)
53
+ arguments(args, :required => [:user, :repo, :sha]) do
54
+ sift VALID_STATUS_PARAM_NAMES, :recursive => false
55
+ assert_required REQUIRED_PARAMS
56
+ end
57
+ params = arguments.params
59
58
 
60
59
  post_request("/repos/#{user}/#{repo}/statuses/#{sha}", params)
61
60
  end
@@ -12,9 +12,7 @@ module Github
12
12
  # github.octocat.say "My custom string..."
13
13
  #
14
14
  def say(*args)
15
- params = args.extract_options!
16
- normalize! params
17
-
15
+ params = arguments(*args).params
18
16
  params[:s] = args.shift unless args.empty?
19
17
 
20
18
  get_request('/octocat', params, :raw => true)
@@ -14,21 +14,14 @@ module Github
14
14
  #
15
15
  # = Examples
16
16
  # github = Github.new
17
+ # github.search.issues 'owner', 'repo-name', 'open','api'
17
18
  # github.search.issues owner: 'owner', repo: 'repo-name', state: 'open', keyword: 'api'
18
19
  #
19
20
  def issues(*args)
20
- params = args.extract_options!
21
- normalize! params
22
-
23
21
  required = ['owner', 'repo', 'state', 'keyword']
24
- assert_required_keys required, params
25
-
26
- options = required.inject({}) do |hash, key|
27
- hash[key] = params.delete(key)
28
- hash
29
- end
22
+ arguments(args, :required => required)
30
23
 
31
- get_request("/legacy/issues/search/#{options['owner']}/#{options['repo']}/#{options['state']}/#{escape(options['keyword'])}", params)
24
+ get_request("/legacy/issues/search/#{owner}/#{repo}/#{state}/#{escape(keyword)}", arguments.params)
32
25
  end
33
26
 
34
27
  # Search repositories
@@ -40,14 +33,13 @@ module Github
40
33
  #
41
34
  # = Examples
42
35
  # github = Github.new
36
+ # github.search.repos 'api'
43
37
  # github.search.repos keyword: 'api'
44
38
  #
45
39
  def repos(*args)
46
- params = args.extract_options!
47
- normalize! params
48
- assert_required_keys %w[ keyword ], params
40
+ arguments(args, :required => [:keyword])
49
41
 
50
- get_request("/legacy/repos/search/#{escape(params.delete('keyword'))}", params)
42
+ get_request("/legacy/repos/search/#{escape(keyword)}", arguments.params)
51
43
  end
52
44
  alias :repositories :repos
53
45
 
@@ -63,11 +55,9 @@ module Github
63
55
  # github.search.users keyword: 'wycats'
64
56
  #
65
57
  def users(*args)
66
- params = args.extract_options!
67
- normalize! params
68
- assert_required_keys %w[ keyword ], params
58
+ arguments(args, :required => [:keyword])
69
59
 
70
- get_request("/legacy/user/search/#{escape(params.delete('keyword'))}", params)
60
+ get_request("/legacy/user/search/#{escape(keyword)}", arguments.params)
71
61
  end
72
62
 
73
63
  # Search email
@@ -83,9 +73,10 @@ module Github
83
73
  # github.search.email email: 'wycats'
84
74
  #
85
75
  def email(*args)
86
- params = args.extract_options!
87
- normalize! params
88
- assert_required_keys %w[ email ], params
76
+ arguments(args) do
77
+ assert_required %w[ email ]
78
+ end
79
+ params = arguments.params
89
80
 
90
81
  get_request("/legacy/user/email/#{params.delete('email')}", params)
91
82
  end
@@ -47,10 +47,10 @@ module Github
47
47
  # users = Github::Users.new
48
48
  # users.list
49
49
  #
50
- def list(params={})
51
- normalize! params
50
+ def list(*args)
51
+ arguments(args)
52
52
 
53
- response = get_request("/users", params)
53
+ response = get_request("/users", arguments.params)
54
54
  return response unless block_given?
55
55
  response.each { |el| yield el }
56
56
  end
@@ -69,8 +69,8 @@ module Github
69
69
  # github.users.get
70
70
  #
71
71
  def get(*args)
72
- params = args.extract_options!
73
- normalize! params
72
+ params = arguments(args).params
73
+
74
74
  if user_name = params.delete('user')
75
75
  get_request("/users/#{user_name}", params)
76
76
  else
@@ -102,10 +102,11 @@ module Github
102
102
  # "bio" => "There once..."
103
103
  #
104
104
  def update(*args)
105
- params = args.extract_options!
106
- normalize! params
107
- filter! VALID_USER_PARAMS_NAMES, params
108
- patch_request("/user", params)
105
+ arguments(args) do
106
+ sift VALID_USER_PARAMS_NAMES
107
+ end
108
+
109
+ patch_request("/user", arguments.params)
109
110
  end
110
111
 
111
112
  end # Users
@@ -11,9 +11,9 @@ module Github
11
11
  # github.users.emails.list
12
12
  # github.users.emails.list { |email| ... }
13
13
  #
14
- def list(params={})
15
- normalize! params
16
- response = get_request("/user/emails", params)
14
+ def list(*args)
15
+ arguments(args)
16
+ response = get_request("/user/emails", arguments.params)
17
17
  return response unless block_given?
18
18
  response.each { |el| yield el }
19
19
  end
@@ -29,9 +29,10 @@ module Github
29
29
  # github.users.emails.add "octocat@github.com", "support@github.com"
30
30
  #
31
31
  def add(*args)
32
- params = args.extract_options!
33
- normalize! params
34
- params['data'] = args if args
32
+ arguments(args)
33
+ params = arguments.params
34
+ params['data'] = arguments.remaining unless arguments.remaining.empty?
35
+
35
36
  post_request("/user/emails", params)
36
37
  end
37
38
  alias :<< :add
@@ -46,9 +47,10 @@ module Github
46
47
  # github.users.emails.delete "octocat@github.com", "support@github.com"
47
48
  #
48
49
  def delete(*args)
49
- params = args.extract_options!
50
- normalize! params
51
- params['data'] = args if args
50
+ arguments(args)
51
+ params = arguments.params
52
+ params['data'] = arguments.remaining unless arguments.remaining.empty?
53
+
52
54
  delete_request("/user/emails", params)
53
55
  end
54
56
 
@@ -13,13 +13,14 @@ module Github
13
13
  # List the authenticated user's followers
14
14
  #
15
15
  # = Examples
16
- # github = Github.new :oauth_token => '...'
16
+ # github = Github.new oauth_token: '...'
17
17
  # github.users.followers
18
18
  # github.users.followers { |user| ... }
19
19
  #
20
- def list(user_name=nil, params={})
21
- normalize! params
22
- response = if user_name
20
+ def list(*args)
21
+ params = arguments(args).params
22
+
23
+ response = if user_name = arguments.remaining.first
23
24
  get_request("/users/#{user_name}/followers", params)
24
25
  else
25
26
  get_request("/user/followers", params)
@@ -40,12 +41,13 @@ module Github
40
41
  #
41
42
  # = Examples
42
43
  #
43
- # github = Github.new :oauth_token => '...'
44
+ # github = Github.new oauth_token: '...'
44
45
  # github.users.followers.following
45
46
  #
46
- def following(user_name=nil, params={})
47
- normalize! params
48
- response = if user_name
47
+ def following(*args)
48
+ params = arguments(args).params
49
+
50
+ response = if user_name = arguments.remaining.first
49
51
  get_request("/users/#{user_name}/following", params)
50
52
  else
51
53
  get_request("/user/following", params)
@@ -57,13 +59,13 @@ module Github
57
59
  # Check if you are following a user
58
60
  #
59
61
  # = Examples
60
- # github = Github.new :oauth_token => '...'
62
+ # github = Github.new oauth_token: '...'
61
63
  # github.users.followers.following? 'user-name'
64
+ # github.users.followers.following? user: 'user-name'
62
65
  #
63
- def following?(user_name, params={})
64
- assert_presence_of user_name
65
- normalize! params
66
- get_request("/user/following/#{user_name}", params)
66
+ def following?(*args)
67
+ arguments(args, :required => [:user])
68
+ get_request("/user/following/#{user}", arguments.params)
67
69
  true
68
70
  rescue Github::Error::NotFound
69
71
  false
@@ -72,25 +74,25 @@ module Github
72
74
  # Follow a user
73
75
  #
74
76
  # = Examples
75
- # github = Github.new :oauth_token => '...'
77
+ # github = Github.new oauth_token: '...'
76
78
  # github.users.followers.follow 'user-name'
79
+ # github.users.followers.follow user: 'user-name'
77
80
  #
78
- def follow(user_name, params={})
79
- assert_presence_of user_name
80
- normalize! params
81
- put_request("/user/following/#{user_name}", params)
81
+ def follow(*args)
82
+ arguments(args, :required => [:user])
83
+ put_request("/user/following/#{user}", arguments.params)
82
84
  end
83
85
 
84
86
  # Unfollow a user
85
87
  #
86
88
  # = Examples
87
- # github = Github.new :oauth_token => '...'
89
+ # github = Github.new oauth_token: '...'
88
90
  # github.users.followers.unfollow 'user-name'
91
+ # github.users.followers.unfollow user: 'user-name'
89
92
  #
90
- def unfollow(user_name, params={})
91
- assert_presence_of user_name
92
- normalize! params
93
- delete_request("/user/following/#{user_name}", params)
93
+ def unfollow(*args)
94
+ arguments(args, :required => [:user])
95
+ delete_request("/user/following/#{user}", arguments.params)
94
96
  end
95
97
 
96
98
  end # Users::Followers