Class: Gemkeeper::GemUploader
- Inherits:
-
Object
- Object
- Gemkeeper::GemUploader
- Defined in:
- lib/gemkeeper/gem_uploader.rb
Instance Attribute Summary collapse
-
#geminabox_url ⇒ Object
readonly
Returns the value of attribute geminabox_url.
Instance Method Summary collapse
-
#initialize(geminabox_url) ⇒ GemUploader
constructor
A new instance of GemUploader.
- #list_gems ⇒ Object
- #upload(gem_path) ⇒ Object
Constructor Details
#initialize(geminabox_url) ⇒ GemUploader
Returns a new instance of GemUploader.
10 11 12 |
# File 'lib/gemkeeper/gem_uploader.rb', line 10 def initialize(geminabox_url) @geminabox_url = geminabox_url end |
Instance Attribute Details
#geminabox_url ⇒ Object (readonly)
Returns the value of attribute geminabox_url.
8 9 10 |
# File 'lib/gemkeeper/gem_uploader.rb', line 8 def geminabox_url @geminabox_url end |
Instance Method Details
#list_gems ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gemkeeper/gem_uploader.rb', line 30 def list_gems response = connection.get("/api/v1/gems.json") raise UploadError, "Failed to list gems: #{response.status} #{response.body}" unless response.success? JSON.parse(response.body) rescue JSON::ParserError => e raise UploadError, "Invalid JSON response: #{e.}" rescue Faraday::Error => e raise UploadError, "Connection error: #{e.}" end |
#upload(gem_path) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gemkeeper/gem_uploader.rb', line 14 def upload(gem_path) raise UploadError, "Gem file not found: #{gem_path}" unless File.exist?(gem_path) response = connection.post("/upload") do |req| req.body = { file: Faraday::Multipart::FilePart.new( gem_path, "application/octet-stream", File.basename(gem_path) ) } end handle_response(response, gem_path) end |