Project

General

Profile

Revision e5f2394a

Added by Justin Sherrill over 5 years ago

Support rest_client 2.0

Runcible was built around being able to take a
rest client response body, pull out relevant details
and craft a new rest client response object with the boy
being the parsed json rather than the raw json. Rest Client
2.0 makes this impossible by making the Response object extend
string.

To resolve this while attempting to not break compatibility, we
have introduced a Runcible::Response object that attempts to pass
method calls to the parsed JSON body, and if that does not make
sense, to the Rest Client Response object.

Even still, I still bumped the version to 2.0 in case there is any
change I am not seeing.

View differences:

lib/runcible/base.rb
75 75
    end
76 76

  
77 77
    def get_response(client, path, *args)
78
      client[path].send(*args) do |response, request, result, &_block|
79
        resp = response.return!(request, result)
78
      client[path].send(*args) do |response, _request, _result, &_block|
79
        resp = response.return!
80 80
        log_debug
81 81
        return resp
82 82
      end
......
132 132
            i.respond_to?(:with_indifferent_access) ? i.with_indifferent_access : i
133 133
          end
134 134
        end
135
        response = rest_client_response(body, response.net_http_res, response.args)
135
        response = Runcible::Response.new(body, response)
136 136
      rescue JSON::ParserError
137 137
        log_exception
138 138
      end
......
140 140
      return response
141 141
    end
142 142

  
143
    def rest_client_response(body, net_http_res, args)
144
      if Gem.loaded_specs['rest-client'].version < Gem::Version.create('1.8.0')
145
        RestClient::Response.create(body, net_http_res, args)
146
      else
147
        RestClient::Response.create(body, net_http_res, args, nil)
148
      end
149
    end
150

  
151 143
    def required_params(local_names, binding, keys_to_remove = [])
152 144
      local_names = local_names.each_with_object({}) do |v, acc|
153 145
        value = binding.eval(v.to_s) unless v == :_

Also available in: Unified diff