Class: Github::Downloads
- Inherits:
-
Object
- Object
- Github::Downloads
- Defined in:
- lib/github/downloads.rb
Defined Under Namespace
Classes: Download, UnexpectedResponse
Constant Summary collapse
- GITHUB_BASE_URL =
"https://api.github.com"
Instance Attribute Summary collapse
-
#uploader ⇒ Object
Returns the value of attribute uploader.
Class Method Summary collapse
Instance Method Summary collapse
- #create(file_path, description = "") ⇒ Object
-
#initialize(client, user, repos) ⇒ Downloads
constructor
A new instance of Downloads.
- #list ⇒ Object
Constructor Details
#initialize(client, user, repos) ⇒ Downloads
Returns a new instance of Downloads.
11 12 13 14 15 |
# File 'lib/github/downloads.rb', line 11 def initialize(client, user, repos) @client = client @user = user @repos = repos end |
Instance Attribute Details
#uploader ⇒ Object
Returns the value of attribute uploader.
7 8 9 |
# File 'lib/github/downloads.rb', line 7 def uploader @uploader end |
Class Method Details
.connect(user, password, repos) ⇒ Object
17 18 19 20 |
# File 'lib/github/downloads.rb', line 17 def self.connect(user, password, repos) client = Client.connect(GITHUB_BASE_URL, user, password) new(client, user, repos) end |
Instance Method Details
#create(file_path, description = "") ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/github/downloads.rb', line 40 def create(file_path, description = "") response = @client.post(downloads_resource_path, { :name => File.basename(file_path), :description => description, :content_type => MIME::Types.type_for(file_path)[0] || MIME::Types["application/octet-stream"][0], :size => File.size?(file_path) }) if response.success? uploader.upload(File.(file_path), response.data) end end |
#list ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/github/downloads.rb', line 30 def list response = @client.get(downloads_resource_path) if response.success? from_response_data(response.data) else raise UnexpectedResponse, response end end |