https://github.com/gocardless/open-charities
A Ruby library for querying the OpenCharities database
https://github.com/gocardless/open-charities
Last synced: about 2 months ago
JSON representation
A Ruby library for querying the OpenCharities database
- Host: GitHub
- URL: https://github.com/gocardless/open-charities
- Owner: gocardless
- License: mit
- Created: 2012-11-25T22:10:34.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2013-01-30T11:52:46.000Z (over 13 years ago)
- Last Synced: 2024-04-24T13:36:43.610Z (about 2 years ago)
- Language: Ruby
- Size: 187 KB
- Stars: 1
- Watchers: 115
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Open Charities
A simple library for querying http://opencharities.org/ database.
## Installation
To install as a standalone
```sh
$ gem install open-charities
```
or as a dependency in a Gemfile
```ruby
gem "open-charities", "~> 0.2.0", require: 'open_charities'
```
## Usage
```ruby
charity = OpenCharities.lookup("1149855")
=> #
charity['title']
=> "VETERAN'S HEADQUARTERS"
charity.title
=> "VETERAN'S HEADQUARTERS"
charity.charity_number
=> "1149855"
charity.address
=> {"region"=>nil, "raw_address"=>nil, "created_at"=>"2012-11-22T05:00:54+00:00"...}
```
As can be seen from this example, some of the attributes are exposed as instance
methods. More specifically, the methods that are exposed correspond to the
top-level keys in the Hash containing information about the charity.
As in the above example, the `address` attribute returns another Hash.
## Caching
Requests can be cached by configuring the gem to use an external cache (for example,
the Rails cache).
```ruby
# file config/initializers/open_charities.rb
# swap in your own cache here
OpenCharities.cache = Rails.cache
# Optional
OpenCharities.cache_args = { expires_in: 10.minutes }
```
## Testing
To run the tests, issue `rspec spec` on the command-line.
### Available testing data
There is testing data available `spec/data/veteransheadquarters.json`. The same
data is used by the tests in `spec/`.