tydaapi

package module
v0.0.0-...-a927c85 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2016 License: MIT Imports: 5 Imported by: 0

README

Build Status Coverage Godoc license Go Report Card

tyda-api

Local binary for exposing http://tyda.se as an API. The binary returns JSON on stdout as default, optionaly indented.

Installation

$ go get github.com/walle/tyda-api/...

Usage

usage: tyda-api [--indented] [--languages LANGUAGES] QUERY

positional arguments:
  query

options:
  --indented, -i         If the output should be indented
  --languages LANGUAGES, -l LANGUAGES
                         Languages to translate to (en fr de es la nb sv) [default: [en]]
  --help, -h             display this help and exit

Testing

Use the go test tool.

$ go test -cover

Contributing

All contributions are welcome! See CONTRIBUTING for more info.

License

The code is under the MIT license. See LICENSE for more information.

Documentation

Overview

Package tydaapi supplies functionality for querying tyda.se and defines a custom response format that plays well with JSON.

Index

Constants

This section is empty.

Variables

View Source
var Languages = map[string]string{
	"sv": "Svenska",
	"en": "Engelska",
	"fr": "Franska",
	"de": "Tyska",
	"es": "Spanska",
	"la": "Latin",
	"nb": "Norska",
}

Languages is a map from short to long form of languages

Functions

func BuildURL

func BuildURL(query string, languages []string) (*url.URL, error)

BuildURL retuns a URL for tyda.se with correct format

Types

type Response

type Response struct {
	SearchTerm       string        `json:"search_term"`
	Language         string        `json:"language"`
	PronunciationURL string        `json:"pronunciation_url"`
	Conjugations     []string      `json:"conjugations"`
	WordClass        string        `json:"word_class"`
	Translations     []Translation `json:"translations"`
	Synonyms         []Word        `json:"synonyms"`
}

Response contains all data parsed that should be delivered

func Parse

func Parse(doc *goquery.Selection) *Response

Parse takes a response and a goquery selection and parses data from the selection into the response structure.

func Search(query string, languages []string) (*Response, error)

Search makes a search on the tyda.se webpage and parses the result into the Response structure. Returns a response and nil, or nil and an error. Languages parameter uses the short form, eg. sv, en es.

type Translation

type Translation struct {
	Language    string `json:"language"`
	Description string `json:"description"`
	Words       []Word `json:"words"`
}

Translation represents one type of translation

type Word

type Word struct {
	Value            string `json:"value"`
	Context          string `json:"context"`
	PronunciationURL string `json:"pronunciation_url"`
	DictionaryURL    string `json:"dictionary_url"`
}

Word represents one specific word

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL