Skip to content

Instantly share code, notes, and snippets.

@luizbafilho
Last active May 8, 2016 04:08
Show Gist options
  • Save luizbafilho/deed1016dfc1019248215c4ecd09f07a to your computer and use it in GitHub Desktop.
Save luizbafilho/deed1016dfc1019248215c4ecd09f07a to your computer and use it in GitHub Desktop.
module Request
[:get, :post, :put, :delete].each do |verb|
define_method verb do |url, payload: {}, headers: {}|
headers = define_headers(headers)
execute(verb, url, payload, headers)
end
end
def define_headers(headers)
default_headers = {
'Authorization' => "Bearer token",
'Accept' => 'application/json'
}
default_headers.merge(headers)
end
private
def execute(method, url, payload, headers)
RestClient::Request.execute(method: method, url: url, payload: payload, headers: headers)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment