Class: ReposDownloads
- Inherits:
-
Object
- Object
- ReposDownloads
- Defined in:
- lib/github/repos/repos_downloads.rb
Instance Attribute Summary collapse
-
#github ⇒ Object
Returns the value of attribute github.
Instance Method Summary collapse
- #createDownload(repo, filePath, description = nil, content_type = nil, user = nil) ⇒ Object
- #deleteDownload(repo, id, user = nil) ⇒ Object
- #getDownload(repo, id, user = nil) ⇒ Object
- #getDownloads(repo, user = nil) ⇒ Object
-
#initialize(github) ⇒ ReposDownloads
constructor
A new instance of ReposDownloads.
Constructor Details
#initialize(github) ⇒ ReposDownloads
Returns a new instance of ReposDownloads.
4 5 6 |
# File 'lib/github/repos/repos_downloads.rb', line 4 def initialize(github) @github = github end |
Instance Attribute Details
#github ⇒ Object
Returns the value of attribute github.
2 3 4 |
# File 'lib/github/repos/repos_downloads.rb', line 2 def github @github end |
Instance Method Details
#createDownload(repo, filePath, description = nil, content_type = nil, user = nil) ⇒ Object
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 |
# File 'lib/github/repos/repos_downloads.rb', line 18 def createDownload(repo, filePath, description=nil, content_type=nil, user=nil) puts 'user:%s' % @github.username puts 'password:%s' % @github.password # PART 1: Create the resource @ github username = user == nil ? @github.username : user params = { :name => Pathname.new(filePath).basename, :size => File.new(filePath).size, :description => description, :content_type => content_type } params = @github.removeEmptyParams(params) data = params.to_json resource = @github.post('repos/%s/%s/downloads' % [username, repo], data) # PART 2: Create the download @ Amazon s3 response = RestClient.post(resource['s3_url'], [ ['key', resource['path']], ['acl', resource['acl']], ['success_action_status', 201], ['Filename', resource['name']], ['AWSAccessKeyId', resource['accesskeyid']], ['Policy', resource['policy']], ['Signature', resource['signature']], ['Content-Type', resource['mime_type']], ['file', File.open(filePath)] ]) if response.code == 201 resource['html_url'] else response.code end end |
#deleteDownload(repo, id, user = nil) ⇒ Object
51 52 53 54 |
# File 'lib/github/repos/repos_downloads.rb', line 51 def deleteDownload(repo, id, user=nil) username = user == nil ? @github.username : user @github.delete('repos/%s/%s/downloads/%s' % [username, repo, id],) end |
#getDownload(repo, id, user = nil) ⇒ Object
13 14 15 16 |
# File 'lib/github/repos/repos_downloads.rb', line 13 def getDownload(repo, id, user=nil) username = user == nil ? @github.username : user @github.get('repos/%s/%s/downloads/%s' % [username, repo, id]) end |
#getDownloads(repo, user = nil) ⇒ Object
8 9 10 11 |
# File 'lib/github/repos/repos_downloads.rb', line 8 def getDownloads(repo, user=nil) username = user == nil ? @github.username : user @github.get('repos/%s/%s/downloads' % [username, repo]) end |