Class: GhostReader::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#configObject

Returns the value of attribute config.



7
8
9
# File 'lib/ghost_reader/client.rb', line 7

def config
  @config
end

#last_modifiedObject

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_requestObject

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_requestObject

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