jcouture / ogp Goto Github PK
View Code? Open in Web Editor NEWSimple Ruby library for parsing Open Graph prototocol information. See http://ogp.me for more information.
License: MIT License
Simple Ruby library for parsing Open Graph prototocol information. See http://ogp.me for more information.
License: MIT License
Using profile type, as well as some other namespaced attributes, this OGP gem will always issue the warning Some og tag names include colons :
, ... removed in the next major version.
The warning then pops up on e.g. logging and consoles. Since it is Kernel#warn, the consumer can disable it, so the problem is minor. Still, this is valid ogp and it is somewhat annoying to see those warnings pop up without being able to do anything about it, other than to disable warnings.
I assume, deprecating this, as announced in that warning, will result in a fix for this issue, so I don't present a PR for it.
If there is anything I can do to help fix this otherwise, or if it is desired to be fixed before it gets deprecated, (e.g. a gsub(':', '_')
), please let me know and I'll do so in a PR.
Hi! It seems OGP is unable to parse Twitter's OpenGraph properties.
I think the problem might be that the meta tag's attributes are in an unusual order. This code shows the problem:
require 'http'
require 'ogp'
class OGPTest
attr_accessor :href
def initialize(href: nil)
@href = href
end
def analyze_opengraph
return nil if @href.nil?
begin
connection = HTTP
.follow(max_hops: 5)
.timeout(30)
.get(@href)
if connection.status == 200
return OGP::OpenGraph.new(connection.body.to_str)
end
rescue Exception => e
puts "Error while trying to access '#{@href}'"
raise
return nil
end
end
end
c = OGPTest.new href: 'https://twitter.com/jack'
puts c.analyze_opengraph
Outputs:
Error while trying to access 'https://twitter.com/jack'
/home/akos/.rvm/gems/ruby-3.0.0/gems/ogp-0.5.0/lib/ogp/open_graph.rb:27:in `initialize': OGP::MalformedSourceError (OGP::MalformedSourceError)
from a.rb:22:in `new'
from a.rb:22:in `analyze_opengraph'
from a.rb:33:in `<main>'
I'm having a problem when trying to parse a page with a tag og:country-name
:
*** NameError Exception: `@country-name' is not allowed as an instance variable name
(example: https://www.kao.co.jp/liese/lineup/sugami/)
Ruby doesn't support hyphen when creating a instance variable, so should we change the code to snake_case tag names before trying to instance?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.