GithubHelp home page GithubHelp logo

ocaml-diffbot's Introduction

ocaml-diffbot

A Client for the diffbot API written in OCaml. See: <diffbot.com>

Installation

This library depends on:

  • Lwt - Cooperative threading library
  • Cohttp - HTTP client
  • Yojson - JSON library

Which must be installed through OPAM.

You can simply run ./deps.sh once you clone this repo to install all the dependencies

Once all the dependencies are installed, build the library by running the following commands in the cloned repo:

$ make
$ make install # install with ocamlfind
# optionally if you want to play around with the example:
$ make example

Configuration

You can set your API token by partially applying analyze. For example:

open Diffbot

let my_analyze = analyze ~token:"<totally secret>"

let resp = my_analyze Article ~url:"http://huffingtonpost.com"

Example

You can run the example command line script after running:

$ make example
# Will run against http://www.xconomy.com/san-francisco/2012/07/25/diffbot-is-using-computer-vision-to-reinvent-the-semantic-web/
$ ./ex1.native <api token> frontpage

To compile your own code that uses this library, for example given a source file diffy.ml:

open Diffbot

let () =
  let response = analyze Frontpage
                   ~token:"<secret>"
                   ~url:"http://huffingtonpost.com" in
  let json = Lwt_main.run response in
  print_endline "Response:";
  json |> Yojson.Basic.to_string |> print_endline

Build & run with:

$ ocamlbuild -use-ocamlfind -pkg diffbot diffy.native
$ ./diffy.native

Documentation

Check out lib/diffbot.mli. There's only a single exposed function so the API is very simple. The signature is copied over here:

(* The type of api calls to make *)
type api =
  | Article
  | Frontpage
  | Product
  | Image
  | Classifier

(* Analyze given a token,which api to use, a url to analyze *)
val analyze : ?version:string -> token:string -> api -> url:string -> json Lwt.t

ocaml-diffbot's People

Contributors

rgrinberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

diffbot

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.