Giter VIP home page Giter VIP logo

sword's Introduction

###sword Scala library for wordnik REST API.

Wordnik Developer

Project setup

Currently I haven't publish any jar files yet(I plan to do so soon). If you use sbt as your build tool, you can add source dependency as:

object MyApp extends Build {
  lazy val root = Project("root", file(".")) dependsOn(sword)

  // wordnik scala library sword
  lazy val sword = uri("git://github.com/markmarch/sword#0.1")
}

Usage

All version 4 of Wordnik api is supported. See Wordnik API doc for all avaiable APIs.

You need to get your api key at Wordnik Developer. And put the api in a .properties file at the root of the project(the same foler as src), for examples:

wordnik.api.key=XXXXXX
wordnik.username=XXXXX
wordnik.password=XXXX
wordnik.auth.token=XXXXX

You need to set up wordnik.username, wordnik.password and wordnik.auth.token to run the tests.

sword uses dispatch.

A sample app:

import org.ontrait.sword._
import dispatch._

object HelloWordnik extends App {
  
  // get the definitions for a word
  val res = Wordnik.get(Definitions("fire").limit(5)) // will fetch get json response
  val definitions = res flatMap { Definition.text } // extract definitions 
  definitions foreach println
  
  // to use different Executor(see http://dispatch.databinder.net/Dispatch.html to learn more about Executor)
  val apiKey = "put you api key here"
  val api = new WordnikAPI(apiKey, new Http)
  
  // get the top example for a word
  val example = Example.get(api.get(TopExample("fire")) match {
    case Right(e) => println(e.text)
    case Left(e) => print(e.getMessage)
  }
  
}

For more example usage, see test code

This library is largely based on n8han's dispatch-meetup.

sword's People

Stargazers

Xiaoming Jia avatar

Watchers

Xiaoming Jia avatar

sword's Issues

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.