rubbish_collection 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -20,7 +20,8 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- collection_times = RubbishCollection.times_at_postcode 'SE1 1EY'
23
+ address = OpenStruct.new :street_name => "Redcross Way", :postcode => "SE1 1EY"
24
+ collection_times = RubbishCollection.times_at_address address
24
25
  collection_times.each do |t|
25
26
  puts t.to_s
26
27
  end
@@ -36,9 +37,17 @@ You can get the ID to register your local authority adapter against by looking
36
37
  at the [local authority database][0] in my [local\_authority gem][1]. It's the
37
38
  last column of the CSV row.
38
39
 
40
+ Note that the API of the address object used in this gem hasn't yet been settled
41
+ on. Different local authorities need different parts or formats of the address
42
+ to determine collection times eg Southwark and Redbridge are pretty good with
43
+ just the postcode but Westminster need a street name. At some point we should
44
+ either find a gem that already caters to addresses and provides a nice API and
45
+ tools for comparison, or we should define or own.
46
+
39
47
  [0]: https://raw.github.com/craigw/local_authority/master/db/local_authorities.csv
40
48
  [1]: https://github.com/craigw/local_authority
41
49
 
50
+
42
51
  ## Contributing
43
52
 
44
53
  1. Fork it
@@ -9,10 +9,10 @@ module RubbishCollection
9
9
  def initialize local_authority
10
10
  end
11
11
 
12
- def collection_times_at postcode
12
+ def collection_times_at address
13
13
  Net::HTTP.start "www.redbridge.gov.uk", 80 do |http|
14
14
  req = Net::HTTP::Get.new '/RecycleRefuse'
15
- req['Cookie'] = "RedbridgeIV3LivePref=postcode=#{postcode}"
15
+ req['Cookie'] = "RedbridgeIV3LivePref=postcode=#{address.postcode}"
16
16
  response = http.request req
17
17
  doc = Nokogiri::HTML response.body
18
18
  info = doc.xpath "//*[@id='RegularCollectionDay']"
@@ -9,9 +9,9 @@ module RubbishCollection
9
9
  def initialize local_authority
10
10
  end
11
11
 
12
- def collection_times_at postcode
12
+ def collection_times_at address
13
13
  Net::HTTP.start "wasteservices.southwark.gov.uk", 80 do |http|
14
- req = Net::HTTP::Get.new "/findAddress.asp?pc=#{postcode.gsub(/\s+/, '')}"
14
+ req = Net::HTTP::Get.new "/findAddress.asp?pc=#{address.postcode.gsub(/\s+/, '')}"
15
15
  response = http.request req
16
16
  addresses = Nokogiri::HTML.fragment response.body
17
17
  first_address = addresses.xpath(".//option").detect { |o| o['value'].to_s.strip != '' }
@@ -1,3 +1,3 @@
1
1
  module RubbishCollection
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -70,12 +70,13 @@ module RubbishCollection
70
70
  end
71
71
  end
72
72
 
73
- def self.times_at_postcode postcode
73
+ def self.times_at_address address
74
+ pc = address.postcode
75
+ local_authority = LocalAuthority::LocalAuthority.find_by_postcode pc
74
76
  times = CollectionTimes.new
75
- local_authority = LocalAuthority::LocalAuthority.find_by_postcode postcode
76
77
  return times if local_authority.nil?
77
78
  adaptor = adapter_for local_authority
78
- adaptor.collection_times_at(postcode).each do |t|
79
+ adaptor.collection_times_at(address).each do |t|
79
80
  times << t
80
81
  end
81
82
  times
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubbish_collection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: