Skip to content
Snippets Groups Projects
Commit 941aca51 authored by David Byers's avatar David Byers
Browse files

Merge branch '5-make-nominatim-url-configurable' into 'master'

Resolve "Make nominatim url configurable"

Closes #5

See merge request !7
parents 98f5ddcd 79a719a7
No related branches found
Tags 1.3.0
1 merge request!7Resolve "Make nominatim url configurable"
......@@ -49,4 +49,4 @@ test:
-l olctest.el \
-f olctest-batch-test \
$(TESTS) \
)
) && echo "All tests passed"
......@@ -3,7 +3,7 @@
;; Copyright (C) 2020 David Byers
;;
;; Author: David Byers <david.byers@liu.se>
;; Version: 1.1.0
;; Version: 1.2.0
;; Package-Requires: ((emacs "25.1"))
;; Keywords: extensions, lisp
;; URL: https://gitlab.liu.se/davby02/olc
......@@ -53,6 +53,13 @@
(declare-function request-response-data "request")
;;; Variables:
(defvar olc-nominatim-url "https://nominatim.openstreetmap.org/"
"Base url for the nominatim endpoint.")
;;; Custom errors:
......@@ -209,6 +216,13 @@ raise, and args for the raised error.
(setq index (1+ index)))
code))))
(defun olc-nominatim-endpoint (path)
"Build a complete url for nominatim endpoint PATH."
(concat olc-nominatim-url
(if (= ?/ (elt olc-nominatim-url (1- (length olc-nominatim-url))))
"" "/")
path))
(defsubst olc-clip-latitude (lat)
"Clip LAT to -90,90."
(max -90 (min 90 lat)))
......@@ -606,7 +620,7 @@ faster.
(let* ((zoom (floor (+ zoom-lo zoom-hi) 2))
(resp (request-response-data
(request
"https://nominatim.openstreetmap.org/reverse"
(olc-nominatim-endpoint "reverse")
:params `((lat . ,(olc-area-lat area))
(lon . ,(olc-area-lon area))
(zoom . ,zoom)
......@@ -720,7 +734,7 @@ full open location code."
;; If the code is full then return it
(if (olc-is-full code)
(olc-recover code 0 0 :format format)
(let ((resp (request "https://nominatim.openstreetmap.org/search"
(let ((resp (request (olc-nominatim-endpoint "search")
:params `((q . ,ref)
(format . "json")
(limit . 1))
......
......@@ -488,14 +488,29 @@
"22+" "Nowhere Special, Pitcairn")) :msg "R1")
(olc-recover-compound "22+ Nowhere Special, Pitcairn"))
(olctest-expect-failure "R2"
(let ((olc-nominatim-url "https://invalid.domain/nominatim"))
(olctest-assert-error (:exp ((olc-recover-error-reference-search-failed
"22+" "Sweden")) :msg "R2")
(olc-recover-compound "22+ Sweden"))))
(let ((olc-nominatim-url "https://invalid.domain/nominatim"))
(olctest-assert-error (:exp ((olc-recover-error-reference-search-failed
"22+" "Sweden")) :msg "R2")
(olc-recover-compound "22+ Sweden")))
))
(defun olctest-issue-5 ()
(olctest-testcase "issue-5"
(olctest-string= :exp "https://nominatim.openstreetmap.org/search"
:act (olc-nominatim-endpoint "search")
:msg "1")
(let ((olc-nominatim-url "https://nominatim.invalid"))
(olctest-string= :exp "https://nominatim.invalid/search"
:act (olc-nominatim-endpoint "search")
:msg "2"))
(let ((olc-nominatim-url "https://nominatim.invalid/"))
(olctest-string= :exp "https://nominatim.invalid/reverse"
:act (olc-nominatim-endpoint "reverse")
:msg "3"))))
(defvar olctest-selected-tests)
......@@ -515,6 +530,7 @@
(run-test validity)
(run-test localtests)
(run-test errors)
(run-test issue-5)
(run-test issue-3)
(run-test issue-2)
(run-test issue-1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment