Skip to content

Instantly share code, notes, and snippets.

@apeiros
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apeiros/9230947 to your computer and use it in GitHub Desktop.
Save apeiros/9230947 to your computer and use it in GitHub Desktop.
def invoke(verb, path, expected_code, additional_params=nil)
if additional_params
response = RestClient.public_send(verb, restclient_uri(path), additional_params.to_json, core_params(verb))
else
response = RestClient.public_send(verb, restclient_uri(path), core_params(verb))
end
rescue RestClient::Exception => e
e
rescue
response
else
response.code == expected_code ? JSON.parse(response.to_str) : nil
end
def get(path)
invoke(:get, path, 200)
end
def post(path, params)
invoke(:post, path, 201, params)
end
def put(path, params)
invoke(:put, path, 201, params)
end
def delete(path)
invoke(:delete, path, 204)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment