项目作者: mbuczko

项目描述 :
Fetching site-embedded data
高级语言: Clojure
项目地址: git://github.com/mbuczko/embodie.git
创建时间: 2019-01-13T13:51:11Z
项目社区:https://github.com/mbuczko/embodie

开源协议:

下载


oEmbed / open-graph info fetcher

Clojars Project

The goal of this project is to fetch oEmbed, open-graph and basic HTML information stored at given URL.

Entire API comes down to:

  1. (require '[embodie.core :as core]
  2. '[embodie.oembed :as oembed])
  3. (core/fetch url)
  4. (core/fetch url providers & opts)
  5. (oembed/init-oembed-providers)
  6. (oembed/init-oembed-providers location)
  7. (oembed/with-oembed-providers providers)

providers is by vector of defined providers, [:oembed :open-graph :html] by default, and can be adjusted, eg. to limit amount of data gathered or simply to fetch data from one particular provider.

The opts map is a way to pass additional options, used currently only by :html provider to limit number of returned images (3 by default):

  1. {:max-images 3}

Additionally:

init-oembed-providers initializes a map of defined oembed providers and defaults to json stored at http://oembed.com/providers.json if no alternative location was provided.

with-oembed-providers is a convenience macro which (re)binds variable with oembed providers initialized before.

Fetching in action

Typical use of API functions:

  1. ;; initialize oembed providers from default list
  2. (def providers (oembed/init-oembed-providers))
  3. ;; fetch info using :oembed, :open-graph and :html providers
  4. (oembed/with-oembed-providers providers
  5. (core/fetch "https://www.instagram.com/p/BoRz3GpAhsg/"))
  6. ;; only :html provider and max 1 image
  7. (core/fetch "https://www.instagram.com/p/BoRz3GpAhsg/" [:html] {:max-images 1})