GithubHelp home page GithubHelp logo

humanapi's Introduction

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:

class User<ActiveRecord::Base
	# Some attributes here
	
	def get_the_token
		# the code to reach the token
	end
end

Then you can do this:

class User<ActiveRecord::Base
	# Some attributes here
	
	humanizable :get_the_token
	
	def get_the_token
		# the code to reach the token
	end
end

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

Always remember to configure the initializer with the access keys:

HumanApi.config do |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.config do |c|
	c.app_id = "<YOUR_APP_ID>"
	c.query_key = "<YOUR_QUERY_KEY>"
	
	# This is the part where the magics happen
	c.human_model = User       # Tell me what is the model you want to use
	c.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 model
u = User.first
u.human.profile    #=> Will return the humanapi user's profile
u.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 activities
u.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 [email protected] or open an issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.