weatherzone 0.7.2 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +0 -7
- data/lib/weatherzone/connection.rb +5 -4
- data/lib/weatherzone.rb +2 -15
- metadata +4 -13
- data/lib/vendor/openuri_memcached/History.txt +0 -18
- data/lib/vendor/openuri_memcached/License.txt +0 -20
- data/lib/vendor/openuri_memcached/README.markdown +0 -48
- data/lib/vendor/openuri_memcached/lib/openuri/common.rb +0 -117
- data/lib/vendor/openuri_memcached/lib/openuri/memcached.rb +0 -36
- data/lib/vendor/openuri_memcached/lib/openuri/rails-cache.rb +0 -21
- data/lib/vendor/openuri_memcached/lib/openuri_memcached.rb +0 -1
data/Manifest.txt
CHANGED
@@ -36,13 +36,6 @@ lib/weatherzone/resources/snow_report.rb
|
|
36
36
|
lib/weatherzone/resources/surf_report.rb
|
37
37
|
lib/weatherzone/resources/warning.rb
|
38
38
|
lib/weatherzone/resources/weather.rb
|
39
|
-
lib/vendor/openuri_memcached/History.txt
|
40
|
-
lib/vendor/openuri_memcached/License.txt
|
41
|
-
lib/vendor/openuri_memcached/README.markdown
|
42
|
-
lib/vendor/openuri_memcached/lib/openuri_memcached.rb
|
43
|
-
lib/vendor/openuri_memcached/lib/openuri/common.rb
|
44
|
-
lib/vendor/openuri_memcached/lib/openuri/memcached.rb
|
45
|
-
lib/vendor/openuri_memcached/lib/openuri/rails-cache.rb
|
46
39
|
lib/tzinfo/definitions/Australia/CDT.rb
|
47
40
|
lib/tzinfo/definitions/Australia/CST.rb
|
48
41
|
lib/tzinfo/definitions/Australia/EDT.rb
|
@@ -30,6 +30,7 @@ module Weatherzone
|
|
30
30
|
@keygen = keygen
|
31
31
|
@logger = options[:logger]
|
32
32
|
@timeout_after = options[:timeout_after] || DEFAULT_TIMEOUT_AFTER
|
33
|
+
@http = Net::HTTP::Persistent.new
|
33
34
|
end
|
34
35
|
|
35
36
|
def self.settings
|
@@ -53,11 +54,11 @@ module Weatherzone
|
|
53
54
|
end
|
54
55
|
|
55
56
|
def request(params)
|
56
|
-
|
57
|
-
info("GET #{
|
57
|
+
uri = URI.parse(wz_url_for(params))
|
58
|
+
info("GET #{uri}")
|
58
59
|
timeout(self.timeout_after) do
|
59
|
-
response =
|
60
|
-
response.
|
60
|
+
response = @http.request(uri)
|
61
|
+
response.body
|
61
62
|
end
|
62
63
|
rescue Timeout::Error, SocketError => e
|
63
64
|
error("webservice connection failed #{e}")
|
data/lib/weatherzone.rb
CHANGED
@@ -8,20 +8,7 @@ require 'timeout'
|
|
8
8
|
require 'nokogiri'
|
9
9
|
require 'sax-machine'
|
10
10
|
require 'tzinfo'
|
11
|
-
|
12
|
-
begin
|
13
|
-
$LOAD_PATH << File.join(File.dirname(__FILE__), *%w[vendor openuri_memcached lib])
|
14
|
-
if defined? Rails
|
15
|
-
require 'openuri/rails-cache'
|
16
|
-
else
|
17
|
-
require 'openuri/memcached'
|
18
|
-
# Cache for 10 minutes. The web service caches for the same period, so this ensures we've always got
|
19
|
-
# the freshest data and the speediest response.
|
20
|
-
OpenURI::Cache.expiry = 600
|
21
|
-
end
|
22
|
-
rescue LoadError
|
23
|
-
require 'open-uri'
|
24
|
-
end
|
11
|
+
require 'net/http/persistent'
|
25
12
|
|
26
13
|
unless defined?(ActiveSupport)
|
27
14
|
require 'ext/class'
|
@@ -35,5 +22,5 @@ require 'weatherzone/helpers/date_parser'
|
|
35
22
|
require 'weatherzone/helpers/units'
|
36
23
|
|
37
24
|
module Weatherzone
|
38
|
-
VERSION = '0.
|
25
|
+
VERSION = '0.8.0'
|
39
26
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 8
|
8
|
+
- 0
|
9
|
+
version: 0.8.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ben Askins
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-10 00:00:00 +10:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -42,8 +42,6 @@ extra_rdoc_files:
|
|
42
42
|
- History.txt
|
43
43
|
- Manifest.txt
|
44
44
|
- README.txt
|
45
|
-
- lib/vendor/openuri_memcached/History.txt
|
46
|
-
- lib/vendor/openuri_memcached/License.txt
|
47
45
|
files:
|
48
46
|
- History.txt
|
49
47
|
- Manifest.txt
|
@@ -83,13 +81,6 @@ files:
|
|
83
81
|
- lib/weatherzone/resources/surf_report.rb
|
84
82
|
- lib/weatherzone/resources/warning.rb
|
85
83
|
- lib/weatherzone/resources/weather.rb
|
86
|
-
- lib/vendor/openuri_memcached/History.txt
|
87
|
-
- lib/vendor/openuri_memcached/License.txt
|
88
|
-
- lib/vendor/openuri_memcached/README.markdown
|
89
|
-
- lib/vendor/openuri_memcached/lib/openuri_memcached.rb
|
90
|
-
- lib/vendor/openuri_memcached/lib/openuri/common.rb
|
91
|
-
- lib/vendor/openuri_memcached/lib/openuri/memcached.rb
|
92
|
-
- lib/vendor/openuri_memcached/lib/openuri/rails-cache.rb
|
93
84
|
- lib/tzinfo/definitions/Australia/CDT.rb
|
94
85
|
- lib/tzinfo/definitions/Australia/CST.rb
|
95
86
|
- lib/tzinfo/definitions/Australia/EDT.rb
|
@@ -1,18 +0,0 @@
|
|
1
|
-
== 0.2.0 2009-01-23
|
2
|
-
* Include support for Rails.cache
|
3
|
-
|
4
|
-
== 0.1.0 2008-04-17
|
5
|
-
* Included Evan Weaver's Memcached C wrapper for a healthy speed improvement
|
6
|
-
|
7
|
-
== 0.0.3 2008-01-18
|
8
|
-
* Caches are now stored by the uri as the key like they originally were
|
9
|
-
|
10
|
-
== 0.0.2 2008-01-15
|
11
|
-
* Some moron forgot to write the dependency list correctly for 0.0.1
|
12
|
-
|
13
|
-
|
14
|
-
== 0.0.1 2008-01-14
|
15
|
-
|
16
|
-
* Inital release:
|
17
|
-
* Proof of concept come used library for a personal project
|
18
|
-
|
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2008-2009 Ben Schwarz
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# OpenURI with caching
|
2
|
-
|
3
|
-
Carelessly make OpenURI requests without getting hate mail.
|
4
|
-
|
5
|
-
## Running with MemCached
|
6
|
-
|
7
|
-
Require the library
|
8
|
-
|
9
|
-
require 'openuri/memcached'
|
10
|
-
|
11
|
-
Start memcached server
|
12
|
-
|
13
|
-
ben@Spinners ~/ Ϟ memcached -d
|
14
|
-
|
15
|
-
Set your memcached host/s (defaults to 127.0.0.1:11211)
|
16
|
-
|
17
|
-
OpenURI::Cache.host = ['10.1.1.10:11211', '10.1.1.11:11211']
|
18
|
-
|
19
|
-
The default expiry is 15 minutes, this can be changed using the `expiry` method
|
20
|
-
|
21
|
-
# Ten long minutes
|
22
|
-
OpenURI::Cache.expiry = 600
|
23
|
-
|
24
|
-
## Running using Rails cache
|
25
|
-
|
26
|
-
You can also cache your OpenURI calls using Rails cache.
|
27
|
-
require the library using `require openuri/rails-cache`
|
28
|
-
|
29
|
-
### Execution
|
30
|
-
Use exactly the same as you would OpenURI, only.. enable it.
|
31
|
-
|
32
|
-
OpenURI::Cache.enable!
|
33
|
-
# As slow a wet week
|
34
|
-
open("http://ab-c.com.au").read
|
35
|
-
|
36
|
-
Quit your app (leave memcached running) and re-run the same request, It will come from cache.
|
37
|
-
|
38
|
-
### Requirements
|
39
|
-
|
40
|
-
* Ruby
|
41
|
-
* MemCached
|
42
|
-
* memcache (gem)
|
43
|
-
* You will need to ensure that you have [corresponding version](http://blog.evanweaver.com/files/doc/fauna/memcached/files/COMPATIBILITY.html) of libmemcached to the memcached gem installed for installation to go by breezy
|
44
|
-
|
45
|
-
### Contributors
|
46
|
-
|
47
|
-
* [Ben Askins](http://github.com/benaskins)
|
48
|
-
* [Rick Olson](http://github.com/technoweenie)
|
@@ -1,117 +0,0 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
|
3
|
-
module Kernel
|
4
|
-
private
|
5
|
-
alias openuri_original_open open
|
6
|
-
def open(name, *rest, &block)
|
7
|
-
if name.respond_to?(:open)
|
8
|
-
name.open(*rest, &block)
|
9
|
-
elsif name.respond_to?(:to_str) &&
|
10
|
-
%r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ name &&
|
11
|
-
(uri = URI.parse(name)).respond_to?(:open)
|
12
|
-
OpenURI::open(name, *rest, &block)
|
13
|
-
else
|
14
|
-
open_uri_original_open(name, *rest, &block)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
module_function :open, :openuri_original_open
|
18
|
-
end
|
19
|
-
|
20
|
-
module OpenURI
|
21
|
-
alias original_open open #:nodoc:
|
22
|
-
def self.open(uri, *rest, &block)
|
23
|
-
if Cache.enabled?
|
24
|
-
response = Cache.get(Cache.key_for(uri))
|
25
|
-
end
|
26
|
-
|
27
|
-
unless response
|
28
|
-
response = openuri_original_open(uri, *rest).read
|
29
|
-
Cache.set(Cache.key_for(uri), response) if Cache.enabled?
|
30
|
-
end
|
31
|
-
|
32
|
-
response = StringIO.new(response)
|
33
|
-
|
34
|
-
if block_given?
|
35
|
-
begin
|
36
|
-
yield response
|
37
|
-
ensure
|
38
|
-
response.close
|
39
|
-
end
|
40
|
-
else
|
41
|
-
response
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
class Cache
|
46
|
-
|
47
|
-
class KeyHash
|
48
|
-
def self.enable!
|
49
|
-
@hash_keys = true
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.disable!
|
53
|
-
@hash_keys = false
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.enabled?
|
57
|
-
@hash_keys
|
58
|
-
end
|
59
|
-
|
60
|
-
def self.disabled?
|
61
|
-
!@hash_keys
|
62
|
-
end
|
63
|
-
|
64
|
-
def self.generate(uri)
|
65
|
-
Digest::MD5.hexdigest(uri)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# Cache is not enabled by default
|
70
|
-
@cache_enabled = false
|
71
|
-
|
72
|
-
class << self
|
73
|
-
attr_writer :expiry, :host
|
74
|
-
|
75
|
-
# Is the cache enabled?
|
76
|
-
def enabled?
|
77
|
-
@cache_enabled
|
78
|
-
end
|
79
|
-
|
80
|
-
# Enable caching
|
81
|
-
def enable!
|
82
|
-
raise NotImplementedError
|
83
|
-
end
|
84
|
-
|
85
|
-
# Disable caching - all queries will be run directly
|
86
|
-
# using the standard OpenURI `open` method.
|
87
|
-
def disable!
|
88
|
-
@cache_enabled = false
|
89
|
-
end
|
90
|
-
|
91
|
-
def disabled?
|
92
|
-
!@cache_enabled
|
93
|
-
end
|
94
|
-
|
95
|
-
def get(key)
|
96
|
-
raise NotImplementedError
|
97
|
-
end
|
98
|
-
|
99
|
-
def set(key, value)
|
100
|
-
raise NotImplementedError
|
101
|
-
end
|
102
|
-
|
103
|
-
def key_for(uri)
|
104
|
-
Cache::KeyHash.enabled? ? Cache::KeyHash.generate(uri.to_s) : uri.to_s
|
105
|
-
end
|
106
|
-
|
107
|
-
# How long your caches will be kept for (in seconds)
|
108
|
-
def expiry
|
109
|
-
@expiry ||= 60 * 10
|
110
|
-
end
|
111
|
-
|
112
|
-
def host
|
113
|
-
@host ||= "127.0.0.1:11211"
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'openuri/common'
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'minigems'
|
5
|
-
rescue LoadError
|
6
|
-
require 'rubygems'
|
7
|
-
end
|
8
|
-
|
9
|
-
gem "memcached", ">= 0.10"
|
10
|
-
require 'memcached'
|
11
|
-
|
12
|
-
module OpenURI
|
13
|
-
class Cache
|
14
|
-
class << self
|
15
|
-
# Enable caching
|
16
|
-
def enable!
|
17
|
-
@cache ||= Memcached.new(host, {
|
18
|
-
:namespace => 'openuri',
|
19
|
-
:no_block => true,
|
20
|
-
:buffer_requests => true
|
21
|
-
})
|
22
|
-
@cache_enabled = true
|
23
|
-
end
|
24
|
-
|
25
|
-
def get(key)
|
26
|
-
@cache.get(key)
|
27
|
-
rescue Memcached::NotFound
|
28
|
-
false
|
29
|
-
end
|
30
|
-
|
31
|
-
def set(key, value)
|
32
|
-
@cache.set(key, value, expiry)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'openuri/common'
|
2
|
-
|
3
|
-
module OpenURI
|
4
|
-
class Cache
|
5
|
-
class << self
|
6
|
-
# Enable caching
|
7
|
-
def enable!
|
8
|
-
@cache = Rails.cache
|
9
|
-
@cache_enabled = true
|
10
|
-
end
|
11
|
-
|
12
|
-
def get(key)
|
13
|
-
@cache.read(key)
|
14
|
-
end
|
15
|
-
|
16
|
-
def set(key, value)
|
17
|
-
@cache.write(key, value, :expires_in => expiry)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require 'openuri/memcached'
|