Class: Twitter::Response::ParseJson

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/twitter/response/parse_json.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) on_complete(env)



17
18
19
20
21
# File 'lib/twitter/response/parse_json.rb', line 17

def on_complete(env)
  if respond_to?(:parse)
    env[:body] = parse(env[:body]) unless [204, 301, 302, 304].include?(env[:status])
  end
end

- (Object) parse(body)



8
9
10
11
12
13
14
15
# File 'lib/twitter/response/parse_json.rb', line 8

def parse(body)
  case body
  when /\A^\s*$\z/, nil
    nil
  else
    MultiJson.decode(body, :symbolize_keys => true)
  end
end