Class: Resync::Client

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(helper: HTTPHelper.new(user_agent: "resync-client #{VERSION}")) ⇒ Client

Creates a new Client

Parameters:

  • helper (HTTPHelper) (defaults to: HTTPHelper.new(user_agent: "resync-client #{VERSION}"))

    the HTTP helper. Defaults to a new HTTP helper with resync-client VERSION as the User-Agent string.



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

#clientClient

Returns:



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.

Parameters:

  • uri (URI, String)

    the URI to download

  • path (String)

    the path to save the download to

Returns:

  • (String)

    the path to the downloaded file



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.

Parameters:

  • uri (URI, String)

    the URI to download

Returns:

  • (String)

    the path to the downloaded 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.

Parameters:

  • uri (URI, String)

    the URI to download

Returns:

  • (String)

    the content of the URI



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