Project

givepulse

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
A wrapper gem around Givepulse's API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.15
~> 2.2
~> 0.11
~> 10.0
~> 3.0
~> 0.51
~> 0.9
~> 3.1
 Project Readme

Givepulse

This gem is a wrapper library around Givepulse's API providing a simple set of Ruby classes around interacting with your Givepulse data.

Installation

Add this line to your application's Gemfile:

gem 'givepulse'

And then execute:

$ bundle

Or install it yourself as:

$ gem install givepulse

Usage

Initializing an API client

First thing you must do when using this API is initialize a client and pass in your API authentication information and then call :authorize on your client object.

require 'givepulse'

@client = Givepulse::Client.new(
    consumer_key: 'sample_consumer_key',
    consumer_secret: 'sample_consumer_secret',
    user_email: 'sample@user.com',
    user_password: 'sample_password'
)
@client.authorize

Accessing data from API endpoints

Once you have initialized a client object, you can begin grabbing data from the API to use in your application. Not all REST endpoints are supported on every API resource, refer to the Givepulse API documentation to see what is available.

Using the client object follows an API like this

affiliations = @client.affiliations.get

new_affiliation = @client.affiliations.create({
    'group1_id' => '12345',
    'group2_id' => '12346',
    'notify' => 'yes'
})

updated_affiliation = @client.affiliations.update(12345, {
    'approve' => 'yes'
})

deleted_affiliation = @client.affiliations.delete(12345)

Filtering API responses

You can add filter and search data to GET requests by passing in Ruby objects to :get calls following the parameters documented in the Givepulse API documentation.

admin_users = @client.users.get({
    'role' => 'admin'
})

Using responses

All responses are returned as plain Ruby objects parsed from the JSON responses given by the API. So, you can use the returned data just like any other Ruby object.

users = @client.users.get

first_user_email = users[:results][0][:email]

Re-authorization

Authorization tokens for the API expire after two hours. The client object will automatically keep track of the time passed since authorization for you. To check if your token has expired, you can use the :authorized? method and call :authorize automatically if your token is expired to refresh it.

unless @client.authorized?
    @client.authorize
end

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/archermalmo/givepulse.

License

The gem is available as open source under the terms of the MIT License.