Skip to content

Commit

Permalink
all queries via GET parameters
Browse files Browse the repository at this point in the history
	closes #3
  • Loading branch information
jpmens committed Jan 23, 2019
1 parent 1c77483 commit d6772c6
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 138 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ clobber: clean
rm -f revgeod lmdb-ll-look

install: revgeod
mkdir -p $(DESTDIR)$(INSTALLDIR)/bin
mkdir -p $(DESTDIR)$(INSTALLDIR)/sbin
mkdir -p $(DESTDIR)/var/local/revgeod
chmod 755 $(DESTDIR)/var/local/revgeod
install -m 755 revgeoc $(DESTDIR)$(INSTALLDIR)/bin/revgeoc
install -m 755 revgeod $(DESTDIR)$(INSTALLDIR)/sbin/revgeod
mkdir -p $(DESTDIR)$(INSTALLDIR)/etc/default
chmod 755 $(DESTDIR)$(INSTALLDIR)/etc/default
Expand Down
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ export OPENCAGE_APIKEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
export REVGEO_IP=127.0.0.1
export REVGEO_PORT=8865

mkdir -p data/geocache/

exec ./revgeod
```

The `data/geocache/` directory (currently hardcoded) must exist and be writeable; that's where the LMDB database is stored. _revgeod_ caches OpenCage's responses (they explicitly permit this):
The _geocache_ directory (currently hardcoded) must exist and be writeable; that's where the LMDB database is stored. _revgeod_ caches OpenCage's responses (they explicitly permit this):

![cache as long as you want](assets/airjp480.png)

Expand All @@ -24,30 +22,29 @@ The `data/geocache/` directory (currently hardcoded) must exist and be writeable
$ curl -i 'http://127.0.0.1:8865/rev?lat=48.85593&lon=2.29431'
HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Length: 111
Content-Length: 163
Content-type: application/json
Date: Tue, 23 Oct 2018 13:10:12 GMT
```
```json
{"address":{"village":"4 r du Général Lambert, 75015 Paris, France","locality":"Paris","cc":"FR","s":"opencage"}}
Date: Wed, 23 Jan 2019 14:08:43 GMT

{
"address": {
"village": "4 r du Général Lambert, 75015 Paris, France",
"locality": "Paris",
"cc": "FR",
"s": "opencage"
}
}
```

A second query for the same location would respond with `lmdb` instead of `opencage` as the source, indicating it's been cached.

```json
{"address":{"village":"4 r du Général Lambert, 75015 Paris, France","locality":"Paris","cc":"FR","s":"lmdb"}}
```

## query params

The following query parameters are mandatory:

- `lat=` specify the latitude as a decimal
- `lon=` specify the longitude as a decimal
The following query parameters are supported on the `/rev` endpoint:

The following optional query parameters are supported:

- `app=` specifies an "application" for which query statistics should be collected (see _statistics_ below).
- `lat=` specify the latitude as a decimal (mandatory)
- `lon=` specify the longitude as a decimal (mandatory)
- `app=` specifies an "application" for which query statistics should be collected (see _statistics_ below) (optional)

## statistics

Expand Down Expand Up @@ -80,15 +77,17 @@ _revgeod_ provides statistics on its `/stats` endpoint:

## options

The following command-line switches are supported:
The following command-line switches are supported for _revgeod_:

* `-d`: dump content of database (all keys/values) to stdout
* `-D`: dump content of database (all keys/values) to stdout, lines prefixed by lat,lon
* `-k`: kill (i.e. delete) individual geohashes
* `-q`: query individual geohashes
* `-s`: connect to _revgeod_ on its compiled-in address/port to obtain and print statistics
* `-v`: show version and exit

The following keywords are supported in _revgeoc_:

* `stats`: connect to _revgeod_ on its compiled-in address/port to obtain and print statistics. Can also be specified as `-s` for backward compatibility.
* `dump`: dump content of database (all keys/values) to stdout, lines areprefixed by lat,lon; can also be specified as `-d` or `-D`
* `kill`: kill (i.e. delete) the specified geohash
* `lookup`: query the specified geohash

## requirements

### rhel/centos
Expand All @@ -100,12 +99,13 @@ yum install lmdb
### debian

```
apt-get install liblmdb-dev lmdb-utils
apt-get install liblmdb-dev lmdb-utils curl libcurl3
```

### macos

```
brew install curl
brew install jpmens/brew/revgeod
```

Expand Down
3 changes: 2 additions & 1 deletion etc/debian/fpm-make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tempdir=$(mktemp -d /tmp/ot-XXX)

make install DESTDIR=$tempdir

install -D c-mini-test.sh $tempdir/usr/share/doc/revgeod/c-mini-test.sh
install -D README.md $tempdir/usr/share/doc/revgeod/README.md
install -D etc/revgeod.service $tempdir/usr/share/doc/revgeod/revgeod.service

name="revgeod"
Expand Down Expand Up @@ -35,6 +35,7 @@ fpm -s dir \
-C $tempdir \
-p ${debfile} \
-d "libcurl3" \
-d "curl" \
-d "liblmdb0" \
-d "libmicrohttpd12" \
--config-files usr/local/etc/default/revgeod \
Expand Down
54 changes: 54 additions & 0 deletions revgeoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/sh

# revgeoc -- a client for revgeod
#
# Copyright (C) 2018-2019 Jan-Piet Mens <jp@mens.de>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.

curl=curl
opts="-sSf"
opts="-i"

host=${REVGEO_HOST:="127.0.0.1"}
port=${REVGEO_PORT:=8865}


case $1 in
dump|-d|-D)
q=dump
;;
stats|-s|version)
q=stats
;;
lookup)
if [ -z "$2" ]; then
echo "$0: lookup needs a geohash"
exit 2
fi

q="lookup?geohash=$2"
;;
kill)
if [ -z "$2" ]; then
echo "$0: kill needs a geohash"
exit 2
fi

q="kill?geohash=$2"
;;

test)
q="rev?lat=48.85593&lon=2.29431&app=revgeoc"
;;

*)
echo "Usage: $0 [test|stats|dump|lookup|kill]" >&2
exit 2
esac

$curl $opts "http://$host:$port/$q" && echo

Loading

0 comments on commit d6772c6

Please sign in to comment.