Class: RailsBridge::ContentRequest

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ContentRequest

Options:

  • :default_content - Content to be returned in test mode or when the remote server is unavailable

  • :request_timeout - Maximum time to wait for successful response in ms

  • :cache_timeout - TTL expiry for cache in seconds - nil or 0 will prevent caching

  • :protocol - Protocol of remote server (http|https). Default is ‘http’

  • :host - Host of remote server.

  • :port - Port of remote server. Default is 80.

  • :path - Path for remote request. Default is ‘/’

  • :params - URL query params for remote request.

  • :fragment - URL part after the ‘#’ for remote request.

  • :url - Explicit URL for remote request.

    if the :url option is passed, the :protocol, :host, :port, :path, :params, and :fragment options are ignored
    


21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rails_bridge/content_request.rb', line 21

def initialize options={}
  if url = options[:url]
    self.url = url
  else
    self.protocol = options[:protocol]
    self.host = options[:host]
    self.port = options[:port]
    self.path = options[:path]
    self.params = options[:params]
  end
  self.default_content = options[:default_content]
  self.request_timeout = options[:request_timeout]
  self.cache_timeout = options[:cache_timeout]
end

Instance Attribute Details

#cache_timeoutObject

Returns the value of attribute cache_timeout.



5
6
7
# File 'lib/rails_bridge/content_request.rb', line 5

def cache_timeout
  @cache_timeout
end

#content_bridgeObject

Returns the value of attribute content_bridge.



5
6
7
# File 'lib/rails_bridge/content_request.rb', line 5

def content_bridge
  @content_bridge
end

#default_contentObject

Returns the value of attribute default_content.



5
6
7
# File 'lib/rails_bridge/content_request.rb', line 5

def default_content
  @default_content
end

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/rails_bridge/content_request.rb', line 5

def host
  @host
end

#on_successObject

Returns the value of attribute on_success.



6
7
8
# File 'lib/rails_bridge/content_request.rb', line 6

def on_success
  @on_success
end

#paramsObject

Returns the value of attribute params.



5
6
7
# File 'lib/rails_bridge/content_request.rb', line 5

def params
  @params
end

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/rails_bridge/content_request.rb', line 5

def path
  @path
end

#portObject

Returns the value of attribute port.



5
6
7
# File 'lib/rails_bridge/content_request.rb', line 5

def port
  @port
end

#protocolObject

Returns the value of attribute protocol.



5
6
7
# File 'lib/rails_bridge/content_request.rb', line 5

def protocol
  @protocol
end

#request_timeoutObject

Returns the value of attribute request_timeout.



5
6
7
# File 'lib/rails_bridge/content_request.rb', line 5

def request_timeout
  @request_timeout
end

#urlObject

We don’t include the params in the URL, because Typhoeus::Request takes them as a separate argument



55
56
57
# File 'lib/rails_bridge/content_request.rb', line 55

def url
  @url
end

Instance Method Details

#get_remote_content(options = {}) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/rails_bridge/content_request.rb', line 59

def get_remote_content( options={} )
  if self.content_bridge
    self.content_bridge.get_remote_content( self, options )
  else
    RailsBridge::ContentBridge.get_remote_content( self, options )
  end
end