get_ogp 0.1.1 → 0.1.2
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/README.md +6 -3
- data/lib/get_ogp.rb +3 -1
- data/lib/get_ogp/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 622ba3af0c94411bd74d4b3ba37cb6791a435d1aaf8ddbb087d5d90e782ee491
|
4
|
+
data.tar.gz: 8d705e6f2b0f5e3051037aac52572e637dcc5dbd1a7f2be4b39eb63723abf67a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db020f441c40bd3d9a61532a8790f16bbea3591bd7f95129c881bb49a712d987e305bb37757919d0788700ab759333f668ef5a391faf0b7ffc478d44da87317d
|
7
|
+
data.tar.gz: 7331b3165d868139f837a0201c90b38212d8a5055ceb6f12f5c4d20af7f182ecee3853877b24dfbbacf1464c4175146559178d7df6b257cbf507af2fa339f540
|
data/README.md
CHANGED
@@ -22,15 +22,18 @@ Or install it yourself as:
|
|
22
22
|
## Usage
|
23
23
|
|
24
24
|
```ruby
|
25
|
+
# get ogp data if property="og:~" or name="og:~" is exist
|
25
26
|
open_graph = GetOgp.get_data("https://ogp.me")
|
26
27
|
open_graph['title'] # => "Open Graph protocol"
|
27
28
|
open_graph['type'] # => "website"
|
28
29
|
open_graph['image'] # => "https://ogp.me/logo.png"
|
29
30
|
open_graph['url'] # => "https://ogp.me/"
|
30
31
|
|
31
|
-
# if ogp is not exist, return
|
32
|
-
not_exist_open_graph = GetOgp.get_data("
|
33
|
-
|
32
|
+
# if ogp is not exist, return title tag text
|
33
|
+
not_exist_open_graph = GetOgp.get_data("http://example.com")
|
34
|
+
open_graph['title'] # => "Example Domain"
|
35
|
+
|
36
|
+
# if ogp and title tag are not exist, return title tag text
|
34
37
|
```
|
35
38
|
|
36
39
|
## Contributing
|
data/lib/get_ogp.rb
CHANGED
@@ -11,10 +11,12 @@ module GetOgp
|
|
11
11
|
html = Nokogiri::HTML.parse(response.body)
|
12
12
|
ogp_date = {}
|
13
13
|
html.css('meta').each do |meta|
|
14
|
-
if meta.attribute('property') && meta.attribute('property').to_s.match(/^og:(.+)$/i)
|
14
|
+
if (meta.attribute('property') && meta.attribute('property').to_s.match(/^og:(.+)$/i)) || (meta.attribute('name') && meta.attribute('name').to_s.match(/^og:(.+)$/i))
|
15
15
|
ogp_date[$1] = meta.attribute('content').to_s
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
ogp_date['title'] = html.css('title')&.text unless ogp_date.has_key?('title')
|
18
20
|
return false if ogp_date.keys.empty?
|
19
21
|
ogp_date
|
20
22
|
rescue => e
|
data/lib/get_ogp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: get_ogp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sinn22
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|