jsonapi

package
v0.0.0-...-30262a5 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2017 License: MIT Imports: 6 Imported by: 2

Documentation

Overview

Package jsonapi implements a http server which responds to simple requests, performs serches on IMDB and returns json objects. It also provides a client for connecting to the server.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HttpClient imdb.HttpGetPoster
	Address    string
}

Client connects to the IMDB jsonapi server and performs basic requests

func (*Client) Item

func (c *Client) Item(id int) (*imdb.ItemData, error)

Item returns information for an item with a given IMDB ID

Example
client := &Client{
	HttpClient: http.DefaultClient,
	Address:    "http://localhost:8088",
}

data, err := client.Item(403358)
if err != nil {
	fmt.Printf("error: %s\n", err)
	return
}

fmt.Printf("%s\n", data)
Output:

id: 403358
type: Movie
title: Nochnoy dozor
year: 2004
other titles:
 > Argentina -> Guardianes de la noche
 > Brazil -> Guardiões da Noite
 > Bulgaria (Bulgarian title) -> Нощна стража
 > Denmark -> Mørkets vogtere
 > Estonia -> Öine patrull
 > Finland -> Night Watch - yövahti
 > Finland (DVD title) -> Yövahti
 > Finland (Swedish title) -> Nattens väktare - nochnoi dozor
 > Finland (alternative title) -> Yövartija
 > France -> Night Watch
 > Georgia -> Gamis gushagi
 > Germany -> Wächter der Nacht - Nochnoi Dozor
 > Greece (transliterated ISO-LATIN-1 title) -> Oi fylakes tis nyhtas
 > Hungary -> Éjszakai őrség
 > Italy -> I guardiani della notte
 > Italy (DVD title) -> Night watch - I guardiani della notte
 > Latvia -> Nakts Sardze
 > Panama -> Guardianes de la noche
 > Peru -> Guardianes de la noche
 > Poland -> Straz nocna
 > Portugal -> Guardiões da Noite
 > Russia -> Ночной дозор
 > Serbia -> Noćna straža
 > Spain -> Guardianes de la noche
 > Sweden -> Nattens väktare
 > Turkey (Turkish title) -> Gece nöbeti
 > UK -> Night Watch
 > World-wide (English title) -> Night Watch
duration: 1h54m0s
short plot: A fantasy-thriller set in present-day Moscow where the respective forces that control daytime and nighttime do battle.
medium plot: Among normal humans live the "Others" possessing various supernatural powers...
long plot: THE SETTING: In the world that is modern Moscow, there exists a parallel realm known as the Gloom (kind of like the Astral Plane)...
poster url: https://images-na.ssl-images-amazon.com/images/M/MV5BMjE0Nzk0NDkyOV5BMl5BanBnXkFtZTcwMjkzOTkyMQ@@.jpg
rating: 6.5
votes: 47k
languages: ru, de
release date: 2005-10-07
tagline: All That Stands Between Light And Darkness Is The Night Watch.

func (*Client) Search

func (c *Client) Search(query *imdb.SearchQuery) ([]*imdb.ShortItem, error)

SearchQuery performs a search on IMDB

Example
client := &Client{
	HttpClient: http.DefaultClient,
	Address:    "http://localhost:8088",
}

query := &imdb.SearchQuery{
	Query:    "Stalker",
	Year:     1979,
	Category: imdb.Movie,
	Exact:    true,
}

items, err := client.Search(query)
if err != nil {
	fmt.Printf("error: %s\n", err)
	return
}

for _, item := range items {
	fmt.Printf("[%s] %07d: %s (%d)\n", item.Type, item.ID, item.Title, item.Year)
}
Output:

[Movie] 0079944: Stalker (1979)

type Server

type Server struct {
	ImdbClient imdb.HttpGetter
}

Server implements a JSON API for querying IMDB

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface

Jump to

Keyboard shortcuts

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