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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a6cb0060e8a7c0d3ec9e4d79fdcdf4b5c101cdc
4
- data.tar.gz: 6477af6b9a515d46c4ffb694d047b29af03a0257
3
+ metadata.gz: a6ab6c2cd49330c1ef7ef58c6745a0aebfcf4189
4
+ data.tar.gz: f2720245384449386a078641d576913bb2650981
5
5
  SHA512:
6
- metadata.gz: c98f1172de428f932d2b35764b69232407696782c1954d89e91c79f6eff43efe00c57b2e7d5ac6fa62bb6db18196b3ca5336b1a06163c9e164e2fd03285a58a3
7
- data.tar.gz: 2cf4e4a6426cf4f6aebaaccb55755b771255dd664ab75e457b967b31d21a1194946f7016424539301663f5e14f50d97b1dc8f6cd816d753694aab5a41e52c17b
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
- # We're going to publish our gem soon...
10
- gem 'human_api', :git => 'git://github.com/Pazienti/humanapi.git'
11
-
7
+ ```ruby
8
+ gem 'human_api'
9
+ ```
12
10
  ## Configuration
13
- The gem is quite simple to configure. You can configure the gem using its home-made initializer:
14
-
15
- HumanApi.config do |c|
16
- c.app_id = "<YOUR_APP_ID>"
17
- c.query_key = "<YOUR_QUERY_KEY>"
18
-
19
- # This is the part where the magics happen
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
- # Somewhere in your model
28
- u = User.first
29
- u.human.profile #=> Will return the humanapi user's profile
30
- u.human.query(:activities) #=> Will return everything you asked for
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
- profile
38
- activities
39
- blood_glucose
40
- blood_pressure
41
- body_fat
42
- genetic_traits
43
- heart_rate
44
- height
45
- locations
46
- sleeps
47
- weight
48
- bmi
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
- u.human.query(:activities, :summary => true) #=> will give you a summary of the activities
53
- u.human.query(:sleeps, :date => "2014-01-01") #=> Will give you a single sleep measurement
54
-
55
- # Getting KPIs (KPIs are just single values you get to retrieve a measurements average value)
56
- u.human.query(:weight) #=> Will give you a single weight value (The avg I guess)
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 team@pazienti.it or open an issue.
109
+ Feel free to contribute with your pull requests and forks. Get in touch with us at dev@pazienti.it or open an issue.
@@ -25,7 +25,9 @@ module HumanApi
25
25
  :locations,
26
26
  :sleeps,
27
27
  :weight,
28
- :bmi
28
+ :bmi,
29
+ :sources,
30
+ :human
29
31
  ]
30
32
 
31
33
  def initialize(options)
@@ -1,3 +1,3 @@
1
1
  module HumanApi
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
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.6
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-02-16 00:00:00.000000000 Z
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.2.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: