github_api 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,6 +6,7 @@ require 'github_api/request'
6
6
  require 'github_api/mime_type'
7
7
  require 'github_api/core_ext/hash'
8
8
  require 'github_api/core_ext/array'
9
+ require 'github_api/compatibility'
9
10
 
10
11
  module Github
11
12
 
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+
3
+ if RUBY_VERSION < "1.9"
4
+
5
+ def ruby_18 #:nodoc:
6
+ yield
7
+ end
8
+
9
+ def ruby_19 #:nodoc:
10
+ false
11
+ end
12
+
13
+ else
14
+
15
+ def ruby_18 #:nodoc:
16
+ false
17
+ end
18
+
19
+ def ruby_19 #:nodoc:
20
+ yield
21
+ end
22
+
23
+ end
@@ -37,12 +37,12 @@ module Github
37
37
 
38
38
  # parse(options['resource'], options['mime_type'] || mime_type) if options['mime_type']
39
39
  debugger
40
-
41
- merged_options = if connection_options.empty?
42
- header_options
43
- else
44
- connection_options.merge(header_options)
45
- end
40
+ # merged_options = if connection_options.empty?
41
+ # header_options.merge(options)
42
+ # else
43
+ # connection_options.merge(header_options)
44
+ # end
45
+ merged_options = header_options.merge(options)
46
46
 
47
47
  clear_cache unless options.empty?
48
48
 
@@ -17,7 +17,7 @@ module Github
17
17
  email
18
18
  location
19
19
  name
20
- ]
20
+ ].freeze
21
21
 
22
22
  # Creates new Orgs API
23
23
  def initialize(options = {})
@@ -47,6 +47,8 @@ module Github
47
47
  return response unless block_given?
48
48
  response.each { |el| yield el }
49
49
  end
50
+ alias :list_orgs :orgs
51
+ alias :list_organizations :orgs
50
52
 
51
53
  # Get properties for a single organization
52
54
  #
@@ -58,6 +60,8 @@ module Github
58
60
  _validate_presence_of org_name
59
61
  get("/orgs/#{org_name}")
60
62
  end
63
+ alias :get_org :org
64
+ alias :organisation :org
61
65
 
62
66
  # Edit organization
63
67
  #
@@ -85,6 +89,7 @@ module Github
85
89
 
86
90
  patch("/orgs/#{org_name}", params)
87
91
  end
92
+ alias :edit_organization :edit_org
88
93
 
89
94
  end # Orgs
90
95
  end # Github
@@ -6,15 +6,16 @@ module Github
6
6
 
7
7
  # List members
8
8
  #
9
- # List all users who are members of an organization. A member is a user
10
- # that belongs to at least 1 team in the organization.
11
- # If the authenticated user is also a member of this organization then
12
- # both concealed and public members will be returned.
9
+ # List all users who are members of an organization. A member is a user
10
+ # that belongs to at least 1 team in the organization.
11
+ # If the authenticated user is also a member of this organization then
12
+ # both concealed and public members will be returned.
13
13
  # Otherwise only public members are returned.
14
14
  #
15
15
  # = Examples
16
16
  # @github = Github.new
17
17
  # @github.orgs.members 'org-name'
18
+ # @github.orgs.members 'org-name' { |memb| ... }
18
19
  #
19
20
  def members(org_name, params={})
20
21
  _validate_presence_of org_name
@@ -23,6 +24,7 @@ module Github
23
24
  return response unless block_given?
24
25
  response.each { |el| yield el }
25
26
  end
27
+ alias :list_members :members
26
28
 
27
29
  # Check if user is a member of an organization
28
30
  #
@@ -38,6 +40,7 @@ module Github
38
40
  rescue Github::ResourceNotFound
39
41
  false
40
42
  end
43
+ alias :is_member? :member?
41
44
 
42
45
  # Remove a member
43
46
  # Removing a user from this list will remove them from all teams and
@@ -52,12 +55,14 @@ module Github
52
55
  _normalize_params_keys(params)
53
56
  delete("/orgs/#{org_name}/members/#{member_name}", params)
54
57
  end
58
+ alias :remove_member :delete_member
55
59
 
56
60
  # List public members
57
61
  # Members of an organization can choose to have their membership publicized or not.
58
62
  # = Examples
59
63
  # @github = Github.new
60
64
  # @github.orgs.public_members 'org-name'
65
+ # @github.orgs.public_members 'org-name' { |memb| ... }
61
66
  #
62
67
  def public_members(org_name, params={})
63
68
  _validate_presence_of org_name
@@ -66,6 +71,8 @@ module Github
66
71
  return response unless block_given?
67
72
  response.each { |el| yield el }
68
73
  end
74
+ alias :list_public_members :public_members
75
+
69
76
  # Get if a user is a public member of an organization
70
77
  #
71
78
  # = Examples
@@ -92,6 +99,8 @@ module Github
92
99
  _normalize_params_keys(params)
93
100
  put("/orgs/#{org_name}/public_members/#{member_name}", params)
94
101
  end
102
+ alias :make_public :publicize
103
+ alias :publicize_membership :publicize
95
104
 
96
105
  # Conceal a user’s membership
97
106
  #
@@ -104,6 +113,7 @@ module Github
104
113
  _normalize_params_keys(params)
105
114
  delete("/orgs/#{org_name}/public_members/#{member_name}", params)
106
115
  end
116
+ alias :conceal_membership :conceal
107
117
 
108
118
  end # Members
109
119
  end # Orgs
@@ -7,9 +7,9 @@ module Github
7
7
  # Api calls that require explicit permissions are noted.
8
8
  module Teams
9
9
 
10
- VALID_TEAM_PARAM_NAMES = %w[ name repo_names permission ]
10
+ VALID_TEAM_PARAM_NAMES = %w[ name repo_names permission ].freeze
11
11
  VALID_TEAM_PARAM_VALUES = {
12
- 'permission' => %w[ pull push admin ]
12
+ 'permission' => %w[ pull push admin ].freeze
13
13
  }
14
14
 
15
15
  # List teams
@@ -22,10 +22,11 @@ module Github
22
22
  _validate_presence_of org_name
23
23
  _normalize_params_keys(params)
24
24
 
25
- get("/orgs/#{org_name}/teams", params)
25
+ response = get("/orgs/#{org_name}/teams", params)
26
26
  return response unless block_given?
27
27
  response.each { |el| yield el }
28
28
  end
29
+ alias :list_teams :teams
29
30
 
30
31
  # Get a team
31
32
  #
@@ -39,6 +40,7 @@ module Github
39
40
 
40
41
  get("/teams/#{team_name}", params)
41
42
  end
43
+ alias :get_team :team
42
44
 
43
45
  # Create a team
44
46
  #
@@ -71,7 +73,7 @@ module Github
71
73
  post("/orgs/#{org_name}/teams", params)
72
74
  end
73
75
 
74
- # Create a team
76
+ # Edit a team
75
77
  # In order to edit a team, the authenticated user must be an owner of the org that the team is associated with.
76
78
  #
77
79
  # = Inputs
@@ -123,10 +125,11 @@ module Github
123
125
  _validate_presence_of team_name
124
126
  _normalize_params_keys(params)
125
127
 
126
- response = get("/teams/:id/members", params)
128
+ response = get("/teams/#{team_name}/members", params)
127
129
  return response unless block_given?
128
130
  response.each { |el| yield el }
129
131
  end
132
+ alias :list_team_members :team_members
130
133
 
131
134
  # Check if a user is a member of a team
132
135
  #
@@ -155,6 +158,7 @@ module Github
155
158
  _normalize_params_keys(params)
156
159
  put("/teams/#{team_name}/members/#{member_name}", params)
157
160
  end
161
+ alias :add_member :add_team_member
158
162
 
159
163
  # Remove a team member
160
164
  # In order to remove a user from a team, the authenticated user must
@@ -171,6 +175,7 @@ module Github
171
175
  _normalize_params_keys(params)
172
176
  delete("/teams/#{team_name}/members/#{member_name}", params)
173
177
  end
178
+ alias :remove_member :remove_team_member
174
179
 
175
180
  # List team repositories
176
181
  #
@@ -179,19 +184,20 @@ module Github
179
184
  # @github.orgs.team_repos 'team-name'
180
185
  #
181
186
  def team_repos(team_name, params={})
182
- _validate_presence_of team_name, member_name
187
+ _validate_presence_of team_name
183
188
  _normalize_params_keys(params)
184
189
 
185
190
  response = get("/teams/#{team_name}/repos", params)
186
191
  return response unless block_given?
187
192
  response.each { |el| yield el }
188
193
  end
194
+ alias :team_repositories :team_repos
189
195
 
190
196
  # Check if a repository belongs to a team
191
197
  #
192
198
  # = Examples
193
199
  # @github = Github.new :oauth_token => '...'
194
- # @github.orgs.team_repo? 'team-name'
200
+ # @github.orgs.team_repo? 'team-name', 'user-name', 'repo-name'
195
201
  #
196
202
  def team_repo?(team_name, user_name, repo_name, params={})
197
203
  _validate_presence_of team_name, user_name, repo_name
@@ -201,6 +207,7 @@ module Github
201
207
  rescue Github::ResourceNotFound
202
208
  false
203
209
  end
210
+ alias :team_repository? :team_repo?
204
211
 
205
212
  # Add a team repository
206
213
  # In order to add a repo to a team, the authenticated user must be
@@ -215,6 +222,7 @@ module Github
215
222
  _normalize_params_keys(params)
216
223
  put("/teams/#{team_name}/repos/#{user_name}/#{repo_name}", params)
217
224
  end
225
+ alias :add_team_repository :add_team_repo
218
226
 
219
227
  # Remove a team repository
220
228
  # In order to add a repo to a team, the authenticated user must be
@@ -230,6 +238,7 @@ module Github
230
238
  _normalize_params_keys(params)
231
239
  delete("/teams/#{team_name}/repos/#{user_name}/#{repo_name}", params)
232
240
  end
241
+ alias :remove_team_repository :remove_team_repo
233
242
 
234
243
  end # Teams
235
244
  end # Orgs
@@ -3,73 +3,151 @@
3
3
  module Github
4
4
  class Repos
5
5
  module Downloads
6
-
6
+
7
7
  REQUIRED_PARAMS = %w[ name size ]
8
- VALID_PARAMS = %w[ name size description content_type ]
9
8
 
10
- REQUIRED_S3_PARAMS = %w[ key acl success_action_status Filename AWSAccessKeyId Policy Signature Content-Type file ]
9
+ VALID_DOWNLOAD_PARAM_NAMES = %w[
10
+ name
11
+ size
12
+ description
13
+ content_type
14
+ ].freeze
15
+
16
+ REQUIRED_S3_PARAMS = %w[
17
+ path
18
+ acl
19
+ name
20
+ accesskeyid
21
+ policy
22
+ signature
23
+ mime_type
24
+ ].freeze
25
+
26
+ # Status code for successful upload to Amazon S3 service
27
+ SUCCESS_STATUS = 201
11
28
 
12
29
  # List downloads for a repository
13
30
  #
14
- # GET /repos/:user/:repo/downloads
31
+ # = Examples
32
+ # @github = Github.new
33
+ # @github.repos.downloads 'user-name', 'repo-name'
34
+ # @github.repos.downloads 'user-name', 'repo-name' { |downl| ... }
15
35
  #
16
- def downloads(user, repo)
17
- get("/repos/#{user}/#{repo}/downloads")
36
+ def downloads(user_name=nil, repo_name=nil, params={})
37
+ _update_user_repo_params(user_name, repo_name)
38
+ _validate_user_repo_params(user, repo) unless user? && repo?
39
+ _normalize_params_keys(params)
40
+
41
+ response = get("/repos/#{user}/#{repo}/downloads")
42
+ return response unless block_given?
43
+ response.each { |el| yield el }
18
44
  end
45
+ alias :list_downloads :downloads
46
+ alias :get_downloads :downloads
19
47
 
20
48
  # Get a single download
21
49
  #
22
- # GET /repos/:user/:repo/downloads/:id
50
+ # = Examples
51
+ # @github = Github.new
52
+ # @github.repos.download 'user-name', 'repo-name'
23
53
  #
24
- def get_download(user, repo, download_id)
54
+ def download(user_name, repo_name, download_id, params={})
55
+ _update_user_repo_params(user_name, repo_name)
56
+ _validate_user_repo_params(user, repo) unless user? && repo?
57
+ _validate_presence_of download_id
58
+ _normalize_params_keys(params)
59
+
25
60
  get("/repos/#{user}/#{repo}/downloads/#{download_id}")
26
61
  end
62
+ alias :get_download :download
27
63
 
28
64
  # Delete download from a repository
29
65
  #
30
- # DELETE /repos/:user/:repo/downloads/:id
66
+ # = Examples
67
+ # @github = Github.new
68
+ # @github.repos.delete_download 'user-name', 'repo-name', 'download-id'
31
69
  #
32
- def delete_download(user, repo, download_id)
70
+ def delete_download(user_name, repo_name, download_id, params={})
71
+ _update_user_repo_params(user_name, repo_name)
72
+ _validate_user_repo_params(user, repo) unless user? && repo?
73
+ _validate_presence_of download_id
74
+ _normalize_params_keys(params)
75
+
33
76
  delete("/repos/#{user}/#{repo}/downloads/#{download_id}")
34
77
  end
35
78
 
36
- # Creating a new download is a two step process.
79
+ # Creating a new download is a two step process.
37
80
  # You must first create a new download resource using this method.
38
81
  # Response from this method is to be used in #upload method.
39
82
  #
40
- # POST /repos/:user/:repo/downloads
83
+ # = Inputs
84
+ # * <tt>:name</tt> - Required string - name of the file that is being created.
85
+ # * <tt>:size</tt> - Required number - size of file in bytes.
86
+ # * <tt>:description</tt> - Optional string
87
+ # * <tt>:content_type</tt> - Optional string
41
88
  #
42
- def create_download(user, repo, params={})
89
+ # = Examples
90
+ # @github = Github.new
91
+ # @github.repos.create_download 'user-name', 'repo-name',
92
+ # "name" => "new_file.jpg",
93
+ # "size" => 114034,
94
+ # "description" => "Latest release",
95
+ # "content_type" => "text/plain"
96
+ #
97
+ def create_download(user_name=nil, repo_name=nil, params={})
98
+ _update_user_repo_params(user_name, repo_name)
99
+ _validate_user_repo_params(user, repo) unless user? && repo?
100
+
43
101
  _normalize_params_keys(params)
44
- raise ArgumentError, "expected following inputs to the method: #{REQUIRED_INPUTS.join(', ')}" unless _valid_inputs(REQUIRED_PARAMS, params)
45
- _filter_params_keys(VALID_PARAMS, params)
102
+ _filter_params_keys(VALID_DOWNLOAD_PARAM_NAMES, params)
103
+
104
+ raise ArgumentError, "Required parameters are: #{REQUIRED_PARAMS.join(', ')}" unless _validate_inputs(REQUIRED_PARAMS, params)
46
105
 
47
106
  post("/repos/#{user}/#{repo}/downloads", params)
48
107
  end
49
-
50
- # Upload a file to Amazon, using the reponse instance from
51
- # Github::Repos::Downloads#create. This can be done by passing
108
+
109
+ # Upload a file to Amazon, using the reponse instance from
110
+ # Github::Repos::Downloads#create_download. This can be done by passing
52
111
  # the response object as an argument to upload method.
53
112
  #
54
- def upload(result, file)
113
+ # = Parameters
114
+ # * <tt>resource</tt> - Required Hashie::Mash -resource of the create_download call
115
+ # * <tt>:size</tt> - Required number - size of file in bytes.
116
+ #
117
+ def upload(resource, filename)
118
+ _validate_presence_of resource, filename
119
+ raise ArgumentError, 'Need to provied resource of Github::Repose::Downloads#create_download call' unless resource.is_a? Hashie::Mash
120
+
55
121
  REQUIRED_S3_PARAMS.each do |key|
56
- raise ArgumentError, "expected following keys: #{REQUIRED_S3_PARAMS.join(', ')}" unless result.respond_to?(key)
122
+ raise ArgumentError, "Expected following key: #{key}" unless resource.respond_to?(key)
57
123
  end
58
-
124
+
59
125
  # TODO use ordered hash if Ruby < 1.9
126
+ hash = ruby_18 {
127
+ require 'active_support'
128
+ ActiveSupport::OrderedHash.new } || ruby_19 { Hash.new }
129
+
60
130
  mapped_params = {
61
- "key" => result.path,
62
- "acl" => result.acl,
63
- "success_action_status" => 201,
64
- "Filename" => result.name,
65
- "AWSAccessKeyId" => result.accesskeyid,
66
- "Policy" => result.policy,
67
- "Signature" => result.signature,
68
- "Content-Type" => result.mime_type,
69
- "file" => file
131
+ 'key' => resource.path,
132
+ 'acl' => resource.acl,
133
+ 'success_action_status' => SUCCESS_STATUS,
134
+ 'Filename' => resource.name,
135
+ 'AWSAccessKeyId' => resource.accesskeyid,
136
+ 'Policy' => resource.policy,
137
+ 'Signature' => resource.signature,
138
+ 'Content-Type' => resource.mime_type,
139
+ 'file' => prepend_at_for(filename.to_s)
70
140
  }
71
-
72
- post(result.s3_url, mapped_params)
141
+
142
+ post('', mapped_params, { :url => resource.s3_url })
143
+ end
144
+ alias :upload_to_s3 :upload
145
+ alias :upload_to_amazon :upload
146
+
147
+ private
148
+
149
+ def prepend_at_for(file)
150
+ /^@.*/ =~ file ? '@' + file : file
73
151
  end
74
152
 
75
153
  end # Downloads