richurls 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -1
- data/lib/body_decorator.rb +5 -0
- data/lib/parsers/favicon_parser.rb +9 -0
- data/lib/parsers/image_parser.rb +6 -29
- data/lib/parsers/provider_display_parser.rb +7 -0
- data/lib/url_helper.rb +15 -0
- data/lib/xml_handler.rb +1 -0
- data/richurls.gemspec +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2072268f21e502e956262e89d03475bed307c6f45d99d2cba65f827dec9ada7
|
4
|
+
data.tar.gz: 6711cccbf99ba51376bbd39dd8845f93d7d3030af1f9875ea3848fc8409199c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2126826dbb14433abffb4be373b30c93463c736146cceff8c4b9c855b12472c988abdf3d1aa430c9be1ad3c42204c588c00046bc6cc20acfb5b52486d1d4c13f
|
7
|
+
data.tar.gz: 20d609d8647b038b39745b7389895401d0223d3fb54d778ece204d0747f6b3ede1717b85601e721607f08a55eadf80d88bf5e1b649a9d496a628c2603411d962
|
data/README.md
CHANGED
@@ -1,2 +1,27 @@
|
|
1
1
|
# richurls
|
2
|
-
A gem which can enrich urls
|
2
|
+
A gem which can enrich urls with speed.
|
3
|
+
|
4
|
+
**Installation**
|
5
|
+
|
6
|
+
```
|
7
|
+
gem install richurls
|
8
|
+
```
|
9
|
+
|
10
|
+
**Usage:**
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
require 'richurls'
|
14
|
+
|
15
|
+
RichUrls.enrich('https://wetransfer.com')
|
16
|
+
|
17
|
+
# Returns:
|
18
|
+
# {
|
19
|
+
# "title"=>"WeTransfer",
|
20
|
+
# "description"=>"WeTransfer is the simplest way to send your files around the world",
|
21
|
+
# "image"=>"https://prod-cdn.wetransfer.net/assets/wt-facebook-568be8def5a86a09cedeb21b8f24cb208e86515a552bd07d856c7d5dfc6a23df.png",
|
22
|
+
# "provider_display"=>"https://wetransfer.com",
|
23
|
+
# "favicon"=>"https://prod-cdn.wetransfer.net/assets/favicon-d12161435ace47c6883360e08466508593325f134c1852b1d0e6e75d5f76adda.ico",
|
24
|
+
# "embed"=>nil
|
25
|
+
# }
|
26
|
+
```
|
27
|
+
|
data/lib/body_decorator.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'ox'
|
2
2
|
|
3
3
|
require_relative 'xml_handler'
|
4
|
+
require_relative 'url_helper'
|
4
5
|
require_relative 'parsers/title_parser'
|
5
6
|
require_relative 'parsers/description_parser'
|
6
7
|
require_relative 'parsers/image_parser'
|
7
8
|
require_relative 'parsers/embed_parser'
|
9
|
+
require_relative 'parsers/provider_display_parser'
|
10
|
+
require_relative 'parsers/favicon_parser'
|
8
11
|
|
9
12
|
module RichUrls
|
10
13
|
class BodyDecorator
|
@@ -14,6 +17,8 @@ module RichUrls
|
|
14
17
|
'title' => Parsers::TitleParser,
|
15
18
|
'description' => Parsers::DescriptionParser,
|
16
19
|
'image' => Parsers::ImageParser,
|
20
|
+
'provider_display' => Parsers::ProviderDisplayParser,
|
21
|
+
'favicon' => Parsers::FaviconParser,
|
17
22
|
'embed' => Parsers::EmbedParser
|
18
23
|
}.freeze
|
19
24
|
|
data/lib/parsers/image_parser.rb
CHANGED
@@ -1,37 +1,14 @@
|
|
1
1
|
module Parsers
|
2
2
|
class ImageParser
|
3
|
-
TRAILING_SLASH_REGEXP = /(\/)+$/.freeze
|
4
|
-
|
5
3
|
def self.call(document, url)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
private_class_method :new
|
10
|
-
|
11
|
-
def initialize(document, url)
|
12
|
-
@document = document
|
13
|
-
@url = url
|
14
|
-
end
|
15
|
-
|
16
|
-
def call
|
17
|
-
if image_source =~ URI::DEFAULT_PARSER.make_regexp
|
18
|
-
image_source
|
19
|
-
elsif image_source
|
20
|
-
url_no_trailing_slash = @url.sub(TRAILING_SLASH_REGEXP, '')
|
21
|
-
|
22
|
-
[url_no_trailing_slash, image_source].join('/')
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
4
|
+
meta_image = document.find {|f| f.name == :meta && f.attributes[:property] == 'og:image' }
|
5
|
+
image_tag = document.find {|f| f.name == :img }
|
27
6
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
image_tag = @document.find {|f| f.name == :img }
|
7
|
+
image_source =
|
8
|
+
(meta_image && meta_image.attributes[:content]) ||
|
9
|
+
(image_tag && image_tag.attributes[:src])
|
32
10
|
|
33
|
-
|
34
|
-
end
|
11
|
+
image_source && UrlHelper.url_for(url, image_source)
|
35
12
|
end
|
36
13
|
end
|
37
14
|
end
|
data/lib/url_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module UrlHelper
|
2
|
+
def self.url_for(domain, url)
|
3
|
+
return if url.nil?
|
4
|
+
return url if url =~ URI::DEFAULT_PARSER.make_regexp
|
5
|
+
|
6
|
+
uri = URI(domain)
|
7
|
+
base = uri.scheme + '://' + uri.host
|
8
|
+
|
9
|
+
if url.start_with?('/')
|
10
|
+
base + url
|
11
|
+
else
|
12
|
+
base + uri.path + '/' + url
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/xml_handler.rb
CHANGED
data/richurls.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: richurls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- grdw
|
@@ -126,10 +126,13 @@ files:
|
|
126
126
|
- lib/parsers/embed_parser/base.rb
|
127
127
|
- lib/parsers/embed_parser/paste.rb
|
128
128
|
- lib/parsers/embed_parser/youtube.rb
|
129
|
+
- lib/parsers/favicon_parser.rb
|
129
130
|
- lib/parsers/image_parser.rb
|
131
|
+
- lib/parsers/provider_display_parser.rb
|
130
132
|
- lib/parsers/title_parser.rb
|
131
133
|
- lib/richurls.rb
|
132
134
|
- lib/url_fetcher.rb
|
135
|
+
- lib/url_helper.rb
|
133
136
|
- lib/xml_handler.rb
|
134
137
|
- richurls.gemspec
|
135
138
|
homepage: https://github.com/wetransfer/richurls
|