Class: HydraWrapper

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

Overview

Copyright © 2010-2011, Diaspora Inc. This file is

licensed under the Affero General Public License version 3 or later.  See
the COPYRIGHT file.

Constant Summary collapse

OPTS =
{
  maxredirs: 3,
  timeout: 25,
  method: :post,
  verbose: AppConfig.settings.typhoeus_verbose?,
  cainfo: AppConfig.environment.certificate_authorities.get,
  headers: {
    'Expect'            => '',
    'Transfer-Encoding' => '',
    'User-Agent'        => "Diaspora #{AppConfig.version_string}"
  }
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, people, encoded_object_xml, dispatcher_class) ⇒ HydraWrapper


24
25
26
27
28
29
30
31
32
33
# File 'lib/hydra_wrapper.rb', line 24

def initialize user, people, encoded_object_xml, dispatcher_class
  @user = user
  @people_to_retry = []
  @people = people
  @dispatcher_class = dispatcher_class
  @encoded_object_xml = encoded_object_xml
  @keep_for_retry_proc = Proc.new do |response|
    true
  end
end

Instance Attribute Details

#dispatcher_classObject

Returns the value of attribute dispatcher_class


21
22
23
# File 'lib/hydra_wrapper.rb', line 21

def dispatcher_class
  @dispatcher_class
end

#encoded_object_xmlObject (readonly)

Returns the value of attribute encoded_object_xml


20
21
22
# File 'lib/hydra_wrapper.rb', line 20

def encoded_object_xml
  @encoded_object_xml
end

#peopleObject

Returns the value of attribute people


21
22
23
# File 'lib/hydra_wrapper.rb', line 21

def people
  @people
end

#people_to_retryObject (readonly)

Returns the value of attribute people_to_retry


20
21
22
# File 'lib/hydra_wrapper.rb', line 20

def people_to_retry
  @people_to_retry
end

#userObject (readonly)

Returns the value of attribute user


20
21
22
# File 'lib/hydra_wrapper.rb', line 20

def user
  @user
end

Instance Method Details

#enqueue_batchObject

Inserts jobs for all @people


36
37
38
39
40
41
42
# File 'lib/hydra_wrapper.rb', line 36

def enqueue_batch
  grouped_people.each do |receive_url, people_for_receive_url|
    if xml = xml_factory.xml_for(people_for_receive_url.first)
      insert_job(receive_url, xml, people_for_receive_url)
    end
  end
end

#keep_for_retry_if {|response| ... } ⇒ Object

This method can be used to tell the hydra whether or not to retry a request that it made which failed.

Yield Parameters:

  • response (Typhoeus::Response)

    The response object for the failed request.

Yield Returns:

  • (Boolean)

    Whether the request whose response was passed to the block should be retried.


48
49
50
# File 'lib/hydra_wrapper.rb', line 48

def keep_for_retry_if &block
  @keep_for_retry_proc = block
end