Class: Wayback::Client

Inherits:
Object
  • Object
show all
Includes:
API::Archive, Configurable
Defined in:
lib/wayback/client.rb

Overview

Wrapper for the Wayback Memento/Timehop API

Instance Attribute Summary

Attributes included from Configurable

#connection_options, #endpoint, #endpoint_path, #identity_map, #json_endpoint, #json_endpoint_path, #middleware

Instance Method Summary collapse

Methods included from Configurable

#configure, keys, #reset!

Methods included from API::Archive

#available, #list, #page

Constructor Details

#initialize(options = {}) ⇒ Wayback::Client

Initializes a new Client object

Parameters:

  • options (Hash) (defaults to: {})


18
19
20
21
22
# File 'lib/wayback/client.rb', line 18

def initialize(options={})
  Wayback::Configurable.keys.each do |key|
    instance_variable_set(:"@#{key}", options[key] || Wayback.instance_variable_get(:"@#{key}"))
  end
end

Instance Method Details

#delete(path, params = {}) ⇒ Object

Perform an HTTP DELETE request



25
26
27
# File 'lib/wayback/client.rb', line 25

def delete(path, params={})
  request(:delete, path, params)
end

#get(path, params = {}) ⇒ Object

Perform an HTTP GET request



30
31
32
# File 'lib/wayback/client.rb', line 30

def get(path, params={})
  request(:get, path, params)
end

#json_get(path, params = {}) ⇒ Object

Perform an HTTP GET request from JSON API



46
47
48
# File 'lib/wayback/client.rb', line 46

def json_get(path, params={})
  json_request(:get, path, params)
end

#post(path, params = {}) ⇒ Object

Perform an HTTP POST request



35
36
37
38
# File 'lib/wayback/client.rb', line 35

def post(path, params={})
  signature_params = params.values.any?{|value| value.respond_to?(:to_io)} ? {} : params
  request(:post, path, params, signature_params)
end

#put(path, params = {}) ⇒ Object

Perform an HTTP PUT request



41
42
43
# File 'lib/wayback/client.rb', line 41

def put(path, params={})
  request(:put, path, params)
end