lib/bitly/utils.rb in philnash-bitly-0.2 vs lib/bitly/utils.rb in philnash-bitly-0.3

- old
+ new

@@ -1,18 +1,21 @@ require 'cgi' module Bitly module Utils - private def underscore(camel_cased_word) # stolen from rails camel_cased_word.to_s.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end + def create_hash_from_url(url) + url.gsub(/^.*bit.ly\//,'') + end + def attr_define(k,v) instance_variable_set("@#{k}", v) meta = class << self; self; end meta.class_eval { attr_reader k.to_sym } end @@ -40,15 +43,15 @@ def get_result(request) begin result = Crack::JSON.parse(Net::HTTP.get(request)) rescue - result = {'statusCode' => 'JSON Parse Error(Bit.ly messed up)', 'errorCode' => 69} + result = {'errorMessage' => 'JSON Parse Error(Bit.ly messed up)', 'errorCode' => 69, 'statusCode' => 'ERROR'} end if result['statusCode'] == "OK" result = result['results'] else - raise BitlyError.new(result['errorMessage'],result['errorCode'],'expand') + raise BitlyError.new(result['errorMessage'],result['errorCode']) end end end end \ No newline at end of file