google_chart_ssl 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +10 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.rdoc +57 -0
- data/Rakefile +11 -0
- data/autotest/discover.rb +1 -0
- data/autotest/testunit.rb +23 -0
- data/google_chart_ssl.gemspec +29 -0
- data/lib/google_chart_ssl/version.rb +3 -0
- data/lib/google_chart_ssl.rb +26 -0
- data/test/google_chart_ssl_test.rb +36 -0
- data/test/helper.rb +30 -0
- metadata +163 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Michael Gee
|
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.
|
data/README.rdoc
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
= GoogleChartSSL
|
2
|
+
|
3
|
+
Including Google Charts in your SSL-protected site causes warnings about 'Mixed Content' (particularly in Internet Explorer). This Rack middleware allows you to point those img tags at a local path instead of Google. The image is retreived by your server then delivered to your client over your SSL connection.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
gem intall google_chart_ssl
|
8
|
+
|
9
|
+
|
10
|
+
== Usage
|
11
|
+
|
12
|
+
require 'google_chart_ssl'
|
13
|
+
use GoogleChartSsl
|
14
|
+
|
15
|
+
Or, if you are using Bundler, just add this to your Gemfile:
|
16
|
+
|
17
|
+
gem 'google_chart_ssl'
|
18
|
+
|
19
|
+
To use GoogleChartSSL in your Rails application, add the following line to your application config file (config/application.rb for Rails3, config/environment.rb for Rails2):
|
20
|
+
|
21
|
+
config.middleware.use GoogleChartSsl
|
22
|
+
|
23
|
+
Now, instead of making your chart request to chart.apis.google.com/chart, just send that request to /google_chart will be forwarded to google and returned over your server's connection.
|
24
|
+
|
25
|
+
|
26
|
+
== Example
|
27
|
+
|
28
|
+
<img src="http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World">
|
29
|
+
|
30
|
+
becomes:
|
31
|
+
|
32
|
+
<img src="/google_chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World">
|
33
|
+
|
34
|
+
|
35
|
+
== TODO
|
36
|
+
|
37
|
+
* Automatically insert a view helper in Rails
|
38
|
+
|
39
|
+
|
40
|
+
== Credits
|
41
|
+
|
42
|
+
* Project layout provided by Bundler.
|
43
|
+
* test setup, and this README file inspired by Tobias Matthies' Rack::SslEnforcer
|
44
|
+
|
45
|
+
|
46
|
+
== Note on Patches/Pull Requests
|
47
|
+
|
48
|
+
* Fork the project.
|
49
|
+
* Make your feature addition or bug fix.
|
50
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
51
|
+
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
52
|
+
* Send me a pull request. Bonus points for topic branches.
|
53
|
+
|
54
|
+
|
55
|
+
== Copyright
|
56
|
+
|
57
|
+
Copyright (c) 2011 Michael Gee. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Autotest.add_discovery { "testunit" }
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Autotest::Testunit < Autotest
|
2
|
+
def initialize
|
3
|
+
super
|
4
|
+
|
5
|
+
@test_mappings = {
|
6
|
+
%r[^test/.*\_test.rb$] => proc { |filename, _|
|
7
|
+
filename
|
8
|
+
},
|
9
|
+
%r[^lib/(.*)\.rb$] => proc { |_, m|
|
10
|
+
"test/#{m[1]}_test.rb"
|
11
|
+
},
|
12
|
+
%r[^test/helper.rb$] => proc {
|
13
|
+
files_matching %r[^test/.*_test\.rb$]
|
14
|
+
},
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
# Given the string filename as the path, determine
|
19
|
+
# the corresponding tests for it, in an array.
|
20
|
+
def tests_for_file(filename)
|
21
|
+
super.select { |f| @files.has_key? f }
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "google_chart_ssl/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "google_chart_ssl"
|
7
|
+
s.version = GoogleChartSsl::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Michael Gee"]
|
10
|
+
s.email = ["michaelpgee@gmail.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Indirectly serve Google Charts through your SSL connection}
|
13
|
+
s.description = %q{Including Google Charts in your SSL-protected site causes warnings about 'Mixed Content' (particularly in Internet Explorer). This Rack middleware allows you to point those img tags at a local path instead of Google. The image is retreived by your server then delivered to your client over your SSL connection.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "google_chart_ssl"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = [] # `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_development_dependency 'bundler'
|
23
|
+
s.add_development_dependency 'rake'
|
24
|
+
s.add_development_dependency 'test-unit'
|
25
|
+
s.add_development_dependency 'rack'
|
26
|
+
s.add_development_dependency 'rack-test'
|
27
|
+
s.add_development_dependency 'fakeweb'
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
class GoogleChartSsl
|
4
|
+
|
5
|
+
def initialize(app, options = {})
|
6
|
+
@app, @options = app, options
|
7
|
+
end
|
8
|
+
|
9
|
+
Google = Net::HTTP.new('chart.apis.google.com', 80)
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
@req = Rack::Request.new(env)
|
13
|
+
if @req.path == '/google_chart' or @req.path == '/google_chart.png'
|
14
|
+
path = '/chart?' + @req.query_string
|
15
|
+
resp = Google.request(Net::HTTP::Get.new(path))
|
16
|
+
headers = {
|
17
|
+
'Content-Length' => resp.content_length.to_s,
|
18
|
+
'Content-Type' => resp.content_type,
|
19
|
+
}
|
20
|
+
[resp.code, headers, [resp.body]]
|
21
|
+
else
|
22
|
+
@app.call(env)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path('../helper', __FILE__)
|
2
|
+
|
3
|
+
class GoogleChartSslTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_regular_requests_go_to_the_main_application
|
6
|
+
get '/hello'
|
7
|
+
assert_equal 200, last_response.status
|
8
|
+
assert_equal 'text/html', last_response.headers['Content-Type']
|
9
|
+
assert_equal 'Hello world!', last_response.body
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_requsts_to_our_path_go_to_google
|
13
|
+
get '/google_chart'
|
14
|
+
assert_equal 200, last_response.status
|
15
|
+
assert_equal 'image/png', last_response.headers['Content-Type']
|
16
|
+
assert_equal '20', last_response.headers['Content-Length']
|
17
|
+
assert_equal 'some binary PNG data', last_response.body
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_requsts_with_a_png_extension_work_too
|
21
|
+
get '/google_chart.png'
|
22
|
+
assert_equal 200, last_response.status
|
23
|
+
assert_equal 'image/png', last_response.headers['Content-Type']
|
24
|
+
assert_equal '20', last_response.headers['Content-Length']
|
25
|
+
assert_equal 'some binary PNG data', last_response.body
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_the_query_string_is_passed_to_google
|
29
|
+
get '/google_chart?chs=50x20'
|
30
|
+
assert_equal 200, last_response.status
|
31
|
+
assert_equal 'image/png', last_response.headers['Content-Type']
|
32
|
+
assert_equal '24', last_response.headers['Content-Length']
|
33
|
+
assert_equal 'a 50px by 20px PNG image', last_response.body
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rack/mock'
|
3
|
+
require 'rack/test'
|
4
|
+
require 'fake_web'
|
5
|
+
require 'google_chart_ssl'
|
6
|
+
|
7
|
+
class Test::Unit::TestCase
|
8
|
+
include Rack::Test::Methods
|
9
|
+
|
10
|
+
FakeWeb.allow_net_connect = false
|
11
|
+
|
12
|
+
FakeWeb.register_uri(:get, 'http://chart.apis.google.com/chart?chs=50x20',
|
13
|
+
:body => 'a 50px by 20px PNG image',
|
14
|
+
:content_length => 24,
|
15
|
+
:content_type => 'image/png')
|
16
|
+
|
17
|
+
FakeWeb.register_uri(:get, %r{\Ahttp://chart.apis.google.com},
|
18
|
+
:body => 'some binary PNG data',
|
19
|
+
:content_length => 20,
|
20
|
+
:content_type => 'image/png')
|
21
|
+
|
22
|
+
def app
|
23
|
+
@app ||= Rack::Builder.app do
|
24
|
+
use Rack::Lint
|
25
|
+
use GoogleChartSsl
|
26
|
+
run lambda {|env| [200, {'Content-Type' => "text/html"}, ['Hello world!']]}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: google_chart_ssl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Michael Gee
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-04 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: bundler
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rake
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: test-unit
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rack
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :development
|
76
|
+
version_requirements: *id004
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: rack-test
|
79
|
+
prerelease: false
|
80
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
type: :development
|
90
|
+
version_requirements: *id005
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: fakeweb
|
93
|
+
prerelease: false
|
94
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
type: :development
|
104
|
+
version_requirements: *id006
|
105
|
+
description: Including Google Charts in your SSL-protected site causes warnings about 'Mixed Content' (particularly in Internet Explorer). This Rack middleware allows you to point those img tags at a local path instead of Google. The image is retreived by your server then delivered to your client over your SSL connection.
|
106
|
+
email:
|
107
|
+
- michaelpgee@gmail.com
|
108
|
+
executables: []
|
109
|
+
|
110
|
+
extensions: []
|
111
|
+
|
112
|
+
extra_rdoc_files: []
|
113
|
+
|
114
|
+
files:
|
115
|
+
- .gitignore
|
116
|
+
- Gemfile
|
117
|
+
- LICENSE
|
118
|
+
- README.rdoc
|
119
|
+
- Rakefile
|
120
|
+
- autotest/discover.rb
|
121
|
+
- autotest/testunit.rb
|
122
|
+
- google_chart_ssl.gemspec
|
123
|
+
- lib/google_chart_ssl.rb
|
124
|
+
- lib/google_chart_ssl/version.rb
|
125
|
+
- test/google_chart_ssl_test.rb
|
126
|
+
- test/helper.rb
|
127
|
+
has_rdoc: true
|
128
|
+
homepage: ""
|
129
|
+
licenses: []
|
130
|
+
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
hash: 3
|
142
|
+
segments:
|
143
|
+
- 0
|
144
|
+
version: "0"
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
none: false
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
hash: 3
|
151
|
+
segments:
|
152
|
+
- 0
|
153
|
+
version: "0"
|
154
|
+
requirements: []
|
155
|
+
|
156
|
+
rubyforge_project: google_chart_ssl
|
157
|
+
rubygems_version: 1.6.2
|
158
|
+
signing_key:
|
159
|
+
specification_version: 3
|
160
|
+
summary: Indirectly serve Google Charts through your SSL connection
|
161
|
+
test_files:
|
162
|
+
- test/google_chart_ssl_test.rb
|
163
|
+
- test/helper.rb
|