class Resync::Client

Utility class for retrieving HTTP content and parsing it as ResourceSync documents.

Constants

VERSION

The version of this gem.

Public Class Methods

new(helper: HTTPHelper.new(user_agent: "resync-client click to toggle source

Creates a new Client @param helper [HTTPHelper] the HTTP helper. Defaults to a new HTTP helper with

+resync-client VERSION+ as the User-Agent string.
# File lib/resync/client.rb, line 17
def initialize(helper: HTTPHelper.new(user_agent: "resync-client #{VERSION}"))
  @helper = helper
end

Public Instance Methods

client() click to toggle source

Allows a {Client} to act as a {Mixins::ClientDelegator} delegate. @return [Client] this client

# File lib/resync/client.rb, line 61
def client
  self
end
download_to_file(uri:, path:) click to toggle source

Gets the content of the specified URI and saves it to the specified file, overwriting it if it exists. @param uri [URI, String] the URI to download @param path [String] the path to save the download to @return [String] the path to the downloaded file

# 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) click to toggle source

Gets the content of the specified URI and saves it to a temporary file. @param uri [URI, String] the URI to download @return [String] the path to the downloaded file

# 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) click to toggle source

Gets the content of the specified URI as a string. @param uri [URI, String] the URI to download @return [String] the content of the URI

# 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) click to toggle source

Gets the content of the specified URI and parses it as a ResourceSync document.

# 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