Class: Resync::Client
- Inherits:
-
Object
- Object
- Resync::Client
- Defined in:
- lib/resync/client.rb,
lib/resync/client/version.rb,
lib/resync/client/http_helper.rb,
lib/resync/client/mixins/dump.rb,
lib/resync/client/zip/bitstream.rb,
lib/resync/client/zip/zip_package.rb,
lib/resync/client/mixins/dump_index.rb,
lib/resync/client/mixins/list_index.rb,
lib/resync/client/mixins/plain_list.rb,
lib/resync/client/mixins/change_index.rb,
lib/resync/client/mixins/downloadable.rb,
lib/resync/client/mixins/dump_manifest.rb,
lib/resync/client/mixins/zipped_resource.rb,
lib/resync/client/mixins/client_delegator.rb,
lib/resync/client/mixins/bitstream_resource.rb,
lib/resync/client/mixins/link_client_delegate.rb,
lib/resync/client/mixins/resource_client_delegate.rb
Overview
Utility class for retrieving HTTP content and parsing it as ResourceSync documents.
Defined Under Namespace
Modules: Mixins, Zip Classes: HTTPHelper
Constant Summary collapse
- VERSION =
The version of this gem.
'0.4.7'.freeze
Instance Method Summary collapse
-
#client ⇒ Client
Allows a Client to act as a Mixins::ClientDelegator delegate.
-
#download_to_file(uri:, path:) ⇒ String
Gets the content of the specified URI and saves it to the specified file, overwriting it if it exists.
-
#download_to_temp_file(uri) ⇒ String
Gets the content of the specified URI and saves it to a temporary file.
-
#get(uri) ⇒ String
Gets the content of the specified URI as a string.
-
#get_and_parse(uri) ⇒ Object
Gets the content of the specified URI and parses it as a ResourceSync document.
-
#initialize(helper: HTTPHelper.new(user_agent: "resync-client #{VERSION}")) ⇒ Client
constructor
Creates a new
Client
.
Constructor Details
#initialize(helper: HTTPHelper.new(user_agent: "resync-client #{VERSION}")) ⇒ Client
Creates a new Client
17 18 19 |
# File 'lib/resync/client.rb', line 17 def initialize(helper: HTTPHelper.new(user_agent: "resync-client #{VERSION}")) @helper = helper end |
Instance Method Details
#client ⇒ Client
Allows a Resync::Client to act as a Resync::Client::Mixins::ClientDelegator delegate.
61 62 63 |
# File 'lib/resync/client.rb', line 61 def client self end |
#download_to_file(uri:, path:) ⇒ String
Gets the content of the specified URI and saves it to the specified file, overwriting it if it exists.
54 55 56 57 |
# File 'lib/resync/client.rb', line 54 def download_to_file(uri:, path:) uri = Resync::XML.to_uri(uri) @helper.fetch_to_file(path: path, uri: uri) end |
#download_to_temp_file(uri) ⇒ String
Gets the content of the specified URI and saves it to a temporary file.
44 45 46 47 |
# File 'lib/resync/client.rb', line 44 def download_to_temp_file(uri) uri = Resync::XML.to_uri(uri) @helper.fetch_to_file(uri: uri) end |
#get(uri) ⇒ String
Gets the content of the specified URI as a string.
36 37 38 39 |
# File 'lib/resync/client.rb', line 36 def get(uri) uri = Resync::XML.to_uri(uri) @helper.fetch(uri: uri) end |
#get_and_parse(uri) ⇒ Object
Gets the content of the specified URI and parses it as a ResourceSync document.
25 26 27 28 29 30 31 |
# File 'lib/resync/client.rb', line 25 def get_and_parse(uri) uri = Resync::XML.to_uri(uri) raw_contents = get(uri) doc = XMLParser.parse(raw_contents) doc.client_delegate = self doc end |