Class: GeminaboxClient
- Inherits:
-
Object
- Object
- GeminaboxClient
- Defined in:
- lib/geminabox_client.rb
Defined Under Namespace
Modules: GemLocator Classes: Error
Instance Attribute Summary collapse
-
#http_client ⇒ Object
readonly
Returns the value of attribute http_client.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #extract_username_and_password_from_url!(url) ⇒ Object
-
#initialize(url) ⇒ GeminaboxClient
constructor
A new instance of GeminaboxClient.
- #push(gemfile, options = {}) ⇒ Object
- #url_for(path) ⇒ Object
Constructor Details
#initialize(url) ⇒ GeminaboxClient
Returns a new instance of GeminaboxClient.
10 11 12 13 14 |
# File 'lib/geminabox_client.rb', line 10 def initialize(url) extract_username_and_password_from_url!(url) @http_client = Geminabox.http_adapter @http_client.set_auth(url_for(:upload), @username, @password) end |
Instance Attribute Details
#http_client ⇒ Object (readonly)
Returns the value of attribute http_client.
8 9 10 |
# File 'lib/geminabox_client.rb', line 8 def http_client @http_client end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
8 9 10 |
# File 'lib/geminabox_client.rb', line 8 def url @url end |
Instance Method Details
#extract_username_and_password_from_url!(url) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/geminabox_client.rb', line 16 def extract_username_and_password_from_url!(url) uri = URI.parse(url.to_s) @username = CGI.unescape(uri.user) if uri.user @password = CGI.unescape(uri.password) if uri.password uri.user = uri.password = nil uri.path = uri.path + "/" unless uri.path.end_with?("/") @url = uri.to_s end |
#push(gemfile, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/geminabox_client.rb', line 29 def push(gemfile, = {}) response = http_client.post(url_for(:upload), { 'file' => File.open(gemfile, "rb"), 'overwrite' => !![:overwrite] }, { 'Accept' => 'text/plain' }) if response.status < 300 response.body else raise GeminaboxClient::Error, "Error (#{response.status} received)\n\n#{response.body}" end end |
#url_for(path) ⇒ Object
25 26 27 |
# File 'lib/geminabox_client.rb', line 25 def url_for(path) url + path.to_s end |