github_api 0.12.4 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cff15a176a3ab3a5fc89519f2fadd76cd7c3a334
4
- data.tar.gz: d7e862b6cb3b09203d71a95ab43ae062183eb3fe
3
+ metadata.gz: a71c5d538e4a0188b7991e64d288552324618f74
4
+ data.tar.gz: 912f75917c8be1cbce0eec32496a6f15eca9c6c1
5
5
  SHA512:
6
- metadata.gz: f39bd5c587a1e6db6c3f072f53ddbb682c7b34373217a9d72f050fa424bbb32805a8d4110daf375b10edeeda596feae8644aa86c15317844ad17369f5030f75d
7
- data.tar.gz: 8e678463209d56ab1e5076a3bc54068624a96d9b931cb0fef40b8f04c01ad87e3e24c44783428de5350aa8475da9a9377b9a033aff56a1404638dd3c9929e218
6
+ metadata.gz: ddda23aac44bc2a628e0d100458f583615324c4fc7cab05da43ec886a9e087581a09faedbbcfef7c2db75fe2d8c4ea1dde3c1eadd2c5f2971bf2406d4829bf1e
7
+ data.tar.gz: e5f063e110e1f3b94b2e9d7fba6dae3cf6209c692b315cd2e33d992520d1d2dff70d35fbc4a388eab652d246ce17735b024366e4d873961bb3cd0ba99d028fb6
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
- [![Application icon](https://github.com/peter-murach/github/raw/master/icons/github_api.png)][icon]
2
- [icon]: https://github.com/peter-murach/github/raw/master/icons/github_api.png
3
- # github_api
1
+ <div align="center">
2
+ <a href="http://peter-murach.github.io/github/"><img width="136" src="https://github.com/peter-murach/github/raw/master/icons/github_api.png" alt="github api logo" /></a>
3
+ </div>
4
+ # GithubAPI
4
5
  [![Gem Version](https://badge.fury.io/rb/github_api.svg)][gem]
5
6
  [![Build Status](https://secure.travis-ci.org/peter-murach/github.svg?branch=master)][travis]
6
7
  [![Code Climate](https://codeclimate.com/github/peter-murach/github/badges/gpa.svg)][codeclimate]
@@ -138,7 +139,7 @@ Github::Client::Repos::Contents.actions
138
139
  The code base is modular. This means that you can work specifically with a given part of GitHub API. If you want to only work with activity starring API do the following:
139
140
 
140
141
  ```ruby
141
- starring = Github::Client::Activity::Starring.new
142
+ starring = Github::Client::Activity::Starring.new oauth_token: token
142
143
  starring.star 'peter-murach', 'github'
143
144
  ```
144
145
 
@@ -404,13 +405,13 @@ Though this method is convenient you should strongly consider using `OAuth` for
404
405
 
405
406
  ### 3.2 Authorizations API
406
407
 
407
- #### 3.2.1 For an User
408
+ #### 3.2.1 For a User
408
409
 
409
- To create an access token through the GitHub Authrizations API, you are required to pass your basic credentials and scopes you wish to have for the authentication token.
410
+ To create an access token through the GitHub Authorizations API, you are required to pass your basic credentials and scopes you wish to have for the authentication token.
410
411
 
411
412
  ```ruby
412
413
  github = Github.new basic_auth: 'login:password'
413
- github.oauth.create scopes: ['repo']
414
+ github.oauth.create scopes: ['repo'], note: 'admin script'
414
415
  ```
415
416
 
416
417
  You can add more than one scope from the `user`, `public_repo`, `repo`, `gist` or leave the scopes parameter out, in which case, the default read-only access will be assumed (includes public user profile info, public repo info, and gists).
@@ -648,7 +649,7 @@ Then update the file just like you do with creating:
648
649
  contents.update 'username', 'repo_name', 'full_path_to/file.ext',
649
650
  path: 'full_path_to/file.ext'
650
651
  message: 'Your commit message',
651
- content: 'The contens to be updated',
652
+ content: 'The contents to be updated',
652
653
  sha: file.sha
653
654
  ```
654
655
 
@@ -118,8 +118,8 @@ module Github
118
118
  # Check if required keys are present inside parameters hash.
119
119
  #
120
120
  # @api public
121
- def assert_required(required)
122
- assert_required_keys required, params
121
+ def assert_required(*required)
122
+ assert_required_keys(required, params)
123
123
  self
124
124
  end
125
125
 
@@ -6,16 +6,6 @@ module Github
6
6
 
7
7
  require_all 'github_api/client/authorizations', 'app'
8
8
 
9
- VALID_AUTH_PARAM_NAMES = %w[
10
- scopes
11
- add_scopes
12
- remove_scopes
13
- note
14
- note_url
15
- client_id
16
- client_secret
17
- ].freeze
18
-
19
9
  # Access to Authorizations::App API
20
10
  namespace :app
21
11
 
@@ -24,9 +14,9 @@ module Github
24
14
  # @see https://developer.github.com/v3/oauth_authorizations/#list-your-authorizations
25
15
  #
26
16
  # @example
27
- # github = Github.new basic_auth: 'login:password'
28
- # github.oauth.list
29
- # github.oauth.list { |auth| ... }
17
+ # github = Github.new basic_auth: 'login:password'
18
+ # github.oauth.list
19
+ # github.oauth.list { |auth| ... }
30
20
  #
31
21
  # @api public
32
22
  def list(*args)
@@ -37,7 +27,7 @@ module Github
37
27
  return response unless block_given?
38
28
  response.each { |el| yield el }
39
29
  end
40
- alias :all :list
30
+ alias_method :all, :list
41
31
 
42
32
  # Get a single authorization
43
33
  #
@@ -56,32 +46,36 @@ module Github
56
46
 
57
47
  get_request("/authorizations/#{arguments.id}", arguments.params)
58
48
  end
59
- alias :find :get
49
+ alias_method :find, :get
60
50
 
61
51
  # Create a new authorization
62
52
  #
53
+ # @see https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization
54
+ #
63
55
  # @param [Hash] params
64
56
  # @option params [Array[String]] :scopes
65
57
  # A list of scopes that this authorization is in.
66
58
  # @option params [String] :note
67
- # A note to remind you what the OAuth token is for.
59
+ # Required. A note to remind you what the OAuth token is for.
68
60
  # @option params [String] :note_url
69
61
  # A URL to remind you what the OAuth token is for.
70
62
  # @option params [String] :client_id
71
63
  # The 20 character OAuth app client key for which to create the token.
72
64
  # @option params [String] :client_secret
73
65
  # The 40 character OAuth app client secret for which to create the token.
66
+ # @option params [String] :fingerprint
67
+ # A unique string to distinguish an authorization from others
68
+ # created for the same client ID and user.
74
69
  #
75
70
  # @example
76
- # github = Github.new basic_auth: 'login:password'
77
- # github.oauth.create
78
- # "scopes" => ["public_repo"]
71
+ # github = Github.new basic_auth: 'login:password'
72
+ # github.oauth.create scopes: ["public_repo"], note: 'amdmin script'
79
73
  #
80
74
  # @api public
81
75
  def create(*args)
82
76
  raise_authentication_error unless authenticated?
83
77
  arguments(args) do
84
- permit VALID_AUTH_PARAM_NAMES
78
+ assert_required :note, :scopes
85
79
  end
86
80
 
87
81
  post_request('/authorizations', arguments.params)
@@ -89,6 +83,8 @@ module Github
89
83
 
90
84
  # Update an existing authorization
91
85
  #
86
+ # @see https://developer.github.com/v3/oauth_authorizations/#update-an-existing-authorization
87
+ #
92
88
  # @param [Hash] inputs
93
89
  # @option inputs [Array] :scopes
94
90
  # Optional array - A list of scopes that this authorization is in.
@@ -100,28 +96,30 @@ module Github
100
96
  # Optional string - A note to remind you what the OAuth token is for.
101
97
  # @optoin inputs [String] :note_url
102
98
  # Optional string - A URL to remind you what the OAuth token is for.
99
+ # @option params [String] :fingerprint
100
+ # A unique string to distinguish an authorization from others
101
+ # created for the same client ID and user.
103
102
  #
104
103
  # @example
105
- # github = Github.new basic_auth: 'login:password'
106
- # github.oauth.update "authorization-id", add_scopes: ["repo"]
104
+ # github = Github.new basic_auth: 'login:password'
105
+ # github.oauth.update "authorization-id", add_scopes: ["repo"]
107
106
  #
108
107
  # @api public
109
108
  def update(*args)
110
109
  raise_authentication_error unless authenticated?
111
- arguments(args, required: [:id]) do
112
- permit VALID_AUTH_PARAM_NAMES
113
- end
110
+ arguments(args, required: [:id])
114
111
 
115
112
  patch_request("/authorizations/#{arguments.id}", arguments.params)
116
113
  end
117
- alias :edit :update
114
+ alias_method :edit, :update
118
115
 
119
116
  # Delete an authorization
120
117
  #
121
118
  # @see https://developer.github.com/v3/oauth_authorizations/#delete-an-authorization
122
119
  #
123
120
  # @example
124
- # github.oauth.delete 'authorization-id'
121
+ # github = Github.new
122
+ # github.oauth.delete 'authorization-id'
125
123
  #
126
124
  # @api public
127
125
  def delete(*args)
@@ -130,14 +128,13 @@ module Github
130
128
 
131
129
  delete_request("/authorizations/#{arguments.id}", arguments.params)
132
130
  end
133
- alias :remove :delete
131
+ alias_method :remove, :delete
134
132
 
135
133
  protected
136
134
 
137
135
  def raise_authentication_error
138
- raise ArgumentError, 'You can only access your own tokens' +
139
- ' via Basic Authentication'
136
+ raise ArgumentError, 'You can only access your own tokens' \
137
+ ' via Basic Authentication'
140
138
  end
141
-
142
139
  end # Client::Authorizations
143
140
  end # Github
@@ -24,9 +24,7 @@ module Github
24
24
  # @api public
25
25
  def create(*args)
26
26
  raise_authentication_error unless authenticated?
27
- arguments(args, required: [:client_id]) do
28
- permit VALID_AUTH_PARAM_NAMES
29
- end
27
+ arguments(args, required: [:client_id])
30
28
 
31
29
  if arguments.client_id
32
30
  put_request("/authorizations/clients/#{arguments.client_id}", arguments.params)
@@ -1,28 +1,41 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Github
4
+ # Organizations API
4
5
  class Client::Orgs < API
5
6
 
6
7
  require_all 'github_api/client/orgs',
7
- 'members',
8
- 'teams'
9
-
10
- VALID_ORG_PARAM_NAMES = %w[
11
- billing_email
12
- company
13
- email
14
- location
15
- name
16
- ].freeze
8
+ 'members',
9
+ 'memberships',
10
+ 'teams'
17
11
 
18
12
  # Access to Client::Orgs::Members API
19
13
  namespace :members
20
14
 
15
+ # Access to Client::Orgs::Memberships API
16
+ namespace :memberships
17
+
21
18
  # Access to Client::Orgs::Teams API
22
19
  namespace :teams
23
20
 
21
+ # List all organizations
22
+ #
23
+ # Lists all organizations, in the order that they were created on GitHub.
24
+ #
25
+ # @see https://developer.github.com/v3/orgs/#list-all-organizations
26
+ #
27
+ # @param [Hash] params
28
+ # @option params [String] :since
29
+ # The integer ID of the last Organization that you've seen.
30
+ #
31
+ # @example
32
+ # github = Github.new
33
+ # github.orgs.list :every
34
+ #
24
35
  # List all public organizations for a user.
25
36
  #
37
+ # @see https://developer.github.com/v3/orgs/#list-user-organizations
38
+ #
26
39
  # @example
27
40
  # github = Github.new
28
41
  # github.orgs.list user: 'user-name'
@@ -37,19 +50,23 @@ module Github
37
50
  def list(*args)
38
51
  params = arguments(args).params
39
52
 
40
- response = if (user_name = params.delete("user"))
41
- get_request("/users/#{user_name}/orgs", params)
53
+ if (user_name = params.delete('user'))
54
+ response = get_request("/users/#{user_name}/orgs", params)
55
+ elsif args.map(&:to_s).include?('every')
56
+ response = get_request('/organizations', params)
42
57
  else
43
58
  # For the authenticated user
44
- get_request("/user/orgs", params)
59
+ response = get_request('/user/orgs', params)
45
60
  end
46
61
  return response unless block_given?
47
62
  response.each { |el| yield el }
48
63
  end
49
- alias :all :list
64
+ alias_method :all, :list
50
65
 
51
66
  # Get properties for a single organization
52
67
  #
68
+ # @see https://developer.github.com/v3/orgs/#get-an-organization
69
+ #
53
70
  # @example
54
71
  # github = Github.new
55
72
  # github.orgs.get 'github'
@@ -60,21 +77,25 @@ module Github
60
77
 
61
78
  get_request("/orgs/#{arguments.org_name}", arguments.params)
62
79
  end
63
- alias :find :get
80
+ alias_method :find, :get
64
81
 
65
82
  # Edit organization
66
83
  #
84
+ # @see https://developer.github.com/v3/orgs/#edit-an-organization
85
+ #
67
86
  # @param [Hash] params
68
- # @input params [String] :billing_email
87
+ # @option params [String] :billing_email
69
88
  # Billing email address. This address is not publicized.
70
- # @input params [String] :company
89
+ # @option params [String] :company
71
90
  # The company name
72
- # @input params [String] :email
91
+ # @option params [String] :email
73
92
  # The publicly visible email address
74
- # @input params [String] :location
93
+ # @option params [String] :location
75
94
  # The location
76
- # @input params [String] :name
95
+ # @option params [String] :name
77
96
  # The shorthand name of the company.
97
+ # @option params [String] :description
98
+ # The description of the company.
78
99
  #
79
100
  # @example
80
101
  # github = Github.new oauth_token: '...'
@@ -88,9 +109,7 @@ module Github
88
109
  #
89
110
  # @api public
90
111
  def edit(*args)
91
- arguments(args, required: [:org_name]) do
92
- permit VALID_ORG_PARAM_NAMES
93
- end
112
+ arguments(args, required: [:org_name])
94
113
 
95
114
  patch_request("/orgs/#{arguments.org_name}", arguments.params)
96
115
  end
@@ -10,21 +10,30 @@ module Github
10
10
  # both concealed and public members will be returned.
11
11
  # Otherwise only public members are returned.
12
12
  #
13
+ # @see https://developer.github.com/v3/orgs/members/#members-list
14
+ #
13
15
  # @param [Hash] params
14
- # @input params [String] :filter
16
+ # @option params [String] :filter
15
17
  # Filter members returned in the list. Can be one of:
16
18
  # * 2fa_disabled: Members without two-factor authentication enabled.
17
19
  # Available for owners of organizations with private repositories.
18
20
  # * all: All members the authenticated user can see.
19
21
  # Default: all
22
+ # @option params [String] :role
23
+ # Filter members returned by their role. Can be one of:
24
+ # * all: All members of the organization, regardless of role.
25
+ # * admin: Organization owners.
26
+ # * member: Non-owner organization members.
20
27
  #
21
28
  # @example
22
- # github = Github.new
23
- # github.orgs.members.list 'org-name'
24
- # github.orgs.members.list 'org-name' { |memb| ... }
29
+ # github = Github.new
30
+ # github.orgs.members.list 'org-name'
31
+ # github.orgs.members.list 'org-name' { |memb| ... }
25
32
  #
26
33
  # List public members
27
34
  #
35
+ # @see https://developer.github.com/v3/orgs/members/#public-members-list
36
+ #
28
37
  # Members of an organization can choose to have their
29
38
  # membership publicized or not.
30
39
  #
@@ -39,14 +48,14 @@ module Github
39
48
  org_name = arguments.org_name
40
49
 
41
50
  response = if params.delete('public')
42
- get_request("/orgs/#{org_name}/public_members", params)
43
- else
44
- get_request("/orgs/#{org_name}/members", params)
45
- end
51
+ get_request("/orgs/#{org_name}/public_members", params)
52
+ else
53
+ get_request("/orgs/#{org_name}/members", params)
54
+ end
46
55
  return response unless block_given?
47
56
  response.each { |el| yield el }
48
57
  end
49
- alias :all :list
58
+ alias_method :all, :list
50
59
 
51
60
  # Check if user is, publicly or privately, a member of an organization
52
61
  #
@@ -67,20 +76,22 @@ module Github
67
76
  user = arguments.user
68
77
 
69
78
  response = if params.delete('public')
70
- get_request("/orgs/#{org_name}/public_members/#{user}", params)
71
- else
72
- get_request("/orgs/#{org_name}/members/#{user}", params)
73
- end
79
+ get_request("/orgs/#{org_name}/public_members/#{user}", params)
80
+ else
81
+ get_request("/orgs/#{org_name}/members/#{user}", params)
82
+ end
74
83
  response.status == 204
75
84
  rescue Github::Error::NotFound
76
85
  false
77
- end
78
86
 
87
+ end
79
88
  # Remove a member
80
89
  #
81
90
  # Removing a user from this list will remove them from all teams and
82
91
  # they will no longer have any access to the organization’s repositories.
83
92
  #
93
+ # @see https://developer.github.com/v3/orgs/members/#remove-a-member
94
+ #
84
95
  # @example
85
96
  # github = Github.new
86
97
  # github.orgs.members.remove 'org-name', 'member-name'
@@ -89,11 +100,14 @@ module Github
89
100
  def delete(*args)
90
101
  arguments(args, required: [:org_name, :user])
91
102
 
92
- delete_request("/orgs/#{arguments.org_name}/members/#{arguments.user}", arguments.params)
103
+ delete_request("/orgs/#{arguments.org_name}/members/#{arguments.user}",
104
+ arguments.params)
93
105
  end
94
- alias :remove :delete
106
+ alias_method :remove, :delete
95
107
 
96
- # Publicize a users membership
108
+ # Publicize a user's membership
109
+ #
110
+ # @see https://developer.github.com/v3/orgs/members/#publicize-a-users-membership
97
111
  #
98
112
  # @example
99
113
  # github = Github.new oauth_token: '...'
@@ -108,11 +122,13 @@ module Github
108
122
  alias :make_public :publicize
109
123
  alias :publicize_membership :publicize
110
124
 
111
- # Conceal a users membership
125
+ # Conceal a user's membership
126
+ #
127
+ # @see https://developer.github.com/v3/orgs/members/#conceal-a-users-membership
112
128
  #
113
129
  # @example
114
- # github = Github.new oauth_token: '...'
115
- # github.orgs.members.conceal 'org-name', 'member-name'
130
+ # github = Github.new oauth_token: '...'
131
+ # github.orgs.members.conceal 'org-name', 'member-name'
116
132
  #
117
133
  # @api public
118
134
  def conceal(*args)
@@ -120,6 +136,6 @@ module Github
120
136
 
121
137
  delete_request("/orgs/#{arguments.org_name}/public_members/#{arguments.user}", arguments.params)
122
138
  end
123
- alias :conceal_membership :conceal
139
+ alias_method :conceal_membership, :conceal
124
140
  end # Client::Orgs::Members
125
141
  end # Github