onebox 1.5.16 → 1.5.17
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.
- checksums.yaml +4 -4
- data/lib/onebox/engine.rb +3 -3
- data/lib/onebox/engine/google_maps_onebox.rb +176 -0
- data/lib/onebox/engine/standard_embed.rb +3 -1
- data/lib/onebox/engine/whitelisted_generic_onebox.rb +2 -1
- data/lib/onebox/helpers.rb +4 -0
- data/lib/onebox/version.rb +1 -1
- data/spec/lib/onebox/engine/google_maps_onebox_spec.rb +70 -0
- metadata +48 -47
- data/lib/onebox/engine/classic_google_maps_onebox.rb +0 -62
- data/spec/lib/onebox/engine/classic_google_maps_onebox_spec.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 451ff8d5ee7ce3d3c3fdeffca55cccba29cdb91c
|
4
|
+
data.tar.gz: 83033812a9b67dd10048cfe72896c5b315e2d5da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a76b282e64d1191b6e7ddd4dc2f8a2b8f30c6f10f409a12ee71d3e794005c6cba66f26d315aec092e05ceb6bc586af6afe2c08ea29ba14000ebb4afd330992c6
|
7
|
+
data.tar.gz: 10faeefda12d96758903bbb6f11e1bfc2462a4f73e6be19466e1b6f3030d3eeb93ca2b0ceb9e7d74114fc0f04e25b5f272b24efc47125dce3b88027280f826a8
|
data/lib/onebox/engine.rb
CHANGED
@@ -123,12 +123,14 @@ require_relative "engine/standard_embed"
|
|
123
123
|
require_relative "engine/html"
|
124
124
|
require_relative "engine/json"
|
125
125
|
require_relative "engine/amazon_onebox"
|
126
|
-
require_relative "engine/classic_google_maps_onebox"
|
127
126
|
require_relative "engine/github_issue_onebox"
|
128
127
|
require_relative "engine/github_blob_onebox"
|
129
128
|
require_relative "engine/github_commit_onebox"
|
130
129
|
require_relative "engine/github_gist_onebox"
|
131
130
|
require_relative "engine/github_pullrequest_onebox"
|
131
|
+
require_relative "engine/google_calendar_onebox"
|
132
|
+
require_relative "engine/google_docs_onebox"
|
133
|
+
require_relative "engine/google_maps_onebox"
|
132
134
|
require_relative "engine/google_play_app_onebox"
|
133
135
|
require_relative "engine/image_onebox"
|
134
136
|
require_relative "engine/video_onebox"
|
@@ -141,5 +143,3 @@ require_relative "engine/youku_onebox"
|
|
141
143
|
require_relative "engine/douban_onebox"
|
142
144
|
require_relative "engine/whitelisted_generic_onebox"
|
143
145
|
require_relative "engine/pubmed_onebox"
|
144
|
-
require_relative "engine/google_calendar_onebox"
|
145
|
-
require_relative "engine/google_docs_onebox"
|
@@ -0,0 +1,176 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class GoogleMapsOnebox
|
4
|
+
include Engine
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def ===(other)
|
8
|
+
if other.kind_of? URI
|
9
|
+
@@matchers && @@matchers.any? {|m| other.to_s =~ m[:regexp] }
|
10
|
+
else
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def matches_regexp(key, regexp)
|
18
|
+
(@@matchers ||= []) << {key: key, regexp: regexp}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Matches shortened Google Maps URLs
|
23
|
+
matches_regexp :short, %r"^(https?:)?//goo\.gl/maps/"
|
24
|
+
|
25
|
+
# Matches URLs for custom-created maps
|
26
|
+
matches_regexp :custom, %r"^(?:https?:)?//www\.google(?:\.(?:\w{2,}))+/maps/d/(?:edit|viewer|embed)\?mid=.+$"
|
27
|
+
|
28
|
+
# Matches URLs with streetview data
|
29
|
+
matches_regexp :streetview, %r"^(?:https?:)?//www\.google(?:\.(?:\w{2,}))+/maps[^@]+@(?<lon>[\d.]+),(?<lat>[\d.]+),(?:\d+)a,(?<zoom>[\d.]+)y,(?<heading>[\d.]+)h,(?<pitch>[\d.]+)t.+?data=.*?!1s(?<pano>[^!]{22})"
|
30
|
+
|
31
|
+
# Matches "normal" Google Maps URLs with arbitrary data
|
32
|
+
matches_regexp :standard, %r"^(?:https?:)?//www\.google(?:\.(?:\w{2,}))+/maps"
|
33
|
+
|
34
|
+
# Matches URLs for the old Google Maps domain which we occasionally get redirected to
|
35
|
+
matches_regexp :canonical, %r"^(?:https?:)?//maps\.google(?:\.(?:\w{2,}))+/maps\?"
|
36
|
+
|
37
|
+
def initialize(url, cache = nil, timeout = nil)
|
38
|
+
super
|
39
|
+
resolve_url!
|
40
|
+
rescue Net::HTTPServerException, Timeout::Error, Net::HTTPError, Errno::ECONNREFUSED, RuntimeError => err
|
41
|
+
raise ArgumentError, "malformed url or unresolveable: #{err.message}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def streetview?
|
45
|
+
!!@streetview
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_html
|
49
|
+
Helpers.click_to_scroll_div + "<iframe src=\"#{link}\" width=\"690\" height=\"400\" frameborder=\"0\" style=\"border:0\"></iframe>"
|
50
|
+
end
|
51
|
+
|
52
|
+
def placeholder_html
|
53
|
+
width = @placeholder_width || 690
|
54
|
+
height = @placeholder_height || 400
|
55
|
+
"<img src=\"#{CGI.escapeHTML(@placeholder)}\" width=\"#{width}\" height=\"#{height}\"/>"
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def data
|
61
|
+
{ link: url, title: url }
|
62
|
+
end
|
63
|
+
|
64
|
+
def resolve_url!
|
65
|
+
@streetview = false
|
66
|
+
type, match = match_url
|
67
|
+
|
68
|
+
# Resolve shortened URL, if necessary
|
69
|
+
if type == :short
|
70
|
+
follow_redirect!
|
71
|
+
type, match = match_url
|
72
|
+
end
|
73
|
+
|
74
|
+
# Try to get the old-maps URI, it is far easier to embed.
|
75
|
+
if type == :standard
|
76
|
+
retry_count = 10
|
77
|
+
while (retry_count -= 1) > 0
|
78
|
+
follow_redirect!
|
79
|
+
type, match = match_url
|
80
|
+
break if type != :standard
|
81
|
+
sleep 0.1
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
case type
|
86
|
+
when :standard
|
87
|
+
# Fallback for map URLs that don't resolve into an easily embeddable old-style URI
|
88
|
+
# Roadmaps use a "z" zoomlevel, satellite maps use "m" the horizontal width in meters
|
89
|
+
# TODO: tilted satellite maps using "a,y,t"
|
90
|
+
match = @url.match(/@(?<lon>[\d.-]+),(?<lat>[\d.-]+),(?<zoom>\d+)(?<mz>[mz])/)
|
91
|
+
raise "unexpected standard url #{@url}" unless match
|
92
|
+
zoom = match[:mz] == "z" ? match[:zoom] : Math.log2(57280048.0 / match[:zoom].to_f).round
|
93
|
+
location = "#{match[:lon]},#{match[:lat]}"
|
94
|
+
url = "https://maps.google.com/maps?ll=#{location}&z=#{zoom}&output=embed&dg=ntvb"
|
95
|
+
url += "&q=#{$1}" if match = @url.match(/\/place\/([^\/\?]+)/)
|
96
|
+
url += "&cid=#{($1 + $2).to_i(16)}" if @url.match(/!3m1!1s0x(\h{16}):0x(\h{16})/)
|
97
|
+
@url = url
|
98
|
+
@placeholder = "http://maps.googleapis.com/maps/api/staticmap?maptype=roadmap¢er=#{location}&zoom=#{zoom}&size=690x400&sensor=false"
|
99
|
+
|
100
|
+
when :custom
|
101
|
+
url = @url.dup
|
102
|
+
@url = rewrite_custom_url(url, "embed")
|
103
|
+
@placeholder = rewrite_custom_url(url, "thumbnail")
|
104
|
+
@placeholder_height = @placeholder_width = 120
|
105
|
+
|
106
|
+
when :streetview
|
107
|
+
@streetview = true
|
108
|
+
panoid = match[:pano]
|
109
|
+
lon = match[:lon].to_f.to_s
|
110
|
+
lat = match[:lat].to_f.to_s
|
111
|
+
heading = match[:heading].to_f.round(4).to_s
|
112
|
+
pitch = (match[:pitch].to_f / 10.0).round(4).to_s
|
113
|
+
fov = (match[:zoom].to_f / 100.0).round(4).to_s
|
114
|
+
zoom = match[:zoom].to_f.round
|
115
|
+
@url = "https://www.google.com/maps/embed?pb=!3m2!2sen!4v0!6m8!1m7!1s#{panoid}!2m2!1d#{lon}!2d#{lat}!3f#{heading}!4f#{pitch}!5f#{fov}"
|
116
|
+
@placeholder = "http://maps.googleapis.com/maps/api/streetview?size=690x400&location=#{lon},#{lat}&pano=#{panoid}&fov=#{zoom}&heading=#{heading}&pitch=#{pitch}&sensor=false"
|
117
|
+
|
118
|
+
when :canonical
|
119
|
+
uri = URI(@url)
|
120
|
+
query = Hash[*uri.query.split("&").map{|a|a.split("=")}.flatten]
|
121
|
+
if !query.has_key?("ll")
|
122
|
+
raise ArgumentError, "canonical url lacks location argument" unless query.has_key?("sll")
|
123
|
+
query["ll"] = query["sll"]
|
124
|
+
@url += "&ll=#{query["sll"]}"
|
125
|
+
end
|
126
|
+
location = query["ll"]
|
127
|
+
if !query.has_key?("z")
|
128
|
+
raise ArgumentError, "canonical url has incomplete query arguments" unless query.has_key?("spn") || query.has_key?("sspn")
|
129
|
+
if !query.has_key?("spn")
|
130
|
+
query["spn"] = query["sspn"]
|
131
|
+
@url += "&spn=#{query["sspn"]}"
|
132
|
+
end
|
133
|
+
angle = query["spn"].split(",").first.to_f
|
134
|
+
zoom = (Math.log(690.0 * 360.0 / angle / 256.0) / Math.log(2)).round
|
135
|
+
else
|
136
|
+
zoom = query["z"]
|
137
|
+
end
|
138
|
+
@url = @url.sub('output=classic', 'output=embed')
|
139
|
+
@placeholder = "http://maps.googleapis.com/maps/api/staticmap?maptype=roadmap&size=690x400&sensor=false¢er=#{location}&zoom=#{zoom}"
|
140
|
+
|
141
|
+
else
|
142
|
+
raise "unexpected url type #{type.inspect}"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def match_url
|
147
|
+
@@matchers.each do |matcher|
|
148
|
+
if m = matcher[:regexp].match(@url)
|
149
|
+
return matcher[:key], m
|
150
|
+
end
|
151
|
+
end
|
152
|
+
raise ArgumentError, "\"#{@url}\" does not match any known pattern"
|
153
|
+
end
|
154
|
+
|
155
|
+
def rewrite_custom_url(url, target)
|
156
|
+
uri = URI(url)
|
157
|
+
uri.path = uri.path.sub(/(?<=^\/maps\/d\/)\w+$/, target)
|
158
|
+
uri.to_s
|
159
|
+
end
|
160
|
+
|
161
|
+
def follow_redirect!
|
162
|
+
uri = URI(@url)
|
163
|
+
begin
|
164
|
+
http = Net::HTTP.start(uri.host, uri.port,
|
165
|
+
use_ssl: uri.scheme == 'https', open_timeout: timeout, read_timeout: timeout)
|
166
|
+
response = http.head(uri.path)
|
167
|
+
raise "unexpected response code #{response.code}" unless %w(301 302).include?(response.code)
|
168
|
+
@url = response["Location"]
|
169
|
+
ensure
|
170
|
+
http.finish rescue nil
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
@@ -19,9 +19,11 @@ module Onebox
|
|
19
19
|
end
|
20
20
|
|
21
21
|
# Some oembed providers (like meetup.com) don't provide links to themselves
|
22
|
-
add_oembed_provider /www\.
|
22
|
+
add_oembed_provider /www\.flickr\.com\//, 'http://www.flickr.com/services/oembed.json'
|
23
23
|
add_oembed_provider /www\.kickstarter\.com\//, 'https://www.kickstarter.com/services/oembed'
|
24
|
+
add_oembed_provider /www\.meetup\.com\//, 'http://api.meetup.com/oembed'
|
24
25
|
add_oembed_provider /www\.ted\.com\//, 'http://www.ted.com/services/v1/oembed.json'
|
26
|
+
add_oembed_provider /(.*\.)?vimeo\.com\//, 'http://vimeo.com/api/oembed.json'
|
25
27
|
|
26
28
|
# Sites that work better with OpenGraph
|
27
29
|
add_opengraph_provider /gfycat\.com\//
|
@@ -62,6 +62,7 @@ module Onebox
|
|
62
62
|
hulu.com
|
63
63
|
ign.com
|
64
64
|
ikea.com
|
65
|
+
imdb.com
|
65
66
|
imgur.com
|
66
67
|
indiatimes.com
|
67
68
|
instagr.am
|
@@ -131,7 +132,7 @@ module Onebox
|
|
131
132
|
# include the entire page HTML. However for some providers like Imgur it allows us
|
132
133
|
# to return gifv and galleries.
|
133
134
|
def self.default_html_providers
|
134
|
-
['Imgur', 'Meetup']
|
135
|
+
['Flickr', 'Imgur', 'Meetup']
|
135
136
|
end
|
136
137
|
|
137
138
|
def self.html_providers
|
data/lib/onebox/helpers.rb
CHANGED
@@ -51,5 +51,9 @@ module Onebox
|
|
51
51
|
response.error!
|
52
52
|
end
|
53
53
|
end
|
54
|
+
|
55
|
+
def self.click_to_scroll_div(width = 690, height = 400)
|
56
|
+
"<div style=\"background:transparent;position:relative;width:#{width}px;height:#{height}px;top:#{height}px;margin-top:-#{height}px;\" onClick=\"style.pointerEvents='none'\"></div>"
|
57
|
+
end
|
54
58
|
end
|
55
59
|
end
|
data/lib/onebox/version.rb
CHANGED
@@ -0,0 +1,70 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Onebox::Engine::GoogleMapsOnebox do
|
4
|
+
|
5
|
+
URLS = {
|
6
|
+
short: {
|
7
|
+
test: "https://goo.gl/maps/rEG3D",
|
8
|
+
redirect: ["302 Found", :long],
|
9
|
+
expect: "https://maps.google.de/maps?sll=40.689249,-74.0445&sspn=0.0062479,0.0109864&cid=4667599994556318251&q=Statue+of+Liberty+National+Monument&output=embed&dg=ntvb&ll=40.689249,-74.0445&spn=0.0062479,0.0109864",
|
10
|
+
},
|
11
|
+
long: {
|
12
|
+
test: "https://www.google.de/maps/place/Statue+of+Liberty+National+Monument/@40.689249,-74.0445,17z/data=!3m1!4b1!4m2!3m1!1s0x89c25090129c363d:0x40c6a5770d25022b",
|
13
|
+
redirect: ["301 Moved Permanently", :canonical],
|
14
|
+
expect: "https://maps.google.de/maps?sll=40.689249,-74.0445&sspn=0.0062479,0.0109864&cid=4667599994556318251&q=Statue+of+Liberty+National+Monument&output=embed&dg=ntvb&ll=40.689249,-74.0445&spn=0.0062479,0.0109864",
|
15
|
+
},
|
16
|
+
canonical: {
|
17
|
+
test: "https://maps.google.de/maps?sll=40.689249,-74.0445&sspn=0.0062479,0.0109864&cid=4667599994556318251&q=Statue+of+Liberty+National+Monument&output=classic&dg=ntvb",
|
18
|
+
expect: "https://maps.google.de/maps?sll=40.689249,-74.0445&sspn=0.0062479,0.0109864&cid=4667599994556318251&q=Statue+of+Liberty+National+Monument&output=embed&dg=ntvb&ll=40.689249,-74.0445&spn=0.0062479,0.0109864",
|
19
|
+
},
|
20
|
+
custom: {
|
21
|
+
test: "https://www.google.com/maps/d/edit?mid=zPYyZFrHi1MU.kX85W_Y2y2_E",
|
22
|
+
expect: "https://www.google.com/maps/d/embed?mid=zPYyZFrHi1MU.kX85W_Y2y2_E",
|
23
|
+
},
|
24
|
+
streetview: {
|
25
|
+
test: "https://www.google.com/maps/@46.414384,10.013947,3a,75y,232.83h,99.08t/data=!3m5!1e1!3m3!1s9WgYUb5quXDjqqFd3DWI6A!2e0!3e5?hl=de",
|
26
|
+
expect: "https://www.google.com/maps/embed?pb=!3m2!2sen!4v0!6m8!1m7!1s9WgYUb5quXDjqqFd3DWI6A!2m2!1d46.414384!2d10.013947!3f232.83!4f9.908!5f0.75",
|
27
|
+
streetview: true
|
28
|
+
},
|
29
|
+
unresolveable: {
|
30
|
+
test: "https://www.google.com/maps/place/Den+Abattoir/@51.2285173,4.4336702,17z/data=!4m7!1m4!3m3!1s0x47c3f7a5ac48e237:0x63d716018f584a33!2zUGnDqXRyYWlu!3b1!3m1!1s0x0000000000000000:0xfbfac0c41c32471a",
|
31
|
+
redirect: ["302 Found", "https://www.google.com/maps/place/Den+Abattoir/@51.2285173,4.4336702,17z/data=!4m7!1m4!3m3!1s0x47c3f7a5ac48e237:0x63d716018f584a33!2zUGnDqXRyYWlu!3b1!3m1!1s0x0000000000000000:0xfbfac0c41c32471a?dg=dbrw&newdg=1"],
|
32
|
+
expect: "https://maps.google.com/maps?ll=51.2285173,4.4336702&z=17&output=embed&dg=ntvb&q=Den+Abattoir&cid=18157036796216755994"
|
33
|
+
},
|
34
|
+
satellite: {
|
35
|
+
test: "https://www.google.de/maps/@40.6894264,-74.0449146,758m/data=!3m1!1e3",
|
36
|
+
redirect: ["302 Found", "https://www.google.de/maps/@40.6894264,-74.0449146,758m/data=!3m1!1e3?dg=dbrw&newdg=1"],
|
37
|
+
expect: "https://maps.google.com/maps?ll=40.6894264,-74.0449146&z=16&output=embed&dg=ntvb"
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
# Register URL redirects
|
42
|
+
before(:all) do
|
43
|
+
URLS.values.each do |t|
|
44
|
+
status, location = *t[:redirect]
|
45
|
+
location = URLS[location][:test] if location.is_a? Symbol
|
46
|
+
FakeWeb.register_uri(:head, t[:test], response: "HTTP/1.1 #{status}\nLocation: #{location}\n\n")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Prevent sleep from wasting our time when we test with strange redirects
|
51
|
+
subject { described_class.send(:allocate).tap {|obj|
|
52
|
+
obj.stub(:sleep)
|
53
|
+
obj.send(:initialize, link)
|
54
|
+
}}
|
55
|
+
|
56
|
+
let(:data) { Onebox::Helpers.symbolize_keys(subject.send(:data)) }
|
57
|
+
let(:link) {|example| URLS[example.metadata[:urltype] || :short][:test] }
|
58
|
+
|
59
|
+
include_context "an engine", urltype: :short
|
60
|
+
|
61
|
+
URLS.each do |kind, t|
|
62
|
+
it "processes #{kind.to_s} url correctly", urltype: kind do
|
63
|
+
expect(subject.url).to eq t[:expect]
|
64
|
+
expect(subject.streetview?).to t[:streetview] ? be_truthy : be_falsey
|
65
|
+
expect(subject.to_html).to include("<iframe")
|
66
|
+
expect(subject.placeholder_html).to include("<img")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onebox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joanna Zeta
|
@@ -10,244 +10,244 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-05-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multi_json
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '1.7'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - ~>
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '1.7'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: mustache
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
|
-
- -
|
33
|
+
- - ~>
|
34
34
|
- !ruby/object:Gem::Version
|
35
35
|
version: '0.99'
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
|
-
- -
|
40
|
+
- - ~>
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '0.99'
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: nokogiri
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- -
|
47
|
+
- - ~>
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: 1.6.1
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- -
|
54
|
+
- - ~>
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: 1.6.1
|
57
57
|
- !ruby/object:Gem::Dependency
|
58
58
|
name: moneta
|
59
59
|
requirement: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
|
-
- -
|
61
|
+
- - ~>
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: '0.7'
|
64
64
|
type: :runtime
|
65
65
|
prerelease: false
|
66
66
|
version_requirements: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
|
-
- -
|
68
|
+
- - ~>
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '0.7'
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: bundler
|
73
73
|
requirement: !ruby/object:Gem::Requirement
|
74
74
|
requirements:
|
75
|
-
- -
|
75
|
+
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '1.3'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
80
|
version_requirements: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
|
-
- -
|
82
|
+
- - ~>
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '1.3'
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
86
|
name: rake
|
87
87
|
requirement: !ruby/object:Gem::Requirement
|
88
88
|
requirements:
|
89
|
-
- -
|
89
|
+
- - ~>
|
90
90
|
- !ruby/object:Gem::Version
|
91
91
|
version: '10.0'
|
92
92
|
type: :development
|
93
93
|
prerelease: false
|
94
94
|
version_requirements: !ruby/object:Gem::Requirement
|
95
95
|
requirements:
|
96
|
-
- -
|
96
|
+
- - ~>
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '10.0'
|
99
99
|
- !ruby/object:Gem::Dependency
|
100
100
|
name: rspec
|
101
101
|
requirement: !ruby/object:Gem::Requirement
|
102
102
|
requirements:
|
103
|
-
- -
|
103
|
+
- - ~>
|
104
104
|
- !ruby/object:Gem::Version
|
105
105
|
version: '2.14'
|
106
106
|
type: :development
|
107
107
|
prerelease: false
|
108
108
|
version_requirements: !ruby/object:Gem::Requirement
|
109
109
|
requirements:
|
110
|
-
- -
|
110
|
+
- - ~>
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: '2.14'
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: yard
|
115
115
|
requirement: !ruby/object:Gem::Requirement
|
116
116
|
requirements:
|
117
|
-
- -
|
117
|
+
- - ~>
|
118
118
|
- !ruby/object:Gem::Version
|
119
119
|
version: '0.8'
|
120
120
|
type: :development
|
121
121
|
prerelease: false
|
122
122
|
version_requirements: !ruby/object:Gem::Requirement
|
123
123
|
requirements:
|
124
|
-
- -
|
124
|
+
- - ~>
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: '0.8'
|
127
127
|
- !ruby/object:Gem::Dependency
|
128
128
|
name: fakeweb
|
129
129
|
requirement: !ruby/object:Gem::Requirement
|
130
130
|
requirements:
|
131
|
-
- -
|
131
|
+
- - ~>
|
132
132
|
- !ruby/object:Gem::Version
|
133
133
|
version: '1.3'
|
134
134
|
type: :development
|
135
135
|
prerelease: false
|
136
136
|
version_requirements: !ruby/object:Gem::Requirement
|
137
137
|
requirements:
|
138
|
-
- -
|
138
|
+
- - ~>
|
139
139
|
- !ruby/object:Gem::Version
|
140
140
|
version: '1.3'
|
141
141
|
- !ruby/object:Gem::Dependency
|
142
142
|
name: pry
|
143
143
|
requirement: !ruby/object:Gem::Requirement
|
144
144
|
requirements:
|
145
|
-
- -
|
145
|
+
- - ~>
|
146
146
|
- !ruby/object:Gem::Version
|
147
147
|
version: '0.9'
|
148
148
|
type: :development
|
149
149
|
prerelease: false
|
150
150
|
version_requirements: !ruby/object:Gem::Requirement
|
151
151
|
requirements:
|
152
|
-
- -
|
152
|
+
- - ~>
|
153
153
|
- !ruby/object:Gem::Version
|
154
154
|
version: '0.9'
|
155
155
|
- !ruby/object:Gem::Dependency
|
156
156
|
name: mocha
|
157
157
|
requirement: !ruby/object:Gem::Requirement
|
158
158
|
requirements:
|
159
|
-
- -
|
159
|
+
- - ~>
|
160
160
|
- !ruby/object:Gem::Version
|
161
161
|
version: '0.14'
|
162
162
|
type: :development
|
163
163
|
prerelease: false
|
164
164
|
version_requirements: !ruby/object:Gem::Requirement
|
165
165
|
requirements:
|
166
|
-
- -
|
166
|
+
- - ~>
|
167
167
|
- !ruby/object:Gem::Version
|
168
168
|
version: '0.14'
|
169
169
|
- !ruby/object:Gem::Dependency
|
170
170
|
name: rubocop
|
171
171
|
requirement: !ruby/object:Gem::Requirement
|
172
172
|
requirements:
|
173
|
-
- -
|
173
|
+
- - ~>
|
174
174
|
- !ruby/object:Gem::Version
|
175
175
|
version: '0.11'
|
176
176
|
type: :development
|
177
177
|
prerelease: false
|
178
178
|
version_requirements: !ruby/object:Gem::Requirement
|
179
179
|
requirements:
|
180
|
-
- -
|
180
|
+
- - ~>
|
181
181
|
- !ruby/object:Gem::Version
|
182
182
|
version: '0.11'
|
183
183
|
- !ruby/object:Gem::Dependency
|
184
184
|
name: twitter
|
185
185
|
requirement: !ruby/object:Gem::Requirement
|
186
186
|
requirements:
|
187
|
-
- -
|
187
|
+
- - ~>
|
188
188
|
- !ruby/object:Gem::Version
|
189
189
|
version: '4.8'
|
190
190
|
type: :development
|
191
191
|
prerelease: false
|
192
192
|
version_requirements: !ruby/object:Gem::Requirement
|
193
193
|
requirements:
|
194
|
-
- -
|
194
|
+
- - ~>
|
195
195
|
- !ruby/object:Gem::Version
|
196
196
|
version: '4.8'
|
197
197
|
- !ruby/object:Gem::Dependency
|
198
198
|
name: guard-rspec
|
199
199
|
requirement: !ruby/object:Gem::Requirement
|
200
200
|
requirements:
|
201
|
-
- -
|
201
|
+
- - ~>
|
202
202
|
- !ruby/object:Gem::Version
|
203
203
|
version: 4.2.8
|
204
204
|
type: :development
|
205
205
|
prerelease: false
|
206
206
|
version_requirements: !ruby/object:Gem::Requirement
|
207
207
|
requirements:
|
208
|
-
- -
|
208
|
+
- - ~>
|
209
209
|
- !ruby/object:Gem::Version
|
210
210
|
version: 4.2.8
|
211
211
|
- !ruby/object:Gem::Dependency
|
212
212
|
name: sinatra
|
213
213
|
requirement: !ruby/object:Gem::Requirement
|
214
214
|
requirements:
|
215
|
-
- -
|
215
|
+
- - ~>
|
216
216
|
- !ruby/object:Gem::Version
|
217
217
|
version: '1.4'
|
218
218
|
type: :development
|
219
219
|
prerelease: false
|
220
220
|
version_requirements: !ruby/object:Gem::Requirement
|
221
221
|
requirements:
|
222
|
-
- -
|
222
|
+
- - ~>
|
223
223
|
- !ruby/object:Gem::Version
|
224
224
|
version: '1.4'
|
225
225
|
- !ruby/object:Gem::Dependency
|
226
226
|
name: sinatra-contrib
|
227
227
|
requirement: !ruby/object:Gem::Requirement
|
228
228
|
requirements:
|
229
|
-
- -
|
229
|
+
- - ~>
|
230
230
|
- !ruby/object:Gem::Version
|
231
231
|
version: '1.4'
|
232
232
|
type: :development
|
233
233
|
prerelease: false
|
234
234
|
version_requirements: !ruby/object:Gem::Requirement
|
235
235
|
requirements:
|
236
|
-
- -
|
236
|
+
- - ~>
|
237
237
|
- !ruby/object:Gem::Version
|
238
238
|
version: '1.4'
|
239
239
|
- !ruby/object:Gem::Dependency
|
240
240
|
name: haml
|
241
241
|
requirement: !ruby/object:Gem::Requirement
|
242
242
|
requirements:
|
243
|
-
- -
|
243
|
+
- - ~>
|
244
244
|
- !ruby/object:Gem::Version
|
245
245
|
version: '4.0'
|
246
246
|
type: :development
|
247
247
|
prerelease: false
|
248
248
|
version_requirements: !ruby/object:Gem::Requirement
|
249
249
|
requirements:
|
250
|
-
- -
|
250
|
+
- - ~>
|
251
251
|
- !ruby/object:Gem::Version
|
252
252
|
version: '4.0'
|
253
253
|
- !ruby/object:Gem::Dependency
|
@@ -273,11 +273,11 @@ executables: []
|
|
273
273
|
extensions: []
|
274
274
|
extra_rdoc_files: []
|
275
275
|
files:
|
276
|
-
-
|
277
|
-
-
|
278
|
-
-
|
279
|
-
-
|
280
|
-
-
|
276
|
+
- .gitignore
|
277
|
+
- .rspec
|
278
|
+
- .rubocop.yml
|
279
|
+
- .ruby-gemset
|
280
|
+
- .travis.yml
|
281
281
|
- Gemfile
|
282
282
|
- Guardfile
|
283
283
|
- LICENSE.txt
|
@@ -287,7 +287,6 @@ files:
|
|
287
287
|
- lib/onebox/engine.rb
|
288
288
|
- lib/onebox/engine/amazon_onebox.rb
|
289
289
|
- lib/onebox/engine/audio_onebox.rb
|
290
|
-
- lib/onebox/engine/classic_google_maps_onebox.rb
|
291
290
|
- lib/onebox/engine/douban_onebox.rb
|
292
291
|
- lib/onebox/engine/github_blob_onebox.rb
|
293
292
|
- lib/onebox/engine/github_commit_onebox.rb
|
@@ -296,6 +295,7 @@ files:
|
|
296
295
|
- lib/onebox/engine/github_pullrequest_onebox.rb
|
297
296
|
- lib/onebox/engine/google_calendar_onebox.rb
|
298
297
|
- lib/onebox/engine/google_docs_onebox.rb
|
298
|
+
- lib/onebox/engine/google_maps_onebox.rb
|
299
299
|
- lib/onebox/engine/google_play_app_onebox.rb
|
300
300
|
- lib/onebox/engine/html.rb
|
301
301
|
- lib/onebox/engine/image_onebox.rb
|
@@ -343,13 +343,13 @@ files:
|
|
343
343
|
- spec/fixtures/youtube.response
|
344
344
|
- spec/lib/onebox/engine/amazon_onebox_spec.rb
|
345
345
|
- spec/lib/onebox/engine/audio_onebox_spec.rb
|
346
|
-
- spec/lib/onebox/engine/classic_google_maps_onebox_spec.rb
|
347
346
|
- spec/lib/onebox/engine/douban_onebox_spec.rb
|
348
347
|
- spec/lib/onebox/engine/github_blob_onebox_spec.rb
|
349
348
|
- spec/lib/onebox/engine/github_commit_onebox_spec.rb
|
350
349
|
- spec/lib/onebox/engine/github_gist_onebox_spec.rb
|
351
350
|
- spec/lib/onebox/engine/github_pullrequest_onebox_spec.rb
|
352
351
|
- spec/lib/onebox/engine/google_docs_onebox_spec.rb
|
352
|
+
- spec/lib/onebox/engine/google_maps_onebox_spec.rb
|
353
353
|
- spec/lib/onebox/engine/google_play_app_onebox_spec.rb
|
354
354
|
- spec/lib/onebox/engine/html_spec.rb
|
355
355
|
- spec/lib/onebox/engine/image_onebox_spec.rb
|
@@ -399,17 +399,17 @@ require_paths:
|
|
399
399
|
- lib
|
400
400
|
required_ruby_version: !ruby/object:Gem::Requirement
|
401
401
|
requirements:
|
402
|
-
- -
|
402
|
+
- - '>='
|
403
403
|
- !ruby/object:Gem::Version
|
404
404
|
version: '0'
|
405
405
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
406
406
|
requirements:
|
407
|
-
- -
|
407
|
+
- - '>='
|
408
408
|
- !ruby/object:Gem::Version
|
409
409
|
version: '0'
|
410
410
|
requirements: []
|
411
411
|
rubyforge_project:
|
412
|
-
rubygems_version: 2.
|
412
|
+
rubygems_version: 2.0.14
|
413
413
|
signing_key:
|
414
414
|
specification_version: 4
|
415
415
|
summary: A gem for turning URLs into previews.
|
@@ -437,13 +437,13 @@ test_files:
|
|
437
437
|
- spec/fixtures/youtube.response
|
438
438
|
- spec/lib/onebox/engine/amazon_onebox_spec.rb
|
439
439
|
- spec/lib/onebox/engine/audio_onebox_spec.rb
|
440
|
-
- spec/lib/onebox/engine/classic_google_maps_onebox_spec.rb
|
441
440
|
- spec/lib/onebox/engine/douban_onebox_spec.rb
|
442
441
|
- spec/lib/onebox/engine/github_blob_onebox_spec.rb
|
443
442
|
- spec/lib/onebox/engine/github_commit_onebox_spec.rb
|
444
443
|
- spec/lib/onebox/engine/github_gist_onebox_spec.rb
|
445
444
|
- spec/lib/onebox/engine/github_pullrequest_onebox_spec.rb
|
446
445
|
- spec/lib/onebox/engine/google_docs_onebox_spec.rb
|
446
|
+
- spec/lib/onebox/engine/google_maps_onebox_spec.rb
|
447
447
|
- spec/lib/onebox/engine/google_play_app_onebox_spec.rb
|
448
448
|
- spec/lib/onebox/engine/html_spec.rb
|
449
449
|
- spec/lib/onebox/engine/image_onebox_spec.rb
|
@@ -463,3 +463,4 @@ test_files:
|
|
463
463
|
- spec/lib/onebox_spec.rb
|
464
464
|
- spec/spec_helper.rb
|
465
465
|
- spec/support/html_spec_helper.rb
|
466
|
+
has_rdoc:
|
@@ -1,62 +0,0 @@
|
|
1
|
-
module Onebox
|
2
|
-
module Engine
|
3
|
-
class ClassicGoogleMapsOnebox
|
4
|
-
include Engine
|
5
|
-
|
6
|
-
matches_regexp /^(https?:)?\/\/((maps|www)\.google\.[\w.]{2,}|goo\.gl)\/maps?.+$/
|
7
|
-
|
8
|
-
def initialize(link, cache = nil, timeout = nil)
|
9
|
-
super(link, cache, timeout)
|
10
|
-
resolve_url!
|
11
|
-
end
|
12
|
-
|
13
|
-
def to_html
|
14
|
-
"<div style=\"background:transparent;position:relative;width:690px;height:400px;top:400px;margin-top:-400px;\" onClick=\"style.pointerEvents='none'\"></div> <iframe src=\"#{link}\" width=\"690px\" height=\"400px\" frameborder=\"0\" style=\"border:0\"></iframe>"
|
15
|
-
end
|
16
|
-
|
17
|
-
def placeholder_html
|
18
|
-
return to_html unless @placeholder
|
19
|
-
"<img src=\"http://maps.googleapis.com/maps/api/staticmap?maptype=roadmap&size=690x400&sensor=false&#{@placeholder}\" width=\"690\" height=\"400\"/>"
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def resolve_url!
|
25
|
-
@url = follow_redirect(@url) if @url.include?("//goo.gl/maps")
|
26
|
-
if m = @url.match(/@([-.\d]+,[-.\d]+),(\d+)z/)
|
27
|
-
@placeholder = "center=#{m[1]}&zoom=#{m[2]}"
|
28
|
-
end
|
29
|
-
|
30
|
-
@url = follow_redirect(@url) if @url.include?("www.google")
|
31
|
-
query = Hash[*URI(@url).query.split("&").map{|a|a.split("=")}.flatten]
|
32
|
-
@url += "&ll=#{query["sll"]}" if !query["ll"]
|
33
|
-
@url += "&spn=#{query["sspn"]}" if !query["spn"]
|
34
|
-
if !@placeholder
|
35
|
-
angle = (query["spn"] || query["sspn"]).split(",").first.to_f
|
36
|
-
zoom = (Math.log(690.0 * 360.0 / angle / 256.0) / Math.log(2)).round
|
37
|
-
@placeholder = "center=#{query["ll"] || query["sll"]}&zoom=#{zoom}"
|
38
|
-
end
|
39
|
-
|
40
|
-
@url = (@url =~ /output=classic/) ?
|
41
|
-
@url.sub('output=classic', 'output=embed') :
|
42
|
-
@url + '&output=embed'
|
43
|
-
end
|
44
|
-
|
45
|
-
def data
|
46
|
-
{link: url, title: url}
|
47
|
-
end
|
48
|
-
|
49
|
-
def follow_redirect(link)
|
50
|
-
uri = URI(link)
|
51
|
-
http = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https')
|
52
|
-
http.open_timeout = timeout
|
53
|
-
http.read_timeout = timeout
|
54
|
-
response = http.head(uri.path)
|
55
|
-
response["Location"] if %(301 302).include?(response.code)
|
56
|
-
rescue
|
57
|
-
link
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Onebox::Engine::ClassicGoogleMapsOnebox do
|
4
|
-
|
5
|
-
URLS = {
|
6
|
-
short: "https://goo.gl/maps/rEG3D",
|
7
|
-
long: "https://www.google.de/maps/place/Statue+of+Liberty+National+Monument/@40.689249,-74.0445,17z/data=!3m1!4b1!4m2!3m1!1s0x89c25090129c363d:0x40c6a5770d25022b",
|
8
|
-
canonical: "https://maps.google.de/maps?sll=40.689249,-74.0445&sspn=0.0062479,0.0109864&cid=4667599994556318251&q=Statue+of+Liberty+National+Monument&output=classic&dg=ntvb",
|
9
|
-
embed: "https://maps.google.de/maps?sll=40.689249,-74.0445&sspn=0.0062479,0.0109864&cid=4667599994556318251&q=Statue+of+Liberty+National+Monument&output=embed&dg=ntvb&ll=40.689249,-74.0445&spn=0.0062479,0.0109864"
|
10
|
-
}
|
11
|
-
|
12
|
-
before(:all) do
|
13
|
-
FakeWeb.register_uri(:head, URLS[:short], response: "HTTP/1.1 302 Found\nLocation: #{URLS[:long]}\n\n")
|
14
|
-
FakeWeb.register_uri(:head, URLS[:long], response: "HTTP/1.1 301 Moved Permanently\nLocation: #{URLS[:canonical]}\n\n")
|
15
|
-
end
|
16
|
-
|
17
|
-
subject { described_class.new(link) }
|
18
|
-
|
19
|
-
it_behaves_like "an engine" do
|
20
|
-
let(:link) { URLS[:canonical] }
|
21
|
-
let(:data) { Onebox::Helpers.symbolize_keys(subject.send(:data)) }
|
22
|
-
end
|
23
|
-
|
24
|
-
shared_examples "embeddable" do |kind|
|
25
|
-
let(:link) { URLS[kind] }
|
26
|
-
|
27
|
-
it "resolves url correctly" do
|
28
|
-
subject.url.should == URLS[:embed]
|
29
|
-
end
|
30
|
-
|
31
|
-
it "produces an iframe" do
|
32
|
-
subject.to_html.should include("iframe", "output=embed")
|
33
|
-
end
|
34
|
-
|
35
|
-
it "produces a placeholder image" do
|
36
|
-
subject.placeholder_html.should include("img")
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context "canonical url" do
|
41
|
-
it_should_behave_like "embeddable", :canonical
|
42
|
-
end
|
43
|
-
|
44
|
-
context "long url" do
|
45
|
-
it_should_behave_like "embeddable", :long
|
46
|
-
end
|
47
|
-
|
48
|
-
context "short url" do
|
49
|
-
it_should_behave_like "embeddable", :short
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|