Sha256: 7c9f9c33680ab10e960e1329a4fbdeca367a8149897f6ba7835b05d7c37f3520
Contents?: true
Size: 1.59 KB
Versions: 2
Compression:
Stored size: 1.59 KB
Contents
require 'faraday' require 'wayback/api/archive' require 'wayback/configurable' require 'wayback/error/client_error' require 'wayback/error/decode_error' require 'uri' module Wayback # Wrapper for the Wayback Memento/Timehop API class Client include Wayback::API::Archive include Wayback::Configurable # Initializes a new Client object # # @param options [Hash] # @return [Wayback::Client] def initialize(options={}) Wayback::Configurable.keys.each do |key| instance_variable_set(:"@#{key}", options[key] || Wayback.instance_variable_get(:"@#{key}")) end end # Perform an HTTP DELETE request def delete(path, params={}) request(:delete, path, params) end # Perform an HTTP GET request def get(path, params={}) request(:get, path, params) end # Perform an HTTP POST request def post(path, params={}) signature_params = params.values.any?{|value| value.respond_to?(:to_io)} ? {} : params request(:post, path, params, signature_params) end # Perform an HTTP PUT request def put(path, params={}) request(:put, path, params) end private def request(method, path, params={}, signature_params=params) connection.send(method.to_sym, path.insert(0, @endpoint_path), params).env rescue Faraday::Error::ClientError raise Wayback::Error::ClientError end # Returns a Faraday::Connection object # # @return [Faraday::Connection] def connection @connection ||= Faraday.new(@endpoint, @connection_options.merge(:builder => @middleware)) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
wayback-0.2.1 | lib/wayback/client.rb |
wayback-0.2.0 | lib/wayback/client.rb |