ihealth_bot 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 68f7f1a4d18bec5de0ca4e61cbc78e12b617ab66
4
+ data.tar.gz: a56935c0cbfe9d0d5bc45cd9e4f5ce13328173af
5
+ SHA512:
6
+ metadata.gz: b92f2ab2fa468c5143a975d1a72da6873ddc5770b9a9c17f8a506a61a0155f5c46c5120f5afa66813e0f949341420abf217467c41b2e2627a53e30da3414b2c4
7
+ data.tar.gz: 41dae5ae1ccd076e78d918715103611556da0a1a4cc3e9fa3525355e17fc0223cb4a022b4ef3f1767d770154260964ba417d894c7b2187f98a16f84597f2ddef
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Josh Haywood
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ #iHealthBot
2
+
3
+ iHealthBot is an automated tool to create iHealth data for several endpoints. Just install the gem, configure your iHealth credentials, and create data.
4
+
5
+ ##Installation
6
+
7
+ ```sh
8
+ $ gem install ihealth_bot
9
+ ```
10
+
11
+ iHealthBot uses the [capybara-webkit driver](https://github.com/thoughtbot/capybara-webkit), so you'll need to install Qt as well.
12
+
13
+ ```sh
14
+ $ brew install qt55
15
+ ```
16
+
17
+ ##Configuration
18
+
19
+ You need to configure iHealthBot with your iHealth credentials before creating data. You can do that with
20
+
21
+ ```sh
22
+ $ ihealth_bot config --email your.email@example.com --password pASsW0Rd
23
+ ```
24
+
25
+ or create it directly in `~/.ihealth_bot`
26
+
27
+ ```javascript
28
+ {
29
+ "credentials": {
30
+ "email": "your.email@example.com",
31
+ "password": "pASsW0Rd"
32
+ }
33
+ }
34
+ ```
35
+
36
+ ##Usage
37
+
38
+ Currently iHealthBot supports creating data for the following endpoints
39
+
40
+ * Activities
41
+ * Blood Glucose
42
+ * Blood Pressure
43
+ * Food
44
+ * Weight
45
+
46
+ To create data
47
+
48
+ ```sh
49
+ $ ihealth_bot create
50
+ ```
51
+
52
+ At the moment, data creation is only enabled for bulk creates meaning you can't create data for a specific endpoint. I'm hoping to enable single endpoint creation in the future.
data/bin/ihealth_bot ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'thor'
5
+ require 'json'
6
+
7
+ class Bot < Thor
8
+ desc 'create', 'Creates iHealth Data'
9
+ def create
10
+ require_relative '../lib/ihealth_bot/config.rb'
11
+
12
+ unless IhealthBot::Config.valid?
13
+ puts 'Invalid or missing config file!'
14
+ puts 'Create one with `ihealth_bot config -e email@example.com -p pA$sW0Rd`'
15
+ return
16
+ end
17
+
18
+ require 'capybara'
19
+ require 'capybara/dsl'
20
+ require 'capybara-webkit'
21
+
22
+ Capybara.default_driver = :webkit
23
+ Capybara.javascript_driver = :webkit
24
+ Capybara.default_max_wait_time = 10
25
+ Capybara.app_host = 'https://cloud.ihealthlabs.com'
26
+
27
+ require_relative '../lib/ihealth_bot.rb'
28
+
29
+ IhealthBot.create_data
30
+ end
31
+
32
+ desc 'config', 'Configure iHealth Bot Credentials'
33
+ method_option :email, type: :string, aliases: '-e', desc: 'iHealth account email address'
34
+ method_option :password, type: :string, alias: '-p', desc: 'iHealth account password'
35
+ def config
36
+ File.open("#{Dir.home}/.ihealth_bot", 'w+') do |f|
37
+ config = JSON.parse(f.read, symbolize_names: true) rescue { credentials: {} }
38
+ config[:credentials][:email] = options[:email] if options[:email]
39
+ config[:credentials][:password] = options[:password] if options[:password]
40
+ f.write(JSON.dump(config))
41
+ end
42
+ end
43
+ end
44
+
45
+ Bot.start
@@ -0,0 +1,24 @@
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
+ require 'ihealth_bot/version'
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'ihealth_bot'
6
+ gem.version = IhealthBot::VERSION
7
+ gem.date = '2016-11-29'
8
+
9
+ gem.authors = ["Josh Haywood"]
10
+ gem.email = 'josh.haywood@gmail.com'
11
+ gem.homepage = 'https://github.com/johaywood/ihealth_bot'
12
+ gem.summary = "Create iHealth data"
13
+ gem.description = "Automagically create iHealth data via the user portal. Useful for testing."
14
+ gem.license = 'MIT'
15
+
16
+ gem.files = `git ls-files -z`.split("\x0")
17
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+
19
+ gem.required_ruby_version = '~> 2.3'
20
+
21
+ gem.add_dependency 'capybara', '2.10.1'
22
+ gem.add_dependency 'capybara-webkit', '1.1.0'
23
+ gem.add_dependency 'thor', '0.19.4'
24
+ end
@@ -0,0 +1,28 @@
1
+ module IhealthBot
2
+ class Config
3
+ def self.email
4
+ config_file.dig(:credentials, :email)
5
+ end
6
+
7
+ def self.password
8
+ config_file.dig(:credentials, :password)
9
+ end
10
+
11
+ def self.valid?
12
+ return false unless File.exist?("#{Dir.home}/.ihealth_bot")
13
+ File.open("#{Dir.home}/.ihealth_bot", 'r') do |f|
14
+ return false unless data = JSON.parse(f.read, symbolize_names: true) rescue nil
15
+ return false unless data[:credentials]
16
+ return false unless data[:credentials][:email]
17
+ return false unless data[:credentials][:password]
18
+ end
19
+ true
20
+ end
21
+
22
+ private
23
+
24
+ def self.config_file
25
+ @config ||= JSON.parse(File.read("#{Dir.home}/.ihealth_bot"), symbolize_names: true)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,370 @@
1
+ module IhealthBot
2
+ module Endpoints
3
+ class Activities < Base
4
+ def self.create
5
+ super('Activities') do
6
+ category = ACTIVITY_CATEGORIES.sample
7
+ find('#txtSportsNamebyList').set(category)
8
+ find(:xpath, AUTOCOMPLETE_XPATH).click
9
+ end
10
+ end
11
+
12
+ ACTIVITY_CATEGORIES = [
13
+ 'Aerobics, high impact',
14
+ 'Aerobics, low impact',
15
+ 'Aerobics, moderate impact',
16
+ 'American Indian Dancing, traditional',
17
+ 'Animal Care, bathing dog',
18
+ 'Archery, stationary target',
19
+ 'Automobile, repair',
20
+ 'Badminton, competitive',
21
+ 'Badminton, social',
22
+ 'Baseball',
23
+ 'Baseball - general',
24
+ 'basketball-non-game',
25
+ 'Basketball, game',
26
+ 'Basketball, nongame, general',
27
+ 'Basketball, officiating',
28
+ 'Basketball, playing in wheelchair',
29
+ 'Basketball, shooting baskets',
30
+ 'bicycling-general',
31
+ 'Bicycling, >20 mph, racing',
32
+ 'Bicycling, 10-12 mph (light)',
33
+ 'Bicycling, 12-14 mph (moderate)',
34
+ 'Bicycling, 14-16 mph (vigorous)',
35
+ 'Bicycling, 16-19 mph, racing',
36
+ 'Bicycling, BMX or mountain',
37
+ 'Bicycling, under 10mph (leisure)',
38
+ 'Bicycling, Unicycling',
39
+ 'Bike-stationary, general',
40
+ 'Bike-stationary, light',
41
+ 'Bike-stationary, vigorous',
42
+ 'Bowling, inside',
43
+ 'Boxing, in ring, general',
44
+ 'Boxing, punching bag',
45
+ 'Boxing, sparring',
46
+ 'Broomball',
47
+ 'Calisthenics, light or moderate',
48
+ 'Calisthenics, vigorous',
49
+ 'Canoeing, on camping trip',
50
+ 'Canoeing, rowing, >6 mph, vigorous effort',
51
+ 'Canoeing, rowing, light effort',
52
+ 'Canoeing, rowing, moderate effort',
53
+ 'Canoeing, rowing,crewing, competition',
54
+ 'Card playing',
55
+ 'Carpentry, general',
56
+ 'Circuit Training',
57
+ 'Cleaning, heavy, vigorous effect',
58
+ 'Cleaning,light, moderate effect',
59
+ 'Climbing, ladder',
60
+ 'Coahing Sports',
61
+ 'Cricket',
62
+ 'Croquet',
63
+ 'Curling',
64
+ 'Dancing - general',
65
+ 'Dancing, 19th Century',
66
+ 'Dancing, Aerobic, general',
67
+ 'Dancing, Aerobic, high impact',
68
+ 'Dancing, Aerobic, low impact',
69
+ 'Dancing, Aerobic, step, with 6-8 inch step',
70
+ 'Dancing, Ballet or modern',
71
+ 'Dancing, ballroom, fast',
72
+ 'Dancing, ballroom, slow',
73
+ 'Dancing, belly',
74
+ 'Dancing, chacha',
75
+ 'Dancing, country',
76
+ 'Dancing, disco',
77
+ 'Dancing, flamenco',
78
+ 'Dancing, folk',
79
+ 'Dancing, foxtrot',
80
+ 'Dancing, general',
81
+ 'Dancing, greek',
82
+ 'Dancing, hula',
83
+ 'Dancing, irish step',
84
+ 'Dancing, jazz',
85
+ 'Dancing, jitterbug',
86
+ 'Dancing, line dancing',
87
+ 'Dancing, mambo',
88
+ 'Dancing, Middle Eastern',
89
+ 'Dancing, polka',
90
+ 'Dancing, samba',
91
+ 'Dancing, square',
92
+ 'Dancing, step',
93
+ 'Dancing, swing',
94
+ 'Dancing, tango',
95
+ 'Dancing, tap',
96
+ 'Dancing, twist',
97
+ 'Dancing, waltz',
98
+ 'Darts',
99
+ 'Diving',
100
+ 'Driving, light vehicle (e.g., car, pick-up)',
101
+ 'Eating, sitting',
102
+ 'Elliptical, light',
103
+ 'Elliptical, moderate',
104
+ 'Elliptical, very vigorous',
105
+ 'Elliptical, vigorous',
106
+ 'Fencing (sport)',
107
+ 'Fishing from boat, sitting',
108
+ 'Fishing from river bank, standing',
109
+ 'Fishing in stream, in waders',
110
+ 'Fishing, general',
111
+ 'Fishing, ice, sitting',
112
+ 'Flying airplane',
113
+ 'Food, preparing, at home',
114
+ 'Football, rugby',
115
+ 'Football, tackle',
116
+ 'Forestry Work',
117
+ 'Frisbee playing, general',
118
+ 'Frisbee, ultimate',
119
+ 'Gardening',
120
+ 'Golf - general',
121
+ 'Golf, carrying clubs',
122
+ 'Golf, general',
123
+ 'Golf, miniature or driving range',
124
+ 'Golf, pulling clubs',
125
+ 'Golf, using power cart',
126
+ 'Gymnastics',
127
+ 'Hand Gliding',
128
+ 'Handball',
129
+ 'Hiking - climbing hills, 10-20 lb load',
130
+ 'Hiking - climbing hills, 21-42 lb load',
131
+ 'Hiking - climbing hills, under 10 lb load',
132
+ 'Hiking - cross country',
133
+ 'Hockey - field or ice',
134
+ 'Horseback Riding, general',
135
+ 'Horseback Riding, trotting',
136
+ 'Horseback Riding, walking',
137
+ 'House Cleaning',
138
+ 'Hunting',
139
+ 'Ice Skating - general',
140
+ 'Ice Skating, general',
141
+ 'Ice Skating, rapidly (>9mph)',
142
+ 'Ice Skating, slow, (9mph or less)',
143
+ 'Ice Skating, speed, competitive',
144
+ 'Irrigation Work (farming)',
145
+ 'Jai Alai',
146
+ 'Jazzercise,slimnastics',
147
+ 'Jogging',
148
+ 'Judo',
149
+ 'Juggling',
150
+ 'Jujitsu',
151
+ 'Jumping Jacks',
152
+ 'Jumping Rope',
153
+ 'Karate',
154
+ 'Kayaking',
155
+ 'Kick Boxing',
156
+ 'Kickball',
157
+ 'Lacrosse',
158
+ 'Laundry doing',
159
+ 'Lawn Mowing',
160
+ 'Listening to Music',
161
+ 'Long Jump',
162
+ 'Luge',
163
+ 'Meditating',
164
+ 'Moto-cross',
165
+ 'Moving furniture, household',
166
+ 'Moving household items, boxes, upstairs',
167
+ 'Moving household items, carring boxes',
168
+ 'Mowing lawn',
169
+ 'Music - listening',
170
+ 'Music Playing, accordian',
171
+ 'Music Playing, cello',
172
+ 'Music Playing, conducting',
173
+ 'Music Playing, drums',
174
+ 'Music Playing, flute',
175
+ 'Music Playing, guitar, sitting',
176
+ 'Music Playing, guitar, standing',
177
+ 'Music Playing, horn',
178
+ 'Music Playing, marcing band',
179
+ 'Music Playing, piano or organ',
180
+ 'Music Playing, trombone',
181
+ 'Music Playing, trumpet',
182
+ 'Music Playing, violin',
183
+ 'Music Playing, woodwind',
184
+ 'Operating - heavy equipment, automated',
185
+ 'Orienteering',
186
+ 'Packing and unpacking boxes',
187
+ 'Paddleball, casual',
188
+ 'Paddleboating',
189
+ 'Painting',
190
+ 'Pilates',
191
+ 'Pistol Shooting',
192
+ 'Planting, seedlings, shrubs and trees',
193
+ 'Play/walk/run with dog',
194
+ 'Polo, on horseback',
195
+ 'Pull-ups, vigorous',
196
+ 'Push-ups, vigorous',
197
+ 'Race Walking',
198
+ 'Racquetball, casual, general',
199
+ 'Racquetball, competitive',
200
+ 'Reading, sitting',
201
+ 'Reclining, reading/writing/talking',
202
+ 'Resting, sitting or lying quietly (not sleeping)',
203
+ 'Riding, in car or other vehicle',
204
+ 'Rock Climbing, ascending',
205
+ 'Rock Climbing, rappelling',
206
+ 'Roller Skating',
207
+ 'Rope jumping, fast',
208
+ 'Rope jumping, moderate',
209
+ 'Rope jumping, slow',
210
+ 'Rowing - stationary, general',
211
+ 'Rowing-stationary, light',
212
+ 'Rowing-stationary, vigorous',
213
+ 'Rowing, stationary',
214
+ 'Running',
215
+ 'running-general',
216
+ 'Running, cross-country',
217
+ 'Running, track',
218
+ 'Running, up stairs',
219
+ 'Sailing, on water or ice, casual',
220
+ 'Sailing, on water or ice, competitive',
221
+ 'Scuba Diving',
222
+ 'Sculling',
223
+ 'Sewing',
224
+ 'Sexual activity, active, vigorous',
225
+ 'Sexual activity, general, moderate',
226
+ 'Sexual activity, passive, light, kissing',
227
+ 'Shopping, groceries, with cart',
228
+ 'Shopping, groceries, without cart',
229
+ 'Shoveling, heavy (over 15 lb per min)',
230
+ 'Shoveling, light (under 10 lb per min)',
231
+ 'Shoveling, moderate (10-15 lb per min)',
232
+ 'Shuffleboard',
233
+ 'Singing, sitting',
234
+ 'Singing, standing',
235
+ 'Sitting, quietly (e.g., watching TV)',
236
+ 'Sitting, talking or talking on phone',
237
+ 'Situps, moderate',
238
+ 'Skateboarding',
239
+ 'Ski Jumping (climbing up carrying skis)',
240
+ 'Skidiving, general',
241
+ 'skiing-snow general',
242
+ 'Skiing, cross-country',
243
+ 'Skiing, downhill, light',
244
+ 'Skiing, downhill, moderate',
245
+ 'Skiing, downhill, vigorous (racing)',
246
+ 'Skiing, snow',
247
+ 'Skindiving, fast',
248
+ 'Skindiving, moderate',
249
+ 'Sky Diving',
250
+ 'Sleeping',
251
+ 'Slimnastis',
252
+ 'Smoking, sitting, quietly',
253
+ 'Snorkeling',
254
+ 'Snow Shoeing',
255
+ 'Snow, mountaineering',
256
+ 'Snowboarding, light',
257
+ 'Snowboarding, moderate',
258
+ 'Snowboarding, vigorous',
259
+ 'Snowmobiling',
260
+ 'Soccer, casual, general',
261
+ 'Soccer, competitive',
262
+ 'Softball or baseball, fast or slow pitch',
263
+ 'Softball, officiating',
264
+ 'Sparring, boxing',
265
+ 'Springboard Diving',
266
+ 'Squash',
267
+ 'Stairmaster, light',
268
+ 'Stairmaster, moderate',
269
+ 'Stairmaster, very vigorous',
270
+ 'Stairmaster, vigorous',
271
+ 'Stretching',
272
+ 'Stroller, pushing baby stroller',
273
+ 'Surfing',
274
+ 'Surfing, body or board',
275
+ 'swimming-general',
276
+ 'Swimming, backstroke',
277
+ 'Swimming, breaststroke',
278
+ 'Swimming, butterfly',
279
+ 'Swimming, crawl (50 yards/min)',
280
+ 'Swimming, crawl (75 yards/min)',
281
+ 'Swimming, freestyle, moderate',
282
+ 'Swimming, freestyle, vigorous',
283
+ 'Swimming, lake, ovean, river',
284
+ 'Swimming, leisurely, not laps',
285
+ 'Swimming, sidestroke',
286
+ 'Swimming, tread water, moderate',
287
+ 'Swimming, tread water, vigorous',
288
+ 'Table tennis, ping pong',
289
+ 'Tae Bo, moderate',
290
+ 'Tae Bo, vigorous',
291
+ 'Tae Kwon Do',
292
+ 'Tai Chi',
293
+ 'tennis-general',
294
+ 'Tennis, doubles',
295
+ 'Tennis, singles',
296
+ 'Touring, walking and riding',
297
+ 'Track and Field, discus',
298
+ 'Track and Field, hammer throw',
299
+ 'Track and Field, high jump',
300
+ 'Track and Field, hurdles',
301
+ 'Track and Field, javelin',
302
+ 'Track and Field, long jump',
303
+ 'Track and Field, pole vault',
304
+ 'Track and Field, steeplechase',
305
+ 'Trampoline',
306
+ 'TreadClimber - resistance 0 @ 1.98mph',
307
+ 'TreadClimber - resistance 1@ 1.98 mph',
308
+ 'TreadClimber - resistance 12 @ 1.98 mph',
309
+ 'TreadClimber - resistance 6 @ 1.98 mph',
310
+ 'Treadmill - 10% incline @ 2.98 mph',
311
+ 'Treadmill - 15% incline @ 2.98 mph',
312
+ 'Treadmill - 5% incline @ 2.98 mph',
313
+ 'Triple Jump',
314
+ 'TV - watching',
315
+ 'Unicycling',
316
+ 'Vacuuming',
317
+ 'Volleyball, beach',
318
+ 'Volleyball, competitive',
319
+ 'Volleyball, competitive, in gymnasium',
320
+ 'Volleyball, noncompetitive',
321
+ 'walking-under3.2km/h',
322
+ 'Walking, 2 mph, very slow',
323
+ 'Walking, 2.5 mph, slow',
324
+ 'Walking, 3 mph, moderate',
325
+ 'Walking, 3.5 mph, brisk',
326
+ 'Walking, 4 mph, very brisk',
327
+ 'Walking, 4.5 mph, fast',
328
+ 'Walking, 5 mph, very fast',
329
+ 'Walking, household',
330
+ 'Walking, marching, rapidly',
331
+ 'Walking, pushing stroller',
332
+ 'Walking, pushing wheelchair',
333
+ 'Walking, to work or class',
334
+ 'Walking, with children',
335
+ 'Walking, with the dog',
336
+ 'Water Aerobics',
337
+ 'Water Calisthenics',
338
+ 'Water Jogging',
339
+ 'Water polo',
340
+ 'Water volleyball',
341
+ 'Weight Lifting, light/moderate',
342
+ 'Weight Lifting, vigorous',
343
+ 'Whitewater rafting',
344
+ 'Wii Fit, Aerobic, Advanced step',
345
+ 'Wii Fit, Aerobic, basic run',
346
+ 'Wii Fit, Aerobic, basic step',
347
+ 'Wii Fit, Aerobic, bird\'s-eye bull\'s-eye',
348
+ 'Wii Fit, Aerobic, drving range',
349
+ 'Wii Fit, Aerobic, free step',
350
+ 'Wii Fit, Aerobic, hula hoop',
351
+ 'Wii Fit, Aerobic, island cycling',
352
+ 'Wii Fit, Aerobic, obstacle course',
353
+ 'Wii Fit, Aerobic, rhythm boxing',
354
+ 'Wii Fit, Aerobic, rhythm kung fu',
355
+ 'Wii Fit, Aerobic, rhythm parade',
356
+ 'Wii Fit, Aerobic, running plus',
357
+ 'Wii Fit, Aerobic, skateboard arena',
358
+ 'Wii Sports, baseball',
359
+ 'Wii Sports, bowling',
360
+ 'Wii Sports, boxing',
361
+ 'Wii Sports, golf',
362
+ 'Wii Sports, tennis',
363
+ 'Windsurfing',
364
+ 'Wrestling (5 min matches)',
365
+ 'Yardwork',
366
+ 'yoga'
367
+ ]
368
+ end
369
+ end
370
+ end
@@ -0,0 +1,44 @@
1
+ module IhealthBot
2
+ module Endpoints
3
+ class Base
4
+ extend Capybara::DSL
5
+
6
+ MAIN_NAVIGATION_XPATH = '//*[@id="main_nav"]/section/div/ul[1]'.freeze
7
+ ENDPOINT_NAVIGATION_XPATH = '//*[@id="MenuSecond"]'.freeze
8
+ LEFT_NAVIGATION_XPATH = '//*[@id="menu_nav_left"]'.freeze
9
+ ERROR_BOX_XPATH = '//*[@id="ErrorBoxHolder"]'.freeze
10
+ AUTOCOMPLETE_XPATH = '/html/body/ul/li[@class="ui-menu-item"][1]/a/table/tbody/tr'.freeze
11
+
12
+ private
13
+
14
+ def self.create(endpoint)
15
+ print "Creating #{endpoint} record..."
16
+
17
+ within(:xpath, MAIN_NAVIGATION_XPATH) do
18
+ click_link 'Data'
19
+ end
20
+
21
+ within(:xpath, ENDPOINT_NAVIGATION_XPATH) do
22
+ click_link endpoint
23
+ end
24
+
25
+ within(:xpath, LEFT_NAVIGATION_XPATH) do
26
+ click_link 'ENTER DATA'
27
+ end
28
+
29
+ yield
30
+
31
+ click_button 'Submit'
32
+
33
+ within(:xpath, ERROR_BOX_XPATH) do
34
+ if current_scope.text.include?('Saved')
35
+ print " ✓ \n"
36
+ else
37
+ print " X \n"
38
+ puts "Error saving data for #{endpoint}"
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,14 @@
1
+ module IhealthBot
2
+ module Endpoints
3
+ class BloodGlucose < Base
4
+ def self.create
5
+ super('Blood Glucose') do
6
+ find('#txtGlucose').set(rand(50..200))
7
+ find('#selMeal').set(%w{Pre-Breakfast Post-Breakfast Pre-Lunch Post-Lunch Pre-Dinner Post-Dinner Bedtime After Snacks Random}.sample)
8
+ find('#selMedication').set(%w{Pre-Medicine Post-Medicine}.sample)
9
+ find('#txtRemark').set("Via iHealth Bot v#{VERSION}")
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module IhealthBot
2
+ module Endpoints
3
+ class BloodPressure < Base
4
+ def self.create
5
+ super('Blood Pressure') do
6
+ find('#txtHighPress').set(rand(100..150))
7
+ find('#txtlowPress').set(rand(50..100))
8
+ find('#txtHeartRate').set(rand(50..90))
9
+ find('#txtRemark').set("Via iHealth Bot v#{VERSION}")
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,29 @@
1
+ module IhealthBot
2
+ module Endpoints
3
+ class Food < Base
4
+ def self.create
5
+ super('Food') do
6
+ 5.times do
7
+ find('#txtFoodName').set(2.times.map { [*'a'..'z'].sample }.join)
8
+
9
+ if no_results?
10
+ next
11
+ else
12
+ find(:xpath, AUTOCOMPLETE_XPATH).click
13
+ break
14
+ end
15
+ end
16
+
17
+ find('#txtEatWeightG').set(rand(1..20))
18
+ find('#eatMeal').set(%w{Breakfast Lunch Dinner Snack}.sample)
19
+ end
20
+ end
21
+
22
+ def self.no_results?
23
+ !find(:xpath, AUTOCOMPLETE_XPATH)
24
+ rescue Capybara::ElementNotFound
25
+ true
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ module IhealthBot
2
+ module Endpoints
3
+ class Weight < Base
4
+ def self.create
5
+ super('Weight') do
6
+ find('#txtWeight').set(rand(220..240))
7
+ find('#txtFatValue').set(rand(10..15))
8
+ find('#txtBoneValue').set(rand(1..10))
9
+ find('#txtWaterValue').set(rand(20..85))
10
+ find('#txtMuscaleValue').set(rand(10..100))
11
+ find('#txtVFR').set(rand(10..15))
12
+ find('#txtRemark').set("Via iHealth Bot v#{VERSION}")
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'endpoints/base.rb'
2
+ require_relative 'endpoints/activities.rb'
3
+ require_relative 'endpoints/blood_glucose.rb'
4
+ require_relative 'endpoints/blood_pressure.rb'
5
+ require_relative 'endpoints/food.rb'
6
+ require_relative 'endpoints/weight.rb'
7
+
8
+ module IhealthBot
9
+ module Endpoints
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module IhealthBot
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,26 @@
1
+ require_relative 'ihealth_bot/endpoints.rb'
2
+ require_relative 'ihealth_bot/version.rb'
3
+ require_relative 'ihealth_bot/config.rb'
4
+
5
+ module IhealthBot
6
+ extend Capybara::DSL
7
+
8
+ def self.create_data
9
+ login
10
+ Endpoints::Activities.create
11
+ Endpoints::BloodGlucose.create
12
+ Endpoints::BloodPressure.create
13
+ Endpoints::Food.create
14
+ Endpoints::Weight.create
15
+ puts "Done! \n"
16
+ end
17
+
18
+ def self.login
19
+ visit('/')
20
+ print 'Logging in...'
21
+ fill_in 'Email', with: Config.email
22
+ fill_in 'Password', with: Config.password
23
+ click_button 'Login'
24
+ print " ✓ \n"
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ihealth_bot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Josh Haywood
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capybara
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.10.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.10.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: capybara-webkit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.19.4
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.19.4
55
+ description: Automagically create iHealth data via the user portal. Useful for testing.
56
+ email: josh.haywood@gmail.com
57
+ executables:
58
+ - ihealth_bot
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - LICENSE
64
+ - README.md
65
+ - bin/ihealth_bot
66
+ - ihealth_bot.gemspec
67
+ - lib/ihealth_bot.rb
68
+ - lib/ihealth_bot/config.rb
69
+ - lib/ihealth_bot/endpoints.rb
70
+ - lib/ihealth_bot/endpoints/activities.rb
71
+ - lib/ihealth_bot/endpoints/base.rb
72
+ - lib/ihealth_bot/endpoints/blood_glucose.rb
73
+ - lib/ihealth_bot/endpoints/blood_pressure.rb
74
+ - lib/ihealth_bot/endpoints/food.rb
75
+ - lib/ihealth_bot/endpoints/weight.rb
76
+ - lib/ihealth_bot/version.rb
77
+ homepage: https://github.com/johaywood/ihealth_bot
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.3'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.5.1
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Create iHealth data
101
+ test_files: []