gottfrois / link_thumbnailer

Ruby gem that fetches images and metadata from a given URL. Much like popular social website with link preview.
MIT License
511 stars 106 forks source link

Methods to know the type of content #113

Open ricardopacheco opened 7 years ago

ricardopacheco commented 7 years ago

Is it possible to have a method that returns the content type of the page? In oembed there is a key that returns this.

Example { title: 'example', type: 'video', url: ... }

gottfrois commented 7 years ago

sounds reasonable, we could fallback to use the content-type from the http request maybe?

ricardopacheco commented 7 years ago

Yea, ruby-oembed gem has an implementation in that sense that you said.

https://github.com/ruby-oembed/ruby-oembed/blob/master/lib/oembed/response.rb#L29

The question is to have the URL type in to_json and boolean methods to check for themselves, type @object.video? @object.image?

This will help, for example, render specific views for each case.

ricardopacheco commented 7 years ago

@gottfrois You could put another hash with the request information?

Like this:

{
  request: {
    content-type: ...,
    ...
  },
  object: {
    url: '...',
    title: '...',
  }
}

This alternative hash could be returned by user option for example: generate (url, http_headers: true)