misfit_activity 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +2 -0
- data/lib/misfit_activity.rb +134 -0
- data/lib/misfit_activity/version.rb +3 -0
- data/misfit_activity.gemspec +23 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f4c924dc9746cf3e82ddc0186da9757ffab484cd
|
4
|
+
data.tar.gz: d47c3c112f5e61f7fc240a5e7d565f1736406309
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 18437cf44c0a9642ad27c650c304fba04cb7f0153408e0a0d03160a939012a2cf9864e8fa5d04369b9a5305d85d6ccbdfb2aec3f3a1af2098f107b0066c628dd
|
7
|
+
data.tar.gz: 634c572ffc94c040088916ff00d4ae53341d94db2b8ae4b8807d4285839fa48e2d0eac7fbdf830d358908eb745cc6410ba52dc34a4fecc53571f7d2abcb10a8c
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 John Contreras
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# MisfitActivity
|
2
|
+
|
3
|
+
A simple ruby api gem to pull misfit activity data.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'misfit_activity'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install misfit_activity
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
# initialize a new MisfitActivity::Client passing the users token
|
23
|
+
client = MisfitActivity::Client.new(token)
|
24
|
+
|
25
|
+
# pull profile information
|
26
|
+
client.profile
|
27
|
+
|
28
|
+
# pull device information
|
29
|
+
client.device
|
30
|
+
|
31
|
+
# pull activity for one specific date
|
32
|
+
client.activity_on_date(Date.today)
|
33
|
+
|
34
|
+
# pull activity for a date range
|
35
|
+
client.activities_in_range("2014-08-01", "2014-08-15")
|
36
|
+
|
37
|
+
```
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it ( https://github.com/[my-github-username]/misfit_activity/fork )
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
require "misfit_activity/version"
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
module MisfitActivity
|
5
|
+
|
6
|
+
class Client
|
7
|
+
attr_accessor :token
|
8
|
+
BASE_URL = "https://api.misfitwearables.com/move/resource/v1/"
|
9
|
+
|
10
|
+
include HTTParty
|
11
|
+
|
12
|
+
def initialize(token)
|
13
|
+
@token = token
|
14
|
+
end
|
15
|
+
|
16
|
+
def profile
|
17
|
+
resource_path = "user/me/profile"
|
18
|
+
url = BASE_URL + resource_path
|
19
|
+
|
20
|
+
response = HTTParty.get(url, headers: get_auth_header)
|
21
|
+
|
22
|
+
if response.code != 200
|
23
|
+
return wrap_error(response)
|
24
|
+
else
|
25
|
+
profile = {
|
26
|
+
user_id: response.parsed_response["userId"],
|
27
|
+
name: response.parsed_response["name"],
|
28
|
+
email: response.parsed_response["email"],
|
29
|
+
gender: response.parsed_response["gender"],
|
30
|
+
birthday: response.parsed_response["birthday"]
|
31
|
+
}
|
32
|
+
|
33
|
+
return wrap_response(profile, response)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def device
|
38
|
+
resource_path = "user/me/device"
|
39
|
+
url = BASE_URL + resource_path
|
40
|
+
|
41
|
+
response = HTTParty.get(url, headers: get_auth_header)
|
42
|
+
|
43
|
+
if response.code != 200
|
44
|
+
return wrap_error(response)
|
45
|
+
else
|
46
|
+
device = {
|
47
|
+
device_type: response.parsed_response["deviceType"],
|
48
|
+
battery_level: response.parsed_response["batteryLevel"]
|
49
|
+
}
|
50
|
+
|
51
|
+
return wrap_response(device, response)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def activity_on_date(date)
|
57
|
+
response = get_activities(date, date)
|
58
|
+
|
59
|
+
return parse_activities(response, date, date)
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def activities_in_range(start_date, end_date)
|
64
|
+
response = get_activities(start_date, end_date)
|
65
|
+
|
66
|
+
return parse_activities(response, start_date, end_date)
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
# private
|
72
|
+
def get_auth_header
|
73
|
+
{ 'Authorization' => "Bearer #{self.token}" }
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
def get_activities(start_date, end_date)
|
78
|
+
resource_path = "user/me/activity/summary"
|
79
|
+
url = BASE_URL + resource_path
|
80
|
+
|
81
|
+
query = {
|
82
|
+
start_date: start_date,
|
83
|
+
end_date: end_date,
|
84
|
+
detail: true
|
85
|
+
}
|
86
|
+
|
87
|
+
return HTTParty.get(url, query: query, headers: get_auth_header)
|
88
|
+
end
|
89
|
+
|
90
|
+
def parse_activities(response, start_date, end_date)
|
91
|
+
if response.code != 200
|
92
|
+
return wrap_error(response)
|
93
|
+
end
|
94
|
+
|
95
|
+
results = []
|
96
|
+
activities = response.parsed_response["summary"]
|
97
|
+
|
98
|
+
(start_date..end_date).each do |date|
|
99
|
+
result = (activities || []).find{ |r| r["date"] == date.to_s } || {}
|
100
|
+
|
101
|
+
activity = {
|
102
|
+
date: date,
|
103
|
+
steps: result["steps"] || 0,
|
104
|
+
distance: result["distance"] || 0,
|
105
|
+
calories: result["calories"] || 0
|
106
|
+
}
|
107
|
+
|
108
|
+
results.push(activity)
|
109
|
+
end
|
110
|
+
|
111
|
+
return wrap_response(results, response)
|
112
|
+
end
|
113
|
+
|
114
|
+
def wrap_response(result, response)
|
115
|
+
{
|
116
|
+
status_code: response.code,
|
117
|
+
message: "success",
|
118
|
+
data: result,
|
119
|
+
raw: response
|
120
|
+
}
|
121
|
+
end
|
122
|
+
|
123
|
+
def wrap_error(response)
|
124
|
+
{
|
125
|
+
status_code: response.code,
|
126
|
+
message: response.parsed_response["message"],
|
127
|
+
data: [],
|
128
|
+
raw: response
|
129
|
+
}
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'misfit_activity/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "misfit_activity"
|
8
|
+
spec.version = MisfitActivity::VERSION
|
9
|
+
spec.authors = ["John Contreras"]
|
10
|
+
spec.email = ["contrerasnet@gmail.com"]
|
11
|
+
spec.summary = %q{Misfit api client for activities.}
|
12
|
+
spec.description = %q{Misfit api client for activities only, profile, device and activities by date/range.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: misfit_activity
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Contreras
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Misfit api client for activities only, profile, device and activities
|
42
|
+
by date/range.
|
43
|
+
email:
|
44
|
+
- contrerasnet@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- lib/misfit_activity.rb
|
55
|
+
- lib/misfit_activity/version.rb
|
56
|
+
- misfit_activity.gemspec
|
57
|
+
homepage: ''
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.2.2
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Misfit api client for activities.
|
81
|
+
test_files: []
|