0.0
No commit activity in last 3 years
No release in over 3 years
Ruby wrapper for the Planning Center Online API.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.5
~> 0.10
~> 0.9
~> 10.1
~> 2.14
~> 0.23
~> 2.9
~> 1.17

Runtime

~> 1.8
~> 0.4
 Project Readme

Planning Center Services

Build Status Code Climate Code Climate Coverage

Ruby wrapper for the Planning Center Services OAuth 1.0 API.

Installation

Add this line to your application's Gemfile:

gem 'planning_center'

And then execute:

$ bundle

Or install it yourself as:

$ gem install planning_center

Usage

Configuration

All API requests are made via an OAuth client. You'll have to register an application with Planning Center to get a consumer key and secret. Then, you can follow the normal OAuth procedures for requesting access tokens for your users.

Once you've jumped through all the OAuth hoops, you're ready to configure a client.

client = PlanningCenter::Client.new do |c|
  c.consumer_key = 'YOUR_CONSUMER_KEY'
  c.consumer_secret = 'YOUR_CONSUMER_SECRET'
  c.access_token = 'YOUR_ACCESS_TOKEN'
  c.access_token_secret = 'YOUR_ACCESS_SECRET'
end

Organization

All Planning Center API data flows through the user's organization. Since each OAuth client is tied to a user's account, you can access the organization directly from a Client object.

client = PlanningCenter::Client.new do |c|
  # config details
end

client.organization # => #<PlanningCenter::Organization>

Attributes

The API response body is parsed and stored as a hash in each object. You can get at the hash directly through the #attrs method or via a method directly.

organization.attrs['name'] # => 'Organization Name'
organization.name # => 'Organization Name'

For more details about what attributes and methods are available for various objects, check out the API docs.

Associations

Associations between objects are setup to work seamlessly, regardless of whether the source object contains a full version of the associated object, a partial set of attributes, or only the id of the associated object.

# Fully embedded association (no additional API request)
organization.service_types # => [#<PlanningCenter::ServiceType>, #<PlanningCenter::ServiceType>, ...]

# Partially embedded association (no immediate additional API request)
service_type.plans # => [#<PlanningCenter::Plan>, #<PlanningCenter::Plan>, ...]

# Association referenced by id (performs API request)
item.arrangement # => [#<PlanningCenter::Arrangement>, #<PlanningCenter::Arrangement>, ...]

Lazily Loaded Attributes

In a few cases, an object retrieved from the API contains embedded associations that don't have their full set of attributes. For example, the service_type API object contains an array of plans, but those plans only have some of the more "vital" attributes.

For these kinds of associations, we initially create the associated object(s) with the partial set of attributes. That way, if you only need to access one of the attributes that's already been loaded, we won't bother making another API request.

But if you need to get at one of the attributes that isn't already loaded, all you have to do is call that method. The object knows that it can load the desired attribute from the API, so it makes that API call, updates the object's attributes, and returns the result.

partial_plan = service_type.plans.first

# No additional API request is made because 'plan_title' was
# already present in the 'service_type' object
partial_plan.plan_title # => 'Plan Title'

# Makes an API request for the entire 'plan' object,
# updates the `attrs`, and returns the desired value
partial_plan.total_length # => 4560

Contributing

  1. Fork it ( http://github.com/molawson/planning_center/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request