ogextractor 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 18afac251b74707af4d74e09853a9f964aba3c036bacd8e7500cdfab473f9e07
4
+ data.tar.gz: 1d62237810bd8e06df3034299e53e796e6ababfb5e02d405f504ba0f7c24e7c7
5
+ SHA512:
6
+ metadata.gz: 8ca5e271c6f2c60deffc4f1e5993fa48cae5dd22948a180ad43d0dc8630f2c56fce1bb6d37716f5af3325e3f98f73632555cafbc14bed141b15a04f664871327
7
+ data.tar.gz: a4a10b0381de0b83dd8f8e3f2bd8b83f8f024d463e209aaa2453549886c5d01a0553e3a48719cb41d5aab68d7e61618977fe57718f90fb06e5366ab66133fa7d
checksums.yaml.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ �+��8IY~v(cD�3�V��O_��.��x�� r ��X�L�|��f=� �X�.�����֠��J��!����I�dx�O������ag4Ƙ���{4̩���hq��Ɛ��k2(Qےk��X��O\H]�*c7����i��޵|`�֣�� a�<s���v��F����p�S�'K����7��+T��S7�7�o���3��v,��?� },s)u�+����� (<�[�����۾�X����P[�'4ބ#�;�`���p����m�к��+��#f���5Ӭ������`&ލ�t:\�;���I�*~�QK$T�
2
+ �h58���M�e�~��n��!Ӧ�qɲP��w$=�}�$�߾�<���!�-{%�}���Ҝ5؟���&pn�y�
data.tar.gz.sig ADDED
Binary file
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: ogextractor.rb
4
+ # description: Reads Twitter and Open Graph metadata from a given URL.
5
+
6
+ require 'nokorexi'
7
+
8
+
9
+ class OgExtractor
10
+
11
+ attr_reader *%i(title description image url type to_h)
12
+
13
+ def initialize(article_url, debug: false)
14
+
15
+ @debug = debug
16
+ @properties = %w(title description image url type)
17
+ @doc = Nokorexi.new(article_url).to_doc
18
+ extract_metadata()
19
+
20
+ end
21
+
22
+ private
23
+
24
+ def extract_metadata()
25
+
26
+ @head = @doc.root.element('head')
27
+
28
+ read_og_meta()
29
+ read_twitter_meta()
30
+ @url ||= @article_url
31
+
32
+ @to_h = if @card then
33
+
34
+ {card: @card, title: @title, img: @image, desc: @description, url: @url}
35
+
36
+ else
37
+
38
+ if img then
39
+
40
+ {card: @card, title: @title, img: @image, desc: @description, url: @url}
41
+
42
+ elsif title
43
+
44
+ {card: @card, title: @title, desc: @description, url: @url}
45
+
46
+ else
47
+
48
+ nil
49
+
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+
56
+ def read_meta(properties=@properties, attrx="property='og")
57
+
58
+ properties.each do |x|
59
+
60
+ e = @head.element("meta[@#{attrx}:#{x}']attribute::content")
61
+ next unless e
62
+
63
+ instance_variable_set('@' + x, e.to_s)
64
+
65
+ end
66
+
67
+ end
68
+
69
+ def read_og_meta()
70
+
71
+ read_meta()
72
+
73
+ end
74
+
75
+ def read_twitter_meta()
76
+
77
+ read_meta(%w(card title description image), "name='twitter")
78
+
79
+ end
80
+
81
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ogextractor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
+ YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjEwNDAyMDk1NDExWhcN
15
+ MjIwNDAyMDk1NDExWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
+ cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDEMjvB
17
+ zpsZF/WzVRFiWfk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1xx9xrnhD9eTci6iWLIED8d4Boj8Ri4pV
33
+ JRhYYZ7VV0APpPjEitnhK5P3iha2jqmszv9p4DcdVSUJrHkgauyQV4hI0eYT/A15
34
+ v15+8mkeOQjpsZvWVfjb0rLUZl2lGkt6+sKIR6wkmnUUjZYQiWz+EIi8b8pYc2l5
35
+ azbIdSapR6G4UjU3aVk8KHCv1Rqf9AJ+M0Hu42nze7wtsc9EVxJKIPRc9PuDo09f
36
+ 7BeuG+9bFS2k1B0duQiGNQQy
37
+ -----END CERTIFICATE-----
38
+ date: 2021-04-02 00:00:00.000000000 Z
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: nokorexi
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.5'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.5.3
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '0.5'
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.5.3
60
+ description:
61
+ email: digital.robertson@gmail.com
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - lib/ogextractor.rb
67
+ homepage: https://github.com/jrobertson/ogextractor
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.7.10
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Reads Twitter and Open Graph metadata from a given URL.
91
+ test_files: []
metadata.gz.sig ADDED
Binary file