Class: Myzofeedtosis::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/myzofeedtosis/client.rb

Overview

Myzofeedtosis::Client is the primary interface to the feed reader. Call it with a url that was previously fetched while connected to the configured backend, and it will 1) only do a retrieval if deemed necessary based on the etag and modified-at of the last etag and 2) mark all entries retrieved as either new or not new. Entries retrieved are normalized using the feed-normalizer gem.

Constant Summary collapse

DEFAULTS =
{
  :backend => {
    :moneta_klass => 'Moneta::Memory'
  }
}
@@backends =
{}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, options = { }) ⇒ Client

Initializes a new myzofeedtosis library. The backend can be a hash of options, in which case we initialize a new HashBack::Backend. Or, it may be a pre-initialized backend, in which case we set the backend to the given HashBack::Backend object.



23
24
25
26
27
28
29
30
31
32
# File 'lib/myzofeedtosis/client.rb', line 23

def initialize(url, options = { })
  @url      = url
  
  if options[:backend].is_a?(HashBack::Backend)
    @backend = options[:backend]
  else
    @options = DEFAULTS.merge(options.dup)
    @backend = HashBack::Backend.new( 'Myzofeedtosis', @options[:backend][:moneta_klass], @options[:backend].except(:moneta_klass) )        
  end      
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/myzofeedtosis/client.rb', line 10

def options
  @options
end

#urlObject (readonly)

Returns the value of attribute url.



10
11
12
# File 'lib/myzofeedtosis/client.rb', line 10

def url
  @url
end

Instance Method Details

#fetchObject

Retrieves the latest entries from this feed. Returns a Myzofeedtosis::Result object which delegates methods to the Curl::Easy object making the request and the FeedNormalizer::Feed object that may have been created from the HTTP response body.



38
39
40
41
42
43
# File 'lib/myzofeedtosis/client.rb', line 38

def fetch
  curl = build_curl_easy
  curl.perform
  feed = process_curl_response(curl)
  Myzofeedtosis::Result.new(curl, feed)
end