Skip to content

Commit

Permalink
git pain
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Lewandowski committed Jan 6, 2010
1 parent 0b7a15c commit 5fc3459
Show file tree
Hide file tree
Showing 12 changed files with 869 additions and 1 deletion.
1 change: 0 additions & 1 deletion vendor/plugins/geoapi
Submodule geoapi deleted from e1d26f
94 changes: 94 additions & 0 deletions vendor/plugins/geoapi/init.rb
@@ -0,0 +1,94 @@

%w{rubygems rest_client httparty json crack/json uuidtools}.each { |x| require x }

# Patch HTTParty to debug
HTTParty::Request.class_eval do
class << self
attr_accessor :debug
end
self.debug = true

def perform_with_debug
if self.class.debug
puts "HTTParty making #{http_method::METHOD} request to:"
puts uri
puts "With Body: #{body}"
end

retryable( :tries => 2 ) do
perform_without_debug
end
end

alias_method :perform_without_debug, :perform
alias_method :perform, :perform_with_debug
end


# monkey patch HTTParty to use a configurable timeout
module HTTParty
class Request
private
def http
http = Net::HTTP.new(uri.host, uri.port, options[:http_proxyaddr], options[:http_proxyport])
http.use_ssl = (uri.port == 443)
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.open_timeout = http.read_timeout = options[:timeout].to_i if options[:timeout].to_i > 0
puts "HTTParty timeout set to #{http.open_timeout}"
http
end
end
end

def retryable(options = {}, &block)
opts = { :tries => 1, :on => Exception }.merge(options)

retry_exception, retries = opts[:on], opts[:tries]

begin
return yield
rescue retry_exception
retry if (retries -= 1) > 0
end

yield
end

class Array
# Extract options from a set of arguments. Removes and returns the last element in the array if it's a hash, otherwise returns a blank hash.
#
# def options(*args)
# args.extract_options!
# end
#
# options(1, 2) # => {}
# options(1, 2, :a => :b) # => {:a=>:b}
def extract_options!
last.is_a?(::Hash) ? pop : {}
end
end

module GeoAPI
API_VERSION = "v1"
API_URL = "http://api.geoapi.com/#{API_VERSION}/"

class ArgumentError < StandardError; end
class BadRequest < StandardError; end
class NotFound < StandardError; end
class NotAcceptable < StandardError; end
end


$:.unshift(File.dirname(__FILE__)) unless
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))

require 'lib/geo_object'
require 'lib/geometry'
require 'lib/version'
require 'lib/entity'
require 'lib/entry'
require 'lib/view'
require 'lib/user_view'
require 'lib/query'
require 'lib/client'
require 'lib/neighborhood'
32 changes: 32 additions & 0 deletions vendor/plugins/geoapi/lib/client.rb
@@ -0,0 +1,32 @@
module GeoAPI
class Client

# To connect to GeoAPI, either:
#
# Add export GEOAPI_KEY=<your-api-key> in your .bashrc file
#
# @client = GeoAPI::Client.new
#
# OR
#
# @client = GeoAPI::Client.new('<your-api-key>')
#
# OR set GEOAPI_KEY='<your-api-key>' before including GeoAPI
#
# @client = GeoAPI::Client.new

def initialize(api_key=nil)
@api_key = api_key || ENV['GEOAPI_KEY'] || GeoAPI::GEOAPI_KEY
end

def api_key
@api_key
end

def self.id_from_guid(guid,apikey)
id = guid.sub('user-','')
id = id.sub("#{apikey}-",'')
end

end
end

0 comments on commit 5fc3459

Please sign in to comment.