https://github.com/varvet/verbum-api-client
https://github.com/varvet/verbum-api-client
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/varvet/verbum-api-client
- Owner: varvet
- License: mit
- Created: 2014-10-22T14:25:46.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2017-11-29T10:47:27.000Z (almost 8 years ago)
- Last Synced: 2024-04-14T05:18:02.842Z (over 1 year ago)
- Language: Ruby
- Size: 64.5 KB
- Stars: 0
- Watchers: 15
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
# Verbum API client
A simple Ruby client for the Verbum API.
### Usage
All resources are queried in the same fashion. For instance, to fetch all psalms:
```ruby
psalms = Verbum::Api::Psalm.all
```To fetch a single psalm:
```ruby
psalm = Verbum::Api::Psalm.find(1)
```To fetch multiple psalms:
```ruby
psalms = Verbum::Api::Psalm.find([1,2,3]) # or
psalms = Verbum::Api::Psalm.find("1,2,3")
```To fetch psalms with additional parameters:
```ruby
psalm = Verbum::Api::Psalm.all(q: "foobar", sort: "title")
```To access data on a psalm:
```ruby
psalm = Verbum::Api::Psalm.find(1)
psalm.id
psalm.title
psalm.href
```To access associated data on a psalm:
```ruby
psalm = Verbum::Api::Psalm.find(1)
psalm.verses
psalm.theme
```This will trigger additional queries to the verse and theme resources.
Psalms have some additional helper methods:
```ruby
psalm = Verbum::Api::Psalm.find(1)
psalm.composers # fetches authorships of type composer
psalm.lyricists # fetches authorships of type lyricist
psalm.refrainists # fetches authorships of type refrainist (Omkväde)
```### Request caching
Configure a ActiveSupport::Cache compatible store to cache requests.
```ruby
Verbum::Api.cache = ActiveSupport::Cache.lookup_store(:memory_store)
```If you're using Rails you can use Rails' cache for convenience:
```ruby
Verbum::Api.cache = Rails.cache
```To define cache expiry:
```ruby
Verbum::Api.cache_expires_in = 45.minutes
```Optionally you can set an expiry padding, in order to no have
every resource time out at once.```ruby
Verbum::Api.cache_expiry_padding = 15.minutes
```Using the two examples above, each cached request will expire randomly in
between 45 minutes and 1 hour.