https://github.com/druids/clj-currencylayer
A client for currencylayer.com API based on clj-http.client
https://github.com/druids/clj-currencylayer
Last synced: 10 months ago
JSON representation
A client for currencylayer.com API based on clj-http.client
- Host: GitHub
- URL: https://github.com/druids/clj-currencylayer
- Owner: druids
- License: mit
- Created: 2018-03-19T07:15:49.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-26T15:39:03.000Z (about 8 years ago)
- Last Synced: 2025-09-03T03:39:42.365Z (10 months ago)
- Language: Clojure
- Size: 14.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
clj-currencylayer
=================
A client for [currencylayer.com API](currencylayer.com) based on [clj-http.client](https://clojars.org/clj-http).
[](https://circleci.com/gh/druids/clj-currencylayer)
[](https://jarkeeper.com/druids/clj-currencylayer)
[](https://opensource.org/licenses/MIT)
Leiningen/Boot
--------------
```clojure
[clj-currencylayer "0.2.0"]
```
Documentation
-------------
All functions are designed to return errors instead of throwing exceptions (except `:pre` in a function).
All API calls return a tuple within following structure: `[:keyword body response]` where`:keyword` can be:
- :ok when a response is a success and parsed
- :error-XXX when a response is parsed but it's an error response (where XXX is an error code from
[error codes](https://currencylayer.com/documentation#error\_codes))
- :error-unmarshalling when a response is not a valid JSON
A `body` is a parsed body and `response` is an original response.
To be able to run examples this line is needed:
```clojure
(require '[clj-currencylayer.core :as currencylayer])
```
### get-live
Returns the most recent exchange rate data. Pass all parameters via `params` hash-map.
```clojure
(currencylayer/get-live {:access_key "asdf", :source "USD", :currencies ["EUR" "CZK"]})
;; [:ok
;; {:success true, :timestamp 1521448156, :source "USD", :quotes {:USDCZK 20.7104, :USDEUR 0.814495}, ...
;; {:request-time 386, ...
```
`:currencies` are joined automatically, thus you can pass them as a sequence
```clojure
(currencylayer/get-live {:access_key "asdf"} ["EUR" "CZK"])
```
Because of a tuple you can do kind of "pattern matching":
```clojure
(let [[status body _] (:currencylayer/get-live {:access_key "asdf", :source "EUR", :currencies ["CZK"]})]
(case status
:ok (process-currencies body)
:error-101 (missing-auth-key body)
(default-error body)))
```
When you need to mock a response, you can pass a host to a caller
```clojure
(currencylayer/get-live {:access_key "asdf"} "my-mock-domain.localhost")
```
Or for development you can use HTTP host
```clojure
(currencylayer/get-live {:access_key "asdf"} currencylayer/currencylayer-host-http)
```