Module: ShelbyArena::Client::Contribution

Included in:
ShelbyArena::Client
Defined in:
lib/shelby_arena/resources/contribution.rb

Instance Method Summary collapse

Instance Method Details

#create_contribution(batch_id, person_id:, date:, currency_type_id:, transaction_number:, contribution_funds:) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/shelby_arena/resources/contribution.rb', line 25

def create_contribution(
  batch_id,
  person_id:,
  date:,
  currency_type_id:,
  transaction_number:,
  contribution_funds:
)
  path = "batch/#{batch_id}/contribution/add"

  body = {
    'BatchId' => batch_id,
    'CurrencyAmount' => sum_of_funds(contribution_funds),
    'TransactionNumber' => transaction_number,
    'ContributionDate' => date,
    'CurrencyTypeId' => currency_type_id,
    'PersonId' => person_id,
    'ContributionFunds' => translate_funds(contribution_funds)
  }

  options = {}
  options[:api_sig] = generate_api_sig(path, options)

  res = json_post("#{path}?api_session=#{options[:api_session]}&api_sig=#{options[:api_sig]}", body.to_json)
  res.dig('ModifyResult', 'ObjectID')
end

#find_contribution(id, options = {}) ⇒ Object



19
20
21
22
23
# File 'lib/shelby_arena/resources/contribution.rb', line 19

def find_contribution(id, options = {})
  options[:api_sig] = generate_api_sig(contribution_path(id), options)
  res = get(contribution_path(id), options.sort)
  Response::Contribution.format(res.dig('Contribution'))
end

#find_contributions_by_batch_id(batch_id, options = {}) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/shelby_arena/resources/contribution.rb', line 11

def find_contributions_by_batch_id(batch_id, options = {})
  path = "batch/#{batch_id}/contribution/list"
  options[:api_sig] = generate_api_sig(path, options)

  res = get(path, options.sort)
  Response::Contribution.format(res.dig('ContributionListResult', 'Contributions', 'Contribution'))
end

#list_contributions(options = {}) ⇒ Object



5
6
7
8
9
# File 'lib/shelby_arena/resources/contribution.rb', line 5

def list_contributions(options = {})
  options[:api_sig] = generate_api_sig(contribution_path, options)
  res = get(contribution_path, options.sort)
  Response::Contribution.format(res.dig('ContributionListResult', 'Contributions', 'Contribution'))
end