Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

45 Commits

Repository files navigation

HumanApi Gem Version

A Ruby client to HumanApi.

Installation

Add this line to your application's Gemfile:

gem'human_api'

Configuration

Let's say you have an User model as follows:

classUser<ActiveRecord::Base# Some attributes heredefget_the_token# the code to reach the tokenendend

Then you can do this:

classUser<ActiveRecord::Base# Some attributes herehumanizable:get_the_tokendefget_the_token# the code to reach the tokenendend

This configuration is really simple. I suggest it over the second one.

Always remember to configure the initializer with the access keys:

HumanApi.configdo |c|
c.app_id=ENV['HUMANAPI_KEY']c.query_key=ENV['HUMANAPI_SECRET']end

###The alternative If you don't like that configuration, you can use a different one, writing right into the initializer:

HumanApi.configdo |c|
c.app_id="<YOUR_APP_ID>"c.query_key="<YOUR_QUERY_KEY>"# This is the part where the magics happenc.human_model=User# Tell me what is the model you want to usec.token_method_name=:human_token# Tell me the method you use to retrieve the token (Inside the human_model)end

It should work in both ways, the choice is yours.

Usage

Once you did the configuration, the usage of the gem is quite ridiculous:

# Somewhere in your modelu=User.firstu.human.profile#=> Will return the humanapi user's profileu.human.query(:activities)#=> Will return everything you asked for

Just use the human instance method from your User instance and that's it ;)

###The query method The query method is meant to ask whatever you want whenever you want. Here are some permitted methods (according to humanapi) you can use to retrieve user's data:

:profile:activities:blood_glucose:blood_pressure:body_fat:genetic_traits:heart_rate:height:locations:sleeps:weight:bmi:sources:human

Mixin' up these methods with some options will give you what you want.

u.human.query(:activities,:summary=>true)#=> will give you a summary of the activitiesu.human.query(:sleeps,:date=>"2014-01-01")#=> Will give you a single sleep measurement# Getting KPIs (KPIs are just single values you get to retrieve a measurements average value)u.human.query(:weight)#=> Will give you a single weight value (The avg I guess)# Getting readings (If you begin with a single avg value and you wanna go deeper)u.human.query(:weight,:readings=>true)

Lastly, as a common rule, I've identified a pattern in humanapis.

  • If the method name is plural, it will give you multiple measurements when calling it. In addition, you can ask for a :summary => true, for a group of value in a specific :date => "DATE" or for a single known measurement :id => "measurement_id"
  • If the method name is singular, it will give you a single avg value for what you asked. In addition, you can ask for all :readings => true and for all readings => true in a specific :date=> "DATE".
  • If I'm missing something just send me a PM or open an issue.

Common errors and troubleshooting

###'rewrite_human_model': Could not find 'token' in User

  • Causes: it does mean that the method you suggested does not exist!
  • What to check: check if you misspelled the method name or the attribute does not exist.
  • Solving: if this does not solve, try using the humanizable function passing a method you can create in your model to retrieve manually just the token. Still having problems? Open an issue or contact us.

Contributing

Feel free to contribute with your pull requests and forks. Get in touch with us at dev@pazienti.it or open an issue.

About

This gem allows you to call HumanApi in RoR

Resources

Stars

3 stars

Watchers

7 watching

Forks

Releases

Packages

Used by

Contributors

Languages