human_api 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +85 -51
- data/lib/human_api/human.rb +3 -1
- data/lib/human_api/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6ab6c2cd49330c1ef7ef58c6745a0aebfcf4189
|
4
|
+
data.tar.gz: f2720245384449386a078641d576913bb2650981
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6943708f160360c960e2d692513a16dee483dac9513d549c01e8ae0e5652fb9a6ee85f518e1b441f882acba124737b5357d89d71639c6083be87762aa06d9d06
|
7
|
+
data.tar.gz: c3423fb32e4c35db07695c941c0438018e36cb4f890661995007591cf41d122fb3132359da4e6ec9d5254e2c7610f075e3ff9716e36761cc9e598f39dfcdaede
|
data/README.md
CHANGED
@@ -1,75 +1,109 @@
|
|
1
|
-
# HumanApi
|
2
|
-
|
1
|
+
# HumanApi [![Gem Version](https://badge.fury.io/rb/human_api.png)](http://badge.fury.io/rb/human_api)
|
3
2
|
A Ruby client to [HumanApi](http://humanapi.co).
|
4
3
|
|
5
4
|
## Installation
|
6
5
|
|
7
6
|
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
```ruby
|
8
|
+
gem 'human_api'
|
9
|
+
```
|
12
10
|
## Configuration
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
#
|
20
|
-
c.human_model = User # Tell me what is the model you want to use
|
21
|
-
c.token_method_name = :human_token # Tell me the method you use to retrieve the token (Inside the human_model)
|
11
|
+
Let's say you have an User model as follows:
|
12
|
+
```ruby
|
13
|
+
class User<ActiveRecord::Base
|
14
|
+
# Some attributes here
|
15
|
+
|
16
|
+
def get_the_token
|
17
|
+
# the code to reach the token
|
22
18
|
end
|
19
|
+
end
|
20
|
+
```
|
21
|
+
Then you can do this:
|
22
|
+
```ruby
|
23
|
+
class User<ActiveRecord::Base
|
24
|
+
# Some attributes here
|
25
|
+
|
26
|
+
humanizable :get_the_token
|
27
|
+
|
28
|
+
def get_the_token
|
29
|
+
# the code to reach the token
|
30
|
+
end
|
31
|
+
end
|
32
|
+
```
|
33
|
+
This configuration is really simple. I suggest it over the second one.
|
34
|
+
|
35
|
+
Always remember to configure the initializer with the access keys:
|
36
|
+
```ruby
|
37
|
+
HumanApi.config do |c|
|
38
|
+
c.app_id = ENV['HUMANAPI_KEY']
|
39
|
+
c.query_key = ENV['HUMANAPI_SECRET']
|
40
|
+
end
|
41
|
+
```
|
42
|
+
###The alternative
|
43
|
+
If you don't like that configuration, you can use a different one, writing right into the initializer:
|
44
|
+
```ruby
|
45
|
+
HumanApi.config do |c|
|
46
|
+
c.app_id = "<YOUR_APP_ID>"
|
47
|
+
c.query_key = "<YOUR_QUERY_KEY>"
|
48
|
+
|
49
|
+
# This is the part where the magics happen
|
50
|
+
c.human_model = User # Tell me what is the model you want to use
|
51
|
+
c.token_method_name = :human_token # Tell me the method you use to retrieve the token (Inside the human_model)
|
52
|
+
end
|
53
|
+
```
|
54
|
+
It should work in both ways, the choice is yours.
|
23
55
|
|
24
56
|
## Usage
|
25
57
|
Once you did the configuration, the usage of the gem is quite ridiculous:
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
58
|
+
```ruby
|
59
|
+
# Somewhere in your model
|
60
|
+
u = User.first
|
61
|
+
u.human.profile #=> Will return the humanapi user's profile
|
62
|
+
u.human.query(:activities) #=> Will return everything you asked for
|
63
|
+
```
|
32
64
|
Just use the _human_ instance method from your User instance and that's it ;)
|
33
65
|
|
34
66
|
###The query method
|
35
67
|
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:
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
68
|
+
```ruby
|
69
|
+
:profile
|
70
|
+
:activities
|
71
|
+
:blood_glucose
|
72
|
+
:blood_pressure
|
73
|
+
:body_fat
|
74
|
+
:genetic_traits
|
75
|
+
:heart_rate
|
76
|
+
:height
|
77
|
+
:locations
|
78
|
+
:sleeps
|
79
|
+
:weight
|
80
|
+
:bmi
|
81
|
+
:sources
|
82
|
+
:human
|
83
|
+
```
|
50
84
|
Mixin' up these methods with some options will give you what you want.
|
85
|
+
```ruby
|
86
|
+
u.human.query(:activities, :summary => true) #=> will give you a summary of the activities
|
87
|
+
u.human.query(:sleeps, :date => "2014-01-01") #=> Will give you a single sleep measurement
|
51
88
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
# Getting readings (If you begin with a single avg value and you wanna go deeper)
|
59
|
-
u.human.query(:weight, :readings => true)
|
60
|
-
|
89
|
+
# Getting KPIs (KPIs are just single values you get to retrieve a measurements average value)
|
90
|
+
u.human.query(:weight) #=> Will give you a single weight value (The avg I guess)
|
91
|
+
|
92
|
+
# Getting readings (If you begin with a single avg value and you wanna go deeper)
|
93
|
+
u.human.query(:weight, :readings => true)
|
94
|
+
```
|
61
95
|
Lastly, as a common rule, I've identified a pattern in humanapis.
|
62
96
|
- 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"
|
63
97
|
- 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".
|
64
98
|
- If I'm missing something just send me a PM or open an issue.
|
65
99
|
|
100
|
+
## Common errors and troubleshooting
|
101
|
+
###'rewrite_human_model': Could not find 'token' in User
|
102
|
+
- Causes: it does mean that the method you suggested does not exist!
|
103
|
+
- What to check: check if you misspelled the method name or the attribute does not exist.
|
104
|
+
- 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.
|
105
|
+
Still having problems? Open an issue or contact us.
|
66
106
|
|
67
|
-
###The alternative
|
68
|
-
If you don't like that configuration, you can use a simple method right in your own user model:
|
69
|
-
|
70
|
-
humanizable :token_method
|
71
|
-
|
72
|
-
That's it! Then you can do something like _u.human.profile_ like I said before.
|
73
107
|
|
74
108
|
## Contributing
|
75
|
-
Feel free to contribute with your pull requests and forks. Get in touch with us at
|
109
|
+
Feel free to contribute with your pull requests and forks. Get in touch with us at dev@pazienti.it or open an issue.
|
data/lib/human_api/human.rb
CHANGED
data/lib/human_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: human_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessio Santo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nestful
|
@@ -105,8 +105,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
105
|
version: '0'
|
106
106
|
requirements: []
|
107
107
|
rubyforge_project:
|
108
|
-
rubygems_version: 2.
|
108
|
+
rubygems_version: 2.0.6
|
109
109
|
signing_key:
|
110
110
|
specification_version: 4
|
111
111
|
summary: API client for HumanAPI
|
112
112
|
test_files: []
|
113
|
+
has_rdoc:
|