Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ SwiftClient offers the following requests:
* `bulk_delete(entries, options = {}) # => entries`
* `post_head(object_name, container_name, _headers = {}, options = {}) # => HTTParty::Response`

By default, the client instructs the Swift server to return JSON via an HTTP Accept header; to disable this pass `:json => false` in `options`. The rest of the `options` are passed directly to the internal [HTTParty](https://rubygems.org/gems/httparty) client.
By default, the client instructs the endpoint to return JSON via an HTTP Accept header. To specify another format pass, e.g., `:format => "plain"` via the `query` parameter of the `get_*` and `paginate_*` methods. Other formats, like `"xml"` are supported as well. Checkout [Object Storage API](https://docs.openstack.org/api-ref/object-store/index.html?expanded=show-container-details-and-list-objects-detail#show-container-details-and-list-objects) for more details.

All `options` are passed directly to the internal [HTTParty](https://rubygems.org/gems/httparty) client.

### Getting large objects
The `get_object` method with out a block is suitable for small objects that easily fit in memory. For larger objects, specify a block to process chunked data as it comes in.
Expand Down
2 changes: 1 addition & 1 deletion lib/swift_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def find_header_key(headers, key)
def request(method, path, opts = {}, &block)
headers = (opts[:headers] || {}).dup
headers["X-Auth-Token"] = auth_token
headers["Accept"] ||= "application/json" unless opts.delete(:json) == false
headers["Accept"] ||= "application/json" unless opts[:query] && opts[:query][:format]

stream_pos = opts[:body_stream].pos if opts[:body_stream]

Expand Down
6 changes: 3 additions & 3 deletions test/swift_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,12 @@ def test_get_objects
assert_equal objects, @swift_client.get_objects("container-1", :limit => 2, :marker => "object-2").parsed_response
end

def test_get_objects_no_json
def test_get_objects_format_plain
response = "object-2\nobject-3\n"

stub_request(:get, "https://example.com/v1/AUTH_account/container-1?limit=2&marker=object-2").with(:headers => { "X-Auth-Token" => "Token" }).to_return(:status => 200, :body => response, :headers => { "Content-Type" => "text/html" })
stub_request(:get, "https://example.com/v1/AUTH_account/container-1?format=plain&limit=2&marker=object-2").with(:headers => { "X-Auth-Token" => "Token" }).to_return(:status => 200, :body => response, :headers => { "Content-Type" => "text/plain" })

assert_equal response, @swift_client.get_objects("container-1", { :limit => 2, :marker => "object-2" }, :json => false).body
assert_equal response, @swift_client.get_objects("container-1", :format => "plain", :limit => 2, :marker => "object-2").body
end

def test_paginate_objects
Expand Down