Class: CarrierwaveRoz::Client
- Inherits:
-
Object
- Object
- CarrierwaveRoz::Client
- Defined in:
- lib/carrierwave_roz/client.rb
Constant Summary collapse
- VERSION =
'v2'
Instance Attribute Summary collapse
-
#access_id ⇒ Object
readonly
Returns the value of attribute access_id.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#secret_key ⇒ Object
readonly
Returns the value of attribute secret_key.
Instance Method Summary collapse
- #delete(path) ⇒ Object
-
#initialize(base_url, access_id, secret_key) ⇒ Client
constructor
A new instance of Client.
- #upload(file, path) ⇒ Object
Constructor Details
#initialize(base_url, access_id, secret_key) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 |
# File 'lib/carrierwave_roz/client.rb', line 12 def initialize(base_url, access_id, secret_key) @base_url = base_url @access_id = access_id @secret_key = secret_key end |
Instance Attribute Details
#access_id ⇒ Object (readonly)
Returns the value of attribute access_id.
9 10 11 |
# File 'lib/carrierwave_roz/client.rb', line 9 def access_id @access_id end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
8 9 10 |
# File 'lib/carrierwave_roz/client.rb', line 8 def base_url @base_url end |
#secret_key ⇒ Object (readonly)
Returns the value of attribute secret_key.
10 11 12 |
# File 'lib/carrierwave_roz/client.rb', line 10 def secret_key @secret_key end |
Instance Method Details
#delete(path) ⇒ Object
33 34 35 36 37 |
# File 'lib/carrierwave_roz/client.rb', line 33 def delete(path) uri = url_for(:delete, path: path) send_request Net::HTTP::Delete.new(uri.request_uri), uri end |
#upload(file, path) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/carrierwave_roz/client.rb', line 18 def upload(file, path) uri = url_for(:upload) upload = UploadIO.new(file.to_file, file.content_type, file.original_filename) request = Net::HTTP::Post::Multipart.new uri.path, 'file' => upload, 'path' => path # Set Content-MD5 header. # This works around an incompatibility between api_auth and multipart-post. # It should no longer be required with api-auth > 1.2.3 body = request.body_stream.read request.body_stream.rewind request['Content-MD5'] = Digest::MD5.base64digest(body) send_request request, uri end |