forked from piotrmurach/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorgs.rb
More file actions
95 lines (83 loc) · 2.4 KB
/
orgs.rb
File metadata and controls
95 lines (83 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# encoding: utf-8
module Github
class Orgs < API
extend AutoloadHelper
autoload_all 'github_api/orgs',
:Members => 'members',
:Teams => 'teams'
VALID_ORG_PARAM_NAMES = %w[
billing_email
company
email
location
name
].freeze
# Access to Orgs::Members API
def members(options={}, &block)
@members ||= ApiFactory.new('Orgs::Members', current_options.merge(options), &block)
end
# Access to Orgs::Teams API
def teams(options={}, &block)
@teams ||= ApiFactory.new('Orgs::Teams', current_options.merge(options), &block)
end
# List all public organizations for a user.
#
# = Examples
# github = Github.new
# github.orgs.list user: 'user-name'
#
# List public and private organizations for the authenticated user.
#
# github = Github.new oauth_token: '..'
# github.orgs.list
#
def list(*args)
params = arguments(args).params
response = if (user_name = params.delete("user"))
get_request("/users/#{user_name}/orgs", params)
else
# For the authenticated user
get_request("/user/orgs", params)
end
return response unless block_given?
response.each { |el| yield el }
end
alias :all :list
# Get properties for a single organization
#
# = Examples
# github = Github.new
# github.orgs.get 'github'
#
def get(*args)
arguments(args, :required => [:org_name])
get_request("/orgs/#{org_name}", arguments.params)
end
alias :find :get
# Edit organization
#
# = Parameters
# <tt>:billing_email</tt> - Optional string - Billing email address. This address is not publicized.
# <tt>:company</tt> - Optional string
# <tt>:email</tt> - Optional string
# <tt>:location</tt> - Optional string
# <tt>:name</tt> - Optional string
#
# = Examples
# github = Github.new oauth_token: '...'
# github.orgs.edit 'github',
# "billing_email": "[email protected]",
# "blog": "https://github.com/blog",
# "company": "GitHub",
# "email": "[email protected]",
# "location": "San Francisco",
# "name": "github"
#
def edit(*args)
arguments(args, :required => [:org_name]) do
sift VALID_ORG_PARAM_NAMES
end
patch_request("/orgs/#{org_name}", arguments.params)
end
end # Orgs
end # Github