From d8b998a99423a600bd9839a46606c4e62fcb64d8 Mon Sep 17 00:00:00 2001 From: John Crepezzi Date: Sat, 19 Nov 2011 01:19:26 -0500 Subject: [PATCH] Remove dependencies --- TODO | 1 - haste.gemspec | 2 +- lib/haste.rb | 17 +++++++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/TODO b/TODO index 8bc2809..2b29f27 100644 --- a/TODO +++ b/TODO @@ -1,2 +1 @@ tests -remove dependencies diff --git a/haste.gemspec b/haste.gemspec index 3746860..479f791 100644 --- a/haste.gemspec +++ b/haste.gemspec @@ -5,7 +5,7 @@ spec = Gem::Specification.new do |s| s.name = 'haste' s.author = 'John Crepezzi' s.add_development_dependency('rspec') - s.add_dependency('rest-client') + s.add_dependency('json') s.description = 'CLI Haste Client' s.email = 'john.crepezzi@gmail.com' s.executables = 'haste' diff --git a/lib/haste.rb b/lib/haste.rb index 3434f92..9ef38ba 100644 --- a/lib/haste.rb +++ b/lib/haste.rb @@ -1,4 +1,3 @@ -require 'restclient' require 'json' module Haste @@ -17,9 +16,19 @@ module Haste # Upload the and output the URL we get back def start - json = RestClient.post "#{server}/documents", input - data = JSON.parse(json) - puts "#{server}/#{data['key']}" + uri = URI.parse server + http = Net::HTTP.new uri.host, uri.port + response = http.post '/documents', input + if response.is_a?(Net::HTTPOK) + data = JSON.parse(response.body) + STDOUT.puts "#{server}/#{data['key']}" + else + STDERR.puts "failure uploading: #{res.status}" + end + rescue RuntimeError, JSON::ParserError => e + STDERR.puts "failure uploading: #{response.code}" + rescue Errno::ECONNREFUSED => e + STDERR.puts "failure connecting: #{e.message}" end private