Module: GogoKit::Utils

Overview

Utility methods for Client

Instance Method Summary collapse

Instance Method Details

#object_from_response(klass, klass_representer, method, url, options) ⇒ Object

Perform an HTTP request an map the to a Representable::JSON



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/gogokit/utils.rb', line 5

def object_from_response(klass,
                         klass_representer,
                         method,
                         url,
                         options)
  response = send(method.to_sym, url, options)
  return nil if response[:status] < 200 ||
                response[:status] > 299 ||
                response[:body].nil?

  klass.new.extend(klass_representer).from_json(response[:body])
end