lifeapi 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/lifeapi/errors.rb +3 -0
- data/lib/lifeapi/version.rb +3 -0
- data/lib/lifeapi.rb +256 -0
- metadata +103 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: eef06ab9eced09662cd1f6155f1665f2cd21cda7
|
|
4
|
+
data.tar.gz: 18141052e3e9e7d796da433fc0b51a92860d1aa7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 86e11399ea6a07e772029850999888bfd64367c0478ec17b0d8a356c73e9c8d81de0e85b2ac90df2c81e383371aafcdfc0695175005d0b31bd4e4ddcab4eebbb
|
|
7
|
+
data.tar.gz: b90b22e76ba71c03c30d9aab0eadb34bc87eb342fafd487a1991349f88b9f720efd0e246049945203af00caa4d317b93714baad1393aa7eb34769bcf8e5a97cf
|
data/lib/lifeapi.rb
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
require "lifeapi/version"
|
|
2
|
+
require "lifeapi/errors"
|
|
3
|
+
require 'httparty'
|
|
4
|
+
require 'json'
|
|
5
|
+
|
|
6
|
+
module Lifeapi
|
|
7
|
+
|
|
8
|
+
# contains a single day
|
|
9
|
+
# record_date: date the day was recorded (or logged)
|
|
10
|
+
# activites: array of activites that belong to the day
|
|
11
|
+
class Day
|
|
12
|
+
|
|
13
|
+
attr_accessor :record_date, :activities
|
|
14
|
+
|
|
15
|
+
def initialize(record_date, activities)
|
|
16
|
+
self.record_date = record_date
|
|
17
|
+
self.activities = Day.parse_activities(activities)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.parse_activities(activities)
|
|
21
|
+
activities_arr = []
|
|
22
|
+
activities.each do |a|
|
|
23
|
+
@a = Activity.new(a["self_type"], a["duration"])
|
|
24
|
+
activities_arr.push(@a)
|
|
25
|
+
end
|
|
26
|
+
return activities_arr
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# contains a single activity
|
|
32
|
+
# type: the type of activity (run, read, sleep, etc)
|
|
33
|
+
# duration: the duration of the activity in minutes
|
|
34
|
+
class Activity
|
|
35
|
+
|
|
36
|
+
attr_accessor :type, :duration
|
|
37
|
+
|
|
38
|
+
def initialize(type, duration)
|
|
39
|
+
self.type = type
|
|
40
|
+
self.duration = duration
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# contains a range of days, condensed
|
|
45
|
+
# start_date: date that the earliest day in range was recorded
|
|
46
|
+
# end_date: date that the latest day in range was recorded
|
|
47
|
+
# activities: array of activities that belongs to the range
|
|
48
|
+
class Range
|
|
49
|
+
attr_accessor :start_date, :end_date, :activities
|
|
50
|
+
|
|
51
|
+
def initialize(start_date, end_date, activities)
|
|
52
|
+
self.start_date = start_date
|
|
53
|
+
self.end_date = end_date
|
|
54
|
+
self.activities = Day.parse_activities(activities)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.parse_activities(activities)
|
|
58
|
+
activities_arr = []
|
|
59
|
+
activities.each do |a|
|
|
60
|
+
@a = Activity.new(a["self_type"], a["duration"])
|
|
61
|
+
activities_arr.push(@a)
|
|
62
|
+
end
|
|
63
|
+
return activities_arr
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# contains an activity and query time
|
|
68
|
+
# query_time: the time that was used in the query
|
|
69
|
+
# activity: the single activitiy that belongs to this query object
|
|
70
|
+
class Query
|
|
71
|
+
attr_accessor :query_time, :activity
|
|
72
|
+
|
|
73
|
+
def initialize(query_time, activity)
|
|
74
|
+
self.query_time = query_time
|
|
75
|
+
self.activity = Query_activity.new(activity["self_type"], activity["duration"], activity["start_time"], activity["end_time"])
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# contains a single query activity
|
|
80
|
+
# needs its own class over regular Activity because it has more info
|
|
81
|
+
# type: the type of activity (run, read, sleep, etc)
|
|
82
|
+
# duration: the duration of the activity in minutes
|
|
83
|
+
# start_time: the time (in 24 hr clock) when the activity was started
|
|
84
|
+
# end_time: the time (in 24 hr clock) when the activity was ended
|
|
85
|
+
class Query_activity
|
|
86
|
+
|
|
87
|
+
attr_accessor :type, :duration, :start_time, :end_time
|
|
88
|
+
|
|
89
|
+
def initialize(type, duration, start_time, end_time)
|
|
90
|
+
self.type = type
|
|
91
|
+
self.duration = duration
|
|
92
|
+
self.start_time = Time.parse(start_time)
|
|
93
|
+
self.end_time = Time.parse(end_time)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# returns a single day object
|
|
98
|
+
# year: the year to be searched
|
|
99
|
+
# month: the month to be searched
|
|
100
|
+
# day: the day to be searched
|
|
101
|
+
def self.get_one_day(year, month, day)
|
|
102
|
+
@year = year
|
|
103
|
+
@month = month
|
|
104
|
+
@day = day
|
|
105
|
+
json_data = HTTParty.get("https://jack-lifeapi.herokuapp.com/v1/days/single",
|
|
106
|
+
:headers => {"year" => "#{@year}", "month" => "#{@month}", "day" => "#{@day}"})
|
|
107
|
+
|
|
108
|
+
#if the params are bad
|
|
109
|
+
if json_data.code == 400
|
|
110
|
+
raise Errors::BadParamsError
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
data = JSON.parse(json_data.to_json)
|
|
114
|
+
|
|
115
|
+
day = Day.new(data["record_date"],data["activities"])
|
|
116
|
+
|
|
117
|
+
return day
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# returns a range object (with condensed days)
|
|
121
|
+
# year1: the year to be used for the first start date
|
|
122
|
+
# month1: the month to be used for the first start date
|
|
123
|
+
# day1: the day to be used for the first start date
|
|
124
|
+
# year2: the year to be used for second the start date
|
|
125
|
+
# month2: the month to be used for second the start date
|
|
126
|
+
# day2: the day to be used for the second start date
|
|
127
|
+
def self.get_range_of_days_condensed(year1, month1, day1, year2, month2, day2)
|
|
128
|
+
@year1 = year1
|
|
129
|
+
@month1 = month1
|
|
130
|
+
@day1 = day1
|
|
131
|
+
@year2 = year2
|
|
132
|
+
@month2 = month2
|
|
133
|
+
@day2 = day2
|
|
134
|
+
@condense = true
|
|
135
|
+
|
|
136
|
+
json_data = HTTParty.get("https://jack-lifeapi.herokuapp.com/v1/days/range",
|
|
137
|
+
:headers => {"year1" => "#{@year1}", "month1" => "#{@month1}", "day1" => "#{@day1}", "year2" => "#{@year2}", "month2" => "#{@month2}", "day2" => "#{@day2}", "condense" => "#{@condense}"})
|
|
138
|
+
|
|
139
|
+
#if the params are bad
|
|
140
|
+
if json_data.code == 400
|
|
141
|
+
raise Errors::BadParamsError
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
data = JSON.parse(json_data.to_json)
|
|
145
|
+
|
|
146
|
+
day = Range.new(data["start_date"], data["end_date"], data["activities"])
|
|
147
|
+
|
|
148
|
+
return day
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# returns an array of days (uncondensed)
|
|
152
|
+
# year1: the year to be used for the first start date
|
|
153
|
+
# month1: the month to be used for the first start date
|
|
154
|
+
# day1: the day to be used for the first start date
|
|
155
|
+
# year2: the year to be used for second the start date
|
|
156
|
+
# month2: the month to be used for second the start date
|
|
157
|
+
# day2: the day to be used for the second start date
|
|
158
|
+
def self.get_range_of_days(year1, month1, day1, year2, month2, day2)
|
|
159
|
+
@year1 = year1
|
|
160
|
+
@month1 = month1
|
|
161
|
+
@day1 = day1
|
|
162
|
+
@year2 = year2
|
|
163
|
+
@month2 = month2
|
|
164
|
+
@day2 = day2
|
|
165
|
+
@condense = false
|
|
166
|
+
|
|
167
|
+
json_data = HTTParty.get("https://jack-lifeapi.herokuapp.com/v1/days/range",
|
|
168
|
+
:headers => {"year1" => "#{@year1}", "month1" => "#{@month1}", "day1" => "#{@day1}", "year2" => "#{@year2}", "month2" => "#{@month2}", "day2" => "#{@day2}", "condense" => "#{@condense}"})
|
|
169
|
+
|
|
170
|
+
#if the params are bad
|
|
171
|
+
if json_data.code == 400
|
|
172
|
+
raise Errors::BadParamsError
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
data = JSON.parse(json_data.to_json)
|
|
176
|
+
|
|
177
|
+
#day = Range.new(data["start_date"], data["end_date"], data["activities"])
|
|
178
|
+
@day_array = []
|
|
179
|
+
data.each do |d|
|
|
180
|
+
@day = Day.new(d["record_date"], d["activities"])
|
|
181
|
+
@day_array += [@day]
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
return @day_array
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
# returns the whole summer, in condensed format
|
|
188
|
+
def self.get_whole_summer_condensed()
|
|
189
|
+
json_data = HTTParty.get("https://jack-lifeapi.herokuapp.com/v1/days/all_time",
|
|
190
|
+
:headers => {"condense" => "true"})
|
|
191
|
+
|
|
192
|
+
#if the params are bad
|
|
193
|
+
if json_data.code == 400
|
|
194
|
+
raise Errors::BadParamsError
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
data = JSON.parse(json_data.to_json)
|
|
198
|
+
|
|
199
|
+
day = Range.new(data["start_date"], data["end_date"], data["activities"])
|
|
200
|
+
|
|
201
|
+
return day
|
|
202
|
+
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
# returns the whole summer as an array of days, in uncondensed format
|
|
206
|
+
def self.get_whole_summer()
|
|
207
|
+
json_data = HTTParty.get("https://jack-lifeapi.herokuapp.com/v1/days/all_time",
|
|
208
|
+
:headers => {"condense" => "false"})
|
|
209
|
+
|
|
210
|
+
#if the params are bad
|
|
211
|
+
if json_data.code == 400
|
|
212
|
+
raise Errors::BadParamsError
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
data = JSON.parse(json_data.to_json)
|
|
216
|
+
|
|
217
|
+
#day = Range.new(data["start_date"], data["end_date"], data["activities"])
|
|
218
|
+
@day_array = []
|
|
219
|
+
data.each do |d|
|
|
220
|
+
@day = Day.new(d["record_date"], d["activities"])
|
|
221
|
+
@day_array += [@day]
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
return @day_array
|
|
225
|
+
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
# queries to find the activity that was done at a specific time
|
|
229
|
+
# month: the month to be searched
|
|
230
|
+
# day: the day to be searched
|
|
231
|
+
# hour: the hour to be searched
|
|
232
|
+
# minute: the minute to be searched
|
|
233
|
+
def self.query(month, day, hour, minute)
|
|
234
|
+
@year = 2016 # year is hardcoded right now because i dont track anything outside of 2016
|
|
235
|
+
@month = month
|
|
236
|
+
@day = day
|
|
237
|
+
@hour = hour
|
|
238
|
+
@minute = minute
|
|
239
|
+
|
|
240
|
+
json_data = HTTParty.get("https://jack-lifeapi.herokuapp.com/v1/days/query",
|
|
241
|
+
:headers => {"year" => "#{@year}", "month" => "#{@month}", "day" => "#{@day}", "hour" => "#{@hour}", "minute" => "#{@minute}"})
|
|
242
|
+
|
|
243
|
+
#if the params are bad
|
|
244
|
+
if json_data.code == 400
|
|
245
|
+
raise Errors::BadParamsError
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
data = JSON.parse(json_data.to_json)
|
|
249
|
+
|
|
250
|
+
#day = Range.new(data["start_date"], data["end_date"], data["activities"])
|
|
251
|
+
query = Query.new(data["query_time"], data["activity"])
|
|
252
|
+
|
|
253
|
+
return query
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: lifeapi
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.10
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- jack rometty
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-05-04 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.11'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.11'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: httparty
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 0.13.7
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 0.13.7
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: json
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '1.8'
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '1.8'
|
|
69
|
+
description: gem for the jack rometty life api.
|
|
70
|
+
email:
|
|
71
|
+
- Jwrometty@gmail.com
|
|
72
|
+
executables: []
|
|
73
|
+
extensions: []
|
|
74
|
+
extra_rdoc_files: []
|
|
75
|
+
files:
|
|
76
|
+
- lib/lifeapi.rb
|
|
77
|
+
- lib/lifeapi/errors.rb
|
|
78
|
+
- lib/lifeapi/version.rb
|
|
79
|
+
homepage: http://www.jackrometty.com
|
|
80
|
+
licenses:
|
|
81
|
+
- MIT
|
|
82
|
+
metadata: {}
|
|
83
|
+
post_install_message:
|
|
84
|
+
rdoc_options: []
|
|
85
|
+
require_paths:
|
|
86
|
+
- lib
|
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
|
+
requirements:
|
|
89
|
+
- - ">="
|
|
90
|
+
- !ruby/object:Gem::Version
|
|
91
|
+
version: '0'
|
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
requirements: []
|
|
98
|
+
rubyforge_project:
|
|
99
|
+
rubygems_version: 2.6.2
|
|
100
|
+
signing_key:
|
|
101
|
+
specification_version: 4
|
|
102
|
+
summary: gem for the jack rometty life api
|
|
103
|
+
test_files: []
|