Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/endpoints/in_kind_donation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

require_relative 'endpoint_helper'

in_kind_donation = @client.in_kind_donation(418)
print_in_kind_donation(in_kind_donation)
10 changes: 10 additions & 0 deletions examples/endpoints/in_kind_donations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require_relative 'endpoint_helper'

in_kind_donations = @client.in_kind_donations(
'where[received_at][gt]' => DateTime.new(2024, 12, 1, 12, 0, 0),
# 'where[received_at][gt]' => '2023-06-01T12:00:00Z',
'where[received_at][lt]' => '2024-12-31T12:00:00Z'
)
print_in_kind_donations(in_kind_donations)
18 changes: 18 additions & 0 deletions examples/helpers/in_kind_donations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

def print_in_kind_donations(list)
print_list('in_kind_donation', 'id', list, %w[data])
end

def print_in_kind_donation(item)
print_item('in_kind_donation', item, %w[data])
end

def in_kind_donation_columns
%w[
id
fair_market_value_cents
received_on
description
]
end
1 change: 1 addition & 0 deletions lib/planning_center/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Client
include PlanningCenter::Endpoints::GroupTypes
include PlanningCenter::Endpoints::Households
include PlanningCenter::Endpoints::InactiveReasons
include PlanningCenter::Endpoints::InKindDonations
include PlanningCenter::Endpoints::MaritalStatuses
include PlanningCenter::Endpoints::NameSuffixes
include PlanningCenter::Endpoints::People
Expand Down
23 changes: 23 additions & 0 deletions lib/planning_center/endpoints/in_kind_donations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module PlanningCenter
module Endpoints
module InKindDonations
def in_kind_donation(id, params = {})
get(
"giving/v2/in_kind_donations/#{id}",
params
)
end

def in_kind_donations(params = {})
# We need to order the donations by a value (created_at being the default),
# because the results are not consistently ordered without it.
get(
'giving/v2/in_kind_donations',
{ order: :created_at }.merge(params)
)
end
end
end
end
33 changes: 33 additions & 0 deletions spec/planning_center/endpoints/in_kind_donations_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe PlanningCenter::Endpoints::InKindDonations do
let!(:client) { FactoryBot.build(:client) }

describe '#in_kind_donations', :vcr do
before do
@in_kind_donations = client.in_kind_donations.body
end

it 'returns an array' do
expect(@in_kind_donations['data']).to be_an(Array)
end

it 'returns in_kind_donations objects' do
expect(@in_kind_donations['data'].first).to be_a(Hash)
expect(@in_kind_donations['data'].first['id']).to_not be_nil
end
end

describe '#in_kind_donation', :vcr do
before do
@in_kind_donation = client.in_kind_donation(418).body
end

it 'returns a in_kind_donation object' do
expect(@in_kind_donation).to be_a(Hash)
expect(@in_kind_donation['data']['id']).to eq('418')
end
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading