Skip to content

Commit

Permalink
I'll be honest, I'm not proud of this
Browse files Browse the repository at this point in the history
But it works
  • Loading branch information
pikesley committed Jan 31, 2016
1 parent 4ab793b commit 96d042a
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ gem 'bootstrap3-datetimepicker-rails', '~> 4.17.37'

gem 'dotenv'
gem 'httparty'
gem 'dropbox-api'
gem 'xml-simple', :require => 'xmlsimple'


group :development, :test do
gem 'pry'
Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ GEM
domain_name (0.5.25)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.1.0)
dropbox-api (0.4.7)
hashie (~> 3.4.0)
multi_json (~> 1.10)
oauth (~> 0.4.7)
email_validator (1.6.0)
activemodel
erubis (2.7.0)
Expand Down Expand Up @@ -111,6 +115,7 @@ GEM
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
hashie (3.4.3)
http-cookie (1.0.2)
domain_name (~> 0.5)
httparty (0.13.7)
Expand Down Expand Up @@ -150,6 +155,7 @@ GEM
notiffany (0.0.8)
nenv (~> 0.1)
shellany (~> 0.0)
oauth (0.4.7)
pg (0.18.4)
pry (0.10.3)
coderay (~> 1.1.0)
Expand Down Expand Up @@ -265,6 +271,7 @@ GEM
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
xml-simple (1.1.5)
xpath (2.0.0)
nokogiri (~> 1.3)

Expand All @@ -280,6 +287,7 @@ DEPENDENCIES
coveralls
database_cleaner
dotenv
dropbox-api
factory_girl_rails
guard-rspec
httparty
Expand All @@ -300,6 +308,7 @@ DEPENDENCIES
turbolinks
uglifier (>= 1.3.0)
web-console (~> 2.0)
xml-simple

BUNDLED WITH
1.11.2
49 changes: 49 additions & 0 deletions lib/dirty_hacky_mess.rb
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
8 changes: 8 additions & 0 deletions lib/tasks/ontrack_import.rake
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
20 changes: 20 additions & 0 deletions spec/requests/layouts_and_shit_spec.rb
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

0 comments on commit 96d042a

Please sign in to comment.