-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I'll be honest, I'm not proud of this
But it works
- Loading branch information
pikesley
committed
Jan 31, 2016
1 parent
4ab793b
commit 96d042a
Showing
5 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'xmlsimple' | ||
require 'json' | ||
require 'httparty' | ||
require 'dotenv' | ||
require 'dropbox-api' | ||
require 'dropbox-api/tasks' | ||
|
||
def dropbox_client | ||
Dotenv.load | ||
Dropbox::API::Config.mode = 'dropbox' | ||
Dropbox::API::Config.app_key = ENV['DROPBOX_APP_KEY'] | ||
Dropbox::API::Config.app_secret = ENV['DROPBOX_APP_SECRET'] | ||
Dropbox::API::Client.new(:token => ENV['DROPBOX_TOKEN'], :secret => ENV['DROPBOX_SECRET']) | ||
end | ||
|
||
def download | ||
dropbox_client.download dropbox_client.ls('ontrack').sort { |x, y| x[:revision] <=> y[:revision] }[-1].path | ||
end | ||
|
||
def munge | ||
data = XmlSimple.xml_in download | ||
r = data['record'] | ||
r.sort! { |x, y| x['datetime'] <=> y['datetime'] } | ||
|
||
r.each do |datum| | ||
datum.each_pair do |k, v| | ||
datum[k] = v[0] | ||
end.to_json | ||
end | ||
end | ||
|
||
def dispatch url | ||
munge.each do |j| | ||
puts "sending #{j}" | ||
HTTParty.post( | ||
url, | ||
body: { | ||
data: j | ||
}.to_json, | ||
headers: { | ||
'Content-Type' => 'application/json' | ||
}, | ||
basic_auth: { | ||
username: ENV['API_USER'], | ||
password: ENV['API_PASSWORD'] | ||
} | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
load File.expand_path('../../dirty_hacky_mess.rb', __FILE__) | ||
|
||
desc 'Import the Ontrack data' | ||
namespace :ontrack do | ||
task :import do | ||
dispatch "#{ENV['host']}/api" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
describe 'Layout' do | ||
describe 'Page has requisite elements' do | ||
let(:user) { create :user } | ||
|
||
it 'has the nav links' do | ||
visit glucose_measurements_url(as: user) | ||
|
||
within 'nav' do | ||
within 'ul' do | ||
expect(page.all('a').map { |link| link.text}).to eq [ | ||
'Glucose', | ||
'Carbs', | ||
'Meds', | ||
'Exercise' | ||
] | ||
end | ||
end | ||
end | ||
end | ||
end |