Skip to content

Commit

Permalink
finished gemspec
Browse files Browse the repository at this point in the history
  • Loading branch information
kevTheDev committed Oct 13, 2011
1 parent 5c8c898 commit 7b28ca4
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 109 deletions.
3 changes: 3 additions & 0 deletions Gemfile
@@ -0,0 +1,3 @@
source "http://rubygems.org"

gemspec
File renamed without changes.
29 changes: 0 additions & 29 deletions Rakefile

This file was deleted.

2 changes: 2 additions & 0 deletions hatch_postcode_anywhere.gemspec
Expand Up @@ -17,4 +17,6 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_dependency('httparty', '>=0.8.1')
end
8 changes: 8 additions & 0 deletions hatch_postcode_anywhere.rb
@@ -0,0 +1,8 @@
module HatchPostcodeAnywhere

autoload :PostcodeAnywhere, 'hatch/postcode_anywhere'
autoload :Version, 'hatch/version'

end

require 'hatch/railtie' if defined?(Rails) && Rails::VERSION::MAJOR >= 3
80 changes: 80 additions & 0 deletions lib/hatch/postcode_anywhere.rb
@@ -0,0 +1,80 @@
require "httparty"
require 'cgi'

module Hatch
class PostcodeAnywhere

SERVICE_ADDRESS = "http://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/RetrieveByPostcodeAndBuilding/v1.00/xmle.ws"

include HTTParty
format :xml

class << self

attr_accessor :key#, :postcode, :number

def license_key
@key
end


end



def self.find(query_options={})
PostcodeAnywhere.validate_key
data = PostcodeAnywhere.lookup(postcode)
data["Table"]["Row"]
end

def self.find_by_postcode(postcode)
PostcodeAnywhere.validate_key
data = PostcodeAnywhere.lookup(postcode)
data["Table"]["Row"]
end

def self.find_by_postcode_and_number(postcode, number)
PostcodeAnywhere.validate_key
data = PostcodeAnywhere.lookup(postcode, number)
data["Table"]["Row"]
end

def self.params(options={})
{
:Key => POSTCODE_ANYWHERE_KEY,
:Postcode => options[:postcode],
:Building => options[:number]
}
end

def self.query_string(options={})
params(options).map{|k,v| "#{CGI::escape(k.to_s)}=#{CGI::escape(v)}"}.join('&')
end

# appends query string to HOST_URL
def to_s
"#{HOST_URL}?#{query_string}"
end


def self.validate_key
unless PostcodeAnywhere.key
raise PostcodeAnywhereException, "Please provide a valid Postcode Anywhere License Key"
end
end

def self.sanitised_postcode(postcode)
postcode.gsub(/\s/, "")
end

def self.lookup(postcode, number='')
param_string = query_string(:postcode => postcode, :number => number)
PostcodeAnywhere.get "#{SERVICE_ADDRESS}?#{param_string}"
end

class PostcodeAnywhereException < StandardError;end

end

end
3 changes: 3 additions & 0 deletions lib/hatch/version.rb
@@ -0,0 +1,3 @@
module Hatch
VERSION = "0.0.1"
end
77 changes: 0 additions & 77 deletions lib/hatch_postcode_anywhere/postcode_anywhere.rb

This file was deleted.

3 changes: 0 additions & 3 deletions lib/hatch_postcode_anywhere/version.rb

This file was deleted.

0 comments on commit 7b28ca4

Please sign in to comment.