Skip to content

Instantly share code, notes, and snippets.

@ttanimichi
Created February 27, 2020 08:24
Show Gist options
  • Save ttanimichi/148c00bb591e667af83ac6b2b74fac3e to your computer and use it in GitHub Desktop.
Save ttanimichi/148c00bb591e667af83ac6b2b74fac3e to your computer and use it in GitHub Desktop.
# Current.time = Time.current
# Current.user = User.find(42)
# MyAPIClient.new.analyze
class MyAPIClient
URL = 'http://api.example.com'
def analyze
response = Faraday.post(URL, body_hash.to_json, headers)
JSON.parse(response.body)
end
private
def headers
{ 'Content-Type' => 'application/json' }
end
def body_hash
{
timeStamp: Current.time.to_i,
userId: Current.user.id,
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment