Module: Tire::Utils

Included in:
ClickLog, Cluster, Index
Defined in:
lib/tire/utils.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.escape(s) ⇒ Object



7
8
9
# File 'lib/tire/utils.rb', line 7

def escape(s)
  URI.encode_www_form_component(s.to_s)
end

.unescape(s) ⇒ Object



11
12
13
14
# File 'lib/tire/utils.rb', line 11

def unescape(s)
  s = s.to_s.respond_to?(:force_encoding) ? s.to_s.force_encoding(Encoding::UTF_8) : s.to_s
  URI.decode_www_form_component(s)
end

Instance Method Details

#logged(endpoint = '/', curl = '') ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/tire/utils.rb', line 16

def logged(endpoint='/', curl='')
  if Configuration.logger
    error = $!

    Configuration.logger.log_request endpoint, @name, curl

    code = @response ? @response.code : error.class rescue 200

    if Configuration.logger.level.to_s == 'debug'
      body = if @response
        defined?(Yajl) ? Yajl::Encoder.encode(@response.body, :pretty => true) : MultiJson.encode(@response.body)
      else
        error.message rescue ''
      end
    else
      body = ''
    end

    Configuration.logger.log_response code, nil, body
  end
end