Class: Hipbot::Http::Request

Inherits:
Struct
  • Object
show all
Defined in:
lib/hipbot/helpers/http.rb

Constant Summary collapse

DEFAULT_HEADERS =
{ 'accept-encoding' => 'gzip, compressed' }.freeze
CONNECTION_SETTINGS =
{ connect_timeout: 5, inactivity_timeout: 10 }.freeze
ERROR_CALLBACK =
->(error){ Hipbot.logger.error(error) }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Request

Returns a new instance of Request.



9
10
11
12
13
14
15
# File 'lib/hipbot/helpers/http.rb', line 9

def initialize *args
  super
  self.params ||= {}
  self.params = params.has_key?(:query) ? params : { query: params }
  self.params = { head: DEFAULT_HEADERS }.merge(params)
  Hipbot.logger.info("HTTP-REQUEST: #{url} #{params}")
end

Instance Attribute Details

#methodObject

Returns the value of attribute method

Returns:

  • (Object)

    the current value of method



4
5
6
# File 'lib/hipbot/helpers/http.rb', line 4

def method
  @method
end

#paramsObject

Returns the value of attribute params

Returns:

  • (Object)

    the current value of params



4
5
6
# File 'lib/hipbot/helpers/http.rb', line 4

def params
  @params
end

#urlObject

Returns the value of attribute url

Returns:

  • (Object)

    the current value of url



4
5
6
# File 'lib/hipbot/helpers/http.rb', line 4

def url
  @url
end

Instance Method Details

#call(&success_block) ⇒ Object



17
18
19
20
21
22
# File 'lib/hipbot/helpers/http.rb', line 17

def call &success_block
  http.errback(&ERROR_CALLBACK)
  http.callback do
    success(&success_block)
  end unless success_block.nil?
end