1 个不稳定版本

0.1.0 2021 年 9 月 30 日

#63 in #discovery

MIT 许可证

17KB
174

oembed-rs

oEmbed 1.0 的通用实现。

Latest Version Documentation License

目前不支持

  • 端点发现
  • XML 响应

快速入门

use std::error::Error;
use std::borrow::Cow;
use oembed::client::*;

struct DummyHttp;

impl Http for DummyHttp {
    fn url_encode<'a>(&mut self, s: &'a str) -> HttpResult<Cow<'a, str>> {
        Ok(s.into())
    }

    fn get(&mut self, _url: &str) -> HttpResult<String> {
        Ok("{
            \"version\": \"1.0\",
            \"type\": \"photo\",
            \"width\": 240,
            \"height\": 160,
            \"title\": \"ZB8T0193\",
            \"url\": \"http://farm4.static.flickr.com/3123/2341623661_7c99f48bbf_m.jpg\",
            \"author_name\": \"Bees\",
            \"author_url\": \"http://www.flickr.com/photos/bees/\",
            \"provider_name\": \"Flickr\",
            \"provider_url\": \"http://www.flickr.com/\"
        }".to_string())
    }
}

let schema = Schema::load_included();
let some_url = "http://www.flickr.com/photos/bees/2341623661/";
let mut http = DummyHttp {};

let response = schema.fetch(&mut http, some_url)
    .expect("Missing provider")
    .expect("Failed to fetch server response");

println!("{:?}", response);

许可证

oembed-rs 包处于 MIT 许可证之下,许可证文件包含在 LICENSE.txt

包含的服务提供者列表 (src/providers.json) 也处于 MIT 许可证之下,许可证文件包含在 LICENSE.providers.txt

依赖项

~0.7–1.4MB
~33K SLoC