Class: Resync::Client
- Inherits:
-
Object
- Object
- Resync::Client
- Defined in:
- lib/resync/client/client.rb,
lib/resync/client/version.rb
Overview
Utility class for retrieving HTTP content and parsing it as ResourceSync documents.
Constant Summary collapse
- VERSION =
The version of this gem.
'0.1.2'
Instance Method Summary collapse
-
#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
15 16 17 |
# File 'lib/resync/client/client.rb', line 15 def initialize(helper: HTTPHelper.new(user_agent: "resync-client #{VERSION}")) @helper = helper end |
Instance Method Details
#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.
52 53 54 55 |
# File 'lib/resync/client/client.rb', line 52 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.
42 43 44 45 |
# File 'lib/resync/client/client.rb', line 42 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.
34 35 36 37 |
# File 'lib/resync/client/client.rb', line 34 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.
23 24 25 26 27 28 29 |
# File 'lib/resync/client/client.rb', line 23 def get_and_parse(uri) uri = Resync::XML.to_uri(uri) raw_contents = get(uri) doc = XMLParser.parse(raw_contents) doc.client = self doc end |