Class: GhostReader::Client
- Inherits:
-
Object
- Object
- GhostReader::Client
- Defined in:
- lib/ghost_reader/client.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#last_modified ⇒ Object
Returns the value of attribute last_modified.
Instance Method Summary collapse
-
#incremental_request ⇒ Object
returns a Head with three keys :timestamp (the value of last-modified header) :data (a nested Hash of translations) :status (the reponse status).
-
#initial_request ⇒ Object
returns a Head with three keys :timestamp (the value of last-modified header) :data (a nested Hash of translations) :status (the reponse status).
-
#initialize(conf = nil) ⇒ Client
constructor
A new instance of Client.
-
#reporting_request(data) ⇒ Object
returns true if redirected, false otherwise.
Constructor Details
#initialize(conf = nil) ⇒ Client
Returns a new instance of Client.
9 10 11 12 |
# File 'lib/ghost_reader/client.rb', line 9 def initialize(conf=nil) self.config = OpenStruct.new(default_config.merge(conf || {})) config.logger ||= Logger.new(config.logfile || STDOUT) end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
7 8 9 |
# File 'lib/ghost_reader/client.rb', line 7 def config @config end |
#last_modified ⇒ Object
Returns the value of attribute last_modified.
7 8 9 |
# File 'lib/ghost_reader/client.rb', line 7 def last_modified @last_modified end |
Instance Method Details
#incremental_request ⇒ Object
returns a Head with three keys
:timestamp (the value of last-modified header)
:data (a nested Hash of translations)
:status (the reponse status)
35 36 37 38 39 40 |
# File 'lib/ghost_reader/client.rb', line 35 def incremental_request headers = { 'If-Modified-Since' => self.last_modified } response = connect_with_retry(:get, :headers => headers) self.last_modified = response.get_header('Last-Modified') if response.status == 200 build_head(response) end |
#initial_request ⇒ Object
returns a Head with three keys
:timestamp (the value of last-modified header)
:data (a nested Hash of translations)
:status (the reponse status)
18 19 20 21 22 |
# File 'lib/ghost_reader/client.rb', line 18 def initial_request response = connect_with_retry self.last_modified = response.get_header('Last-Modified') build_head(response) end |
#reporting_request(data) ⇒ Object
returns true if redirected, false otherwise
25 26 27 28 29 |
# File 'lib/ghost_reader/client.rb', line 25 def reporting_request(data) response = connect_with_retry(:post, :body => "data=#{data.to_json}") log("Reporting request not redirected", :error) unless response.status == 302 { :status => response.status } end |