shelby_arena 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/test.yml +22 -0
- data/.gitignore +4 -0
- data/.ruby-version +1 -0
- data/.travis.yml +1 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +44 -0
- data/Rakefile +14 -0
- data/bin/rspec +19 -0
- data/lib/shelby_arena/client.rb +101 -0
- data/lib/shelby_arena/error.rb +50 -0
- data/lib/shelby_arena/resources/batch.rb +43 -0
- data/lib/shelby_arena/resources/contribution.rb +72 -0
- data/lib/shelby_arena/resources/fund.rb +23 -0
- data/lib/shelby_arena/resources/person.rb +72 -0
- data/lib/shelby_arena/response/base.rb +41 -0
- data/lib/shelby_arena/response/batch.rb +23 -0
- data/lib/shelby_arena/response/contribution.rb +28 -0
- data/lib/shelby_arena/response/contribution_fund.rb +20 -0
- data/lib/shelby_arena/response/fund.rb +20 -0
- data/lib/shelby_arena/response/person.rb +35 -0
- data/lib/shelby_arena/version.rb +3 -0
- data/lib/shelby_arena.rb +6 -0
- data/shelby_arena.gemspec +33 -0
- metadata +194 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 10481118fe91152ecf2b01b3b9fc330854b95a4f22f73cf6f2992e2b9caa85ad
|
4
|
+
data.tar.gz: a71771473869f334f87e62899d177dc90f527f48a524d325ac6a3c16c98fb36f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c8cd1b36bf96c30003a42ecf07844d2186d495576b1833c181fdaed3de608cc787515218bf561916275c7359a0f32a6b262dd18725bf9c2b7b4e921a2e612c94
|
7
|
+
data.tar.gz: 72d7b0bde4b069746f87c44b679c5432c48e51e36b7fc4cbb611d170be7dd59811d9459cf203c682ab887adebaa69ae332742f121d99d8ac969f067edc4e718b
|
@@ -0,0 +1,22 @@
|
|
1
|
+
name: Run specs
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v2
|
15
|
+
- name: Set up Ruby
|
16
|
+
uses: ruby/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
bundler-cache: true
|
19
|
+
- name: Install dependencies
|
20
|
+
run: bundle install
|
21
|
+
- name: Run tests
|
22
|
+
run: bundle exec rspec
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.4
|
data/.travis.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
language: ruby
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Taylor Brooks
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Shelby Arena Ruby Client ![example workflow](https://github.com/taylorbrooks/shelby_arena/actions/workflows/test.yml/badge.svg)
|
2
|
+
|
3
|
+
A Ruby wrapper for the Shelby Arena API
|
4
|
+
|
5
|
+
### Installation
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
````ruby
|
8
|
+
# in your Gemfile
|
9
|
+
gem 'shelby_arena', '~> 0.0.1'
|
10
|
+
|
11
|
+
# then...
|
12
|
+
bundle install
|
13
|
+
````
|
14
|
+
|
15
|
+
### Usage
|
16
|
+
````ruby
|
17
|
+
# Authenticating with username and password
|
18
|
+
client = ShelbyArena::Client.new(
|
19
|
+
url: ...,
|
20
|
+
username: ...,
|
21
|
+
password: ...,
|
22
|
+
)
|
23
|
+
|
24
|
+
# Find a people by attributes
|
25
|
+
client.find_people_by_email('gob@bluthco.com')
|
26
|
+
client.find_people_by_name_and_email('Tobias', 'Funke', 'tobias@bluemangroup.com')
|
27
|
+
````
|
28
|
+
|
29
|
+
### History
|
30
|
+
|
31
|
+
- View the [changelog](https://github.com/taylorbrooks/shelby_arena/blob/master/CHANGELOG.md)
|
32
|
+
- This gem follows [Semantic Versioning](http://semver.org/)
|
33
|
+
|
34
|
+
### Contributing
|
35
|
+
|
36
|
+
Everyone is encouraged to help improve this project. Here are a few ways you can help:
|
37
|
+
|
38
|
+
- [Report bugs](https://github.com/taylorbrooks/shelby_arena/issues)
|
39
|
+
- Fix bugs and [submit pull requests](https://github.com/taylorbrooks/shelby_arena/pulls)
|
40
|
+
- Write, clarify, or fix documentation
|
41
|
+
- Suggest or add new features
|
42
|
+
|
43
|
+
### Copyright
|
44
|
+
Copyright (c) 2023 Taylor Brooks. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
|
6
|
+
task default: :spec
|
7
|
+
|
8
|
+
task :environment do
|
9
|
+
require 'dotenv'
|
10
|
+
Dotenv.load
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
13
|
+
require 'shelby_arena'
|
14
|
+
end
|
data/bin/rspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'rspec' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require 'pathname'
|
11
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path(
|
12
|
+
'../../Gemfile',
|
13
|
+
Pathname.new(__FILE__).realpath
|
14
|
+
)
|
15
|
+
|
16
|
+
require 'rubygems'
|
17
|
+
require 'bundler/setup'
|
18
|
+
|
19
|
+
load Gem.bin_path('rspec-core', 'rspec')
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
Dir[File.expand_path('../resources/*.rb', __FILE__)].each { |f| require f }
|
4
|
+
require File.expand_path('../response/base.rb', __FILE__)
|
5
|
+
Dir[File.expand_path('../response/*.rb', __FILE__)].each { |f| require f }
|
6
|
+
|
7
|
+
module ShelbyArena
|
8
|
+
class Client
|
9
|
+
include ShelbyArena::Client::Batch
|
10
|
+
include ShelbyArena::Client::Fund
|
11
|
+
include ShelbyArena::Client::Person
|
12
|
+
include ShelbyArena::Client::Contribution
|
13
|
+
|
14
|
+
attr_reader :url, :username, :password, :logger, :connection, :adapter, :ssl, :api_key, :api_secret, :api_session
|
15
|
+
|
16
|
+
def initialize(url:, username:, password:, api_key:, api_secret:, logger: true, adapter: Faraday.default_adapter, ssl: nil)
|
17
|
+
if username.nil? && password.nil?
|
18
|
+
raise ArgumentError, 'either username and password'
|
19
|
+
end
|
20
|
+
|
21
|
+
@url = "#{url}/api.svc/"
|
22
|
+
@username = username
|
23
|
+
@password = password
|
24
|
+
@api_key = api_key
|
25
|
+
@api_secret = api_secret
|
26
|
+
@logger = logger
|
27
|
+
@adapter = adapter
|
28
|
+
@ssl = ssl
|
29
|
+
@api_session = fetch_api_session
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete(path, options = {})
|
33
|
+
connection.delete(path, options).body
|
34
|
+
end
|
35
|
+
|
36
|
+
def get(path, options = {})
|
37
|
+
connection.get(path, options).body
|
38
|
+
end
|
39
|
+
|
40
|
+
def patch(path, options = {})
|
41
|
+
connection.patch(path, options).body
|
42
|
+
end
|
43
|
+
|
44
|
+
def post(path, options = {})
|
45
|
+
connection.post(path, options).body
|
46
|
+
end
|
47
|
+
|
48
|
+
def json_post(path, options = {})
|
49
|
+
connection(true).post(path, options).body
|
50
|
+
end
|
51
|
+
|
52
|
+
def put(path, options = {})
|
53
|
+
connection.put(path, options).body
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def fetch_api_session
|
59
|
+
params = {
|
60
|
+
username: username,
|
61
|
+
password: password,
|
62
|
+
api_key: api_key
|
63
|
+
}
|
64
|
+
|
65
|
+
res = post('login', **params)
|
66
|
+
|
67
|
+
res.dig('ApiSession', 'SessionID')
|
68
|
+
end
|
69
|
+
|
70
|
+
def generate_api_sig(path, options = {})
|
71
|
+
options[:api_session] = api_session
|
72
|
+
params = Faraday::FlatParamsEncoder.encode(options)
|
73
|
+
thing_to_hash = "#{api_secret}_#{path}?#{params}".downcase
|
74
|
+
Digest::MD5.hexdigest(thing_to_hash)
|
75
|
+
end
|
76
|
+
|
77
|
+
def connection(json = false)
|
78
|
+
headers = {
|
79
|
+
accept: 'application/json',
|
80
|
+
'User-Agent' => "shelby-arena-ruby-gem/v#{ShelbyArena::VERSION}"
|
81
|
+
}
|
82
|
+
|
83
|
+
headers['Content-Type'] = 'application/json' if json
|
84
|
+
|
85
|
+
client_opts = {
|
86
|
+
url: url,
|
87
|
+
headers: headers
|
88
|
+
}
|
89
|
+
|
90
|
+
client_opts[:ssl] = ssl if ssl
|
91
|
+
|
92
|
+
Faraday.new(client_opts) do |conn|
|
93
|
+
conn.request :url_encoded
|
94
|
+
conn.response :logger if logger
|
95
|
+
conn.response :xml
|
96
|
+
conn.use FaradayMiddleware::ShelbyArenaErrorHandler
|
97
|
+
conn.adapter adapter
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module ShelbyArena
|
2
|
+
class Error < StandardError; end
|
3
|
+
class BadGateway < Error; end
|
4
|
+
class BadRequest < Error; end
|
5
|
+
class CloudflareError < Error; end
|
6
|
+
class Forbidden < Error; end
|
7
|
+
class GatewayTimeout < Error; end
|
8
|
+
class InternalServerError < Error; end
|
9
|
+
class NotFound < Error; end
|
10
|
+
class ServiceUnavailable < Error; end
|
11
|
+
class Unauthorized < Error; end
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'faraday'
|
15
|
+
module FaradayMiddleware
|
16
|
+
class ShelbyArenaErrorHandler < Faraday::Middleware
|
17
|
+
ERROR_STATUSES = 400..600
|
18
|
+
|
19
|
+
def on_complete(env)
|
20
|
+
case env[:status]
|
21
|
+
when 400
|
22
|
+
raise ShelbyArena::BadRequest, error_message(env)
|
23
|
+
when 401
|
24
|
+
raise ShelbyArena::Unauthorized, error_message(env)
|
25
|
+
when 403
|
26
|
+
raise ShelbyArena::Forbidden, error_message(env)
|
27
|
+
when 404
|
28
|
+
raise ShelbyArena::NotFound, error_message(env)
|
29
|
+
when 500
|
30
|
+
raise ShelbyArena::InternalServerError, error_message(env)
|
31
|
+
when 502
|
32
|
+
raise ShelbyArena::BadGateway, error_message(env)
|
33
|
+
when 503
|
34
|
+
raise ShelbyArena::ServiceUnavailable, error_message(env)
|
35
|
+
when 504
|
36
|
+
raise ShelbyArena::GatewayTimeout, error_message(env)
|
37
|
+
when 520
|
38
|
+
raise ShelbyArena::CloudflareError, error_message(env)
|
39
|
+
when ERROR_STATUSES
|
40
|
+
raise ShelbyArena::Error, error_message(env)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def error_message(env)
|
47
|
+
"#{env[:status]}: #{env[:url]} #{env[:body]}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module ShelbyArena
|
2
|
+
class Client
|
3
|
+
module Batch
|
4
|
+
def list_batches(options = {})
|
5
|
+
path = 'batch/list'
|
6
|
+
options[:api_sig] = generate_api_sig(path, options)
|
7
|
+
|
8
|
+
res = get(path, options.sort)
|
9
|
+
Response::Batch.format(res.dig('BatchListResult', 'Batches', 'Batch'))
|
10
|
+
end
|
11
|
+
|
12
|
+
def find_batch(id, options = {})
|
13
|
+
path = "batch/#{id}"
|
14
|
+
options[:api_sig] = generate_api_sig(path, options)
|
15
|
+
|
16
|
+
res = get(path, options.sort)
|
17
|
+
Response::Batch.format(res.dig('Batch'))
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_batch(name:, start_date:, end_date:)
|
21
|
+
path = 'batch/add'
|
22
|
+
body = {
|
23
|
+
BatchName: name,
|
24
|
+
BatchDate: start_date,
|
25
|
+
BatchDateEnd: end_date
|
26
|
+
}
|
27
|
+
|
28
|
+
options = {}
|
29
|
+
options[:api_sig] = generate_api_sig(path, options)
|
30
|
+
json_body = body.to_json
|
31
|
+
|
32
|
+
json_post("#{path}?api_session=#{options[:api_session]}&api_sig=#{options[:api_sig]}", json_body)
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete_batch(id, options = {})
|
36
|
+
path = "batch/#{id}"
|
37
|
+
options[:api_sig] = generate_api_sig(path, options)
|
38
|
+
require 'pry'; binding.pry
|
39
|
+
delete(path, options.sort)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module ShelbyArena
|
2
|
+
class Client
|
3
|
+
module Contribution
|
4
|
+
|
5
|
+
def list_contributions(options = {})
|
6
|
+
options[:api_sig] = generate_api_sig(contribution_path, options)
|
7
|
+
res = get(contribution_path, options.sort)
|
8
|
+
Response::Contribution.format(res.dig('ContributionListResult', 'Contributions', 'Contribution'))
|
9
|
+
end
|
10
|
+
|
11
|
+
def find_contributions_by_batch_id(batch_id, options = {})
|
12
|
+
path = "batch/#{batch_id}/contribution/list"
|
13
|
+
options[:api_sig] = generate_api_sig(path, options)
|
14
|
+
|
15
|
+
res = get(path, options.sort)
|
16
|
+
Response::Contribution.format(res.dig('ContributionListResult', 'Contributions', 'Contribution'))
|
17
|
+
end
|
18
|
+
|
19
|
+
def find_contribution(id, options = {})
|
20
|
+
options[:api_sig] = generate_api_sig(contribution_path(id), options)
|
21
|
+
res = get(contribution_path(id), options.sort)
|
22
|
+
Response::Contribution.format(res.dig('Contribution'))
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_contribution(
|
26
|
+
batch_id,
|
27
|
+
person_id:,
|
28
|
+
date:,
|
29
|
+
currency_type_id:,
|
30
|
+
transaction_number:,
|
31
|
+
contribution_funds:
|
32
|
+
)
|
33
|
+
path = "batch/#{batch_id}/contribution/add"
|
34
|
+
|
35
|
+
body = {
|
36
|
+
'BatchId' => batch_id,
|
37
|
+
'CurrencyAmount' => sum_of_funds(contribution_funds),
|
38
|
+
'TransactionNumber' => transaction_number,
|
39
|
+
'ContributionDate' => date,
|
40
|
+
'CurrencyTypeId' => currency_type_id,
|
41
|
+
'PersonId' => person_id,
|
42
|
+
'ContributionFunds' => translate_funds(contribution_funds)
|
43
|
+
}
|
44
|
+
|
45
|
+
options = {}
|
46
|
+
options[:api_sig] = generate_api_sig(path, options)
|
47
|
+
|
48
|
+
res = json_post("#{path}?api_session=#{options[:api_session]}&api_sig=#{options[:api_sig]}", body.to_json)
|
49
|
+
res.dig('ModifyResult', 'ObjectID')
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def sum_of_funds(contribution_funds)
|
55
|
+
contribution_funds.map { |fund| fund[:amount] }.sum
|
56
|
+
end
|
57
|
+
|
58
|
+
def translate_funds(contribution_funds)
|
59
|
+
contribution_funds.map do |fund|
|
60
|
+
{
|
61
|
+
'FundId' => fund[:fund_id],
|
62
|
+
'Amount' => fund[:amount]
|
63
|
+
}
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def contribution_path(id = nil)
|
68
|
+
id ? "contribution/#{id}" : 'contribution/list'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ShelbyArena
|
2
|
+
class Client
|
3
|
+
module Fund
|
4
|
+
def list_funds(options = {})
|
5
|
+
options[:api_sig] = generate_api_sig(fund_path, options)
|
6
|
+
res = get(fund_path, options.sort)
|
7
|
+
Response::Fund.format(res.dig('FundListResult', 'Funds', 'Fund'))
|
8
|
+
end
|
9
|
+
|
10
|
+
def find_fund(id, options = {})
|
11
|
+
options[:api_sig] = generate_api_sig(fund_path(id), options)
|
12
|
+
res = get(fund_path(id), options.sort)
|
13
|
+
Response::Fund.format(res.dig('Fund'))
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def fund_path(id = nil)
|
19
|
+
id ? "fund/#{id}" : 'fund/list'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module ShelbyArena
|
2
|
+
class Client
|
3
|
+
module Person
|
4
|
+
def list_people(options = {})
|
5
|
+
options[:api_sig] = generate_api_sig(people_path, options)
|
6
|
+
res = get(people_path, options.sort)
|
7
|
+
Response::Person.format(res.dig('PersonListResult', 'Persons', 'Person'))
|
8
|
+
end
|
9
|
+
|
10
|
+
def find_people_by_name_and_email(first_name, last_name, email)
|
11
|
+
list_people(firstName: first_name, lastName: last_name, email: email)
|
12
|
+
end
|
13
|
+
|
14
|
+
def find_people_by_email(email)
|
15
|
+
list_people(email: email)
|
16
|
+
end
|
17
|
+
|
18
|
+
def find_person(id, options = {})
|
19
|
+
path = people_path(id)
|
20
|
+
options[:api_sig] = generate_api_sig(path, options)
|
21
|
+
res = get(path, options.sort)
|
22
|
+
Response::Person.format(res.dig('Person'))
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_person(
|
26
|
+
first_name:,
|
27
|
+
last_name:,
|
28
|
+
email:
|
29
|
+
)
|
30
|
+
path = 'person/add'
|
31
|
+
|
32
|
+
body = {
|
33
|
+
'FirstName' => first_name,
|
34
|
+
'LastName' => last_name,
|
35
|
+
'Emails' => ['Address' => email]
|
36
|
+
}
|
37
|
+
|
38
|
+
options = {}
|
39
|
+
options[:api_sig] = generate_api_sig(path, options)
|
40
|
+
res = json_post("#{path}?api_session=#{options[:api_session]}&api_sig=#{options[:api_sig]}", body.to_json)
|
41
|
+
res.dig('ModifyResult', 'ObjectID')
|
42
|
+
end
|
43
|
+
|
44
|
+
def update_person(
|
45
|
+
id,
|
46
|
+
first_name: nil,
|
47
|
+
last_name: nil,
|
48
|
+
email: nil
|
49
|
+
)
|
50
|
+
path = "#{people_path(id)}/update"
|
51
|
+
|
52
|
+
body = {}
|
53
|
+
|
54
|
+
body['FirstName'] = first_name if first_name
|
55
|
+
body['LastName'] = last_name if last_name
|
56
|
+
body['Emails'] = ['Address' => email] if email
|
57
|
+
|
58
|
+
options = {}
|
59
|
+
options[:api_sig] = generate_api_sig(path, options)
|
60
|
+
|
61
|
+
res = json_post("#{path}?api_session=#{options[:api_session]}&api_sig=#{options[:api_sig]}", body.to_json)
|
62
|
+
res.dig('ModifyResult', 'ObjectID')
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def people_path(id = nil)
|
68
|
+
id ? "person/#{id}" : 'person/list'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module ShelbyArena
|
2
|
+
module Response
|
3
|
+
class Base
|
4
|
+
attr_reader :data
|
5
|
+
|
6
|
+
def self.format(data)
|
7
|
+
new(data).format
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(data)
|
11
|
+
@data = data
|
12
|
+
end
|
13
|
+
|
14
|
+
def format
|
15
|
+
if data.is_a?(Array)
|
16
|
+
data.map { |item| format_single(item) }
|
17
|
+
else
|
18
|
+
format_single(data)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_h(dict, data)
|
23
|
+
return {} if data.nil?
|
24
|
+
|
25
|
+
dict.each_with_object({}) do |(l, r), object|
|
26
|
+
object[l] = data[r]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_boolean(string)
|
31
|
+
string.downcase == 'true'
|
32
|
+
end
|
33
|
+
|
34
|
+
def date_parse(string)
|
35
|
+
return DateTime.parse(string) if string
|
36
|
+
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ShelbyArena
|
2
|
+
module Response
|
3
|
+
class Batch < Base
|
4
|
+
MAP = {
|
5
|
+
name: 'BatchName',
|
6
|
+
id: 'BatchId',
|
7
|
+
start_date: 'BatchDate',
|
8
|
+
end_date: 'BatchDateEnd',
|
9
|
+
verify_amount: 'VerifyAmount',
|
10
|
+
finalized: 'Finalized'
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
def format_single(data)
|
14
|
+
response = to_h(MAP, data)
|
15
|
+
response[:start_date] = date_parse(response[:start_date])
|
16
|
+
response[:end_date] = date_parse(response[:end_date])
|
17
|
+
response[:verify_amount] = response[:verify_amount].to_f
|
18
|
+
response[:finalized] = to_boolean(response[:finalized])
|
19
|
+
response
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ShelbyArena
|
2
|
+
module Response
|
3
|
+
class Contribution < Base
|
4
|
+
MAP = {
|
5
|
+
id: 'ContributionId',
|
6
|
+
batch_id: 'BatchId',
|
7
|
+
amount: 'CurrencyAmount',
|
8
|
+
date: 'ContributionDate',
|
9
|
+
memo: 'Memo',
|
10
|
+
person_id: 'PersonId',
|
11
|
+
person: 'PersonInformation',
|
12
|
+
transaction_number: 'TransactionNumber',
|
13
|
+
currency_type_id: 'CurrencyTypeId',
|
14
|
+
currency_type_value: 'CurrencyTypeValue',
|
15
|
+
contribution_funds: 'ContributionFunds'
|
16
|
+
}.freeze
|
17
|
+
|
18
|
+
|
19
|
+
def format_single(data)
|
20
|
+
response = to_h(MAP, data)
|
21
|
+
response[:contribution_funds] = ContributionFund.format(response[:contribution_funds].dig('ContributionFund')) if response[:contribution_funds]
|
22
|
+
response[:person] = Person.format(response[:person])
|
23
|
+
response[:amount] = response[:amount].to_f
|
24
|
+
response
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ShelbyArena
|
2
|
+
module Response
|
3
|
+
class ContributionFund < Base
|
4
|
+
MAP = {
|
5
|
+
id: 'ContributionFundId',
|
6
|
+
contribution_id: 'ContributionId',
|
7
|
+
amount: 'Amount',
|
8
|
+
fund: 'Fund',
|
9
|
+
fund_id: 'FundId'
|
10
|
+
}.freeze
|
11
|
+
|
12
|
+
def format_single(data)
|
13
|
+
response = to_h(MAP, data)
|
14
|
+
response[:fund] = Fund.format(response[:fund])
|
15
|
+
response[:amount] = response[:amount].to_f
|
16
|
+
response
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ShelbyArena
|
2
|
+
module Response
|
3
|
+
class Fund < Base
|
4
|
+
MAP = {
|
5
|
+
id: 'FundId',
|
6
|
+
active: 'Active',
|
7
|
+
name: 'FundName',
|
8
|
+
online_name: 'OnlineName',
|
9
|
+
description: 'FundDescription',
|
10
|
+
is_tax_deductible: 'TaxDeductible',
|
11
|
+
start_date: 'StartDate',
|
12
|
+
end_date: 'EndDate'
|
13
|
+
}.freeze
|
14
|
+
|
15
|
+
def format_single(data)
|
16
|
+
to_h(MAP, data)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module ShelbyArena
|
2
|
+
module Response
|
3
|
+
class Person < Base
|
4
|
+
MAP = {
|
5
|
+
age: 'Age',
|
6
|
+
first_name: 'FirstName',
|
7
|
+
last_name: 'LastName',
|
8
|
+
person_id: 'PersonID',
|
9
|
+
person_link: 'PersonLink',
|
10
|
+
gender: 'Gender'
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
def format_single(data)
|
14
|
+
response = to_h(MAP, data)
|
15
|
+
response[:email] = set_email(data)
|
16
|
+
response[:emails] = set_emails(data)
|
17
|
+
response
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def set_email(raw_response)
|
23
|
+
# find_person returns an array of `Emails`
|
24
|
+
# list_person return `FirstActiveEmail`
|
25
|
+
raw_response.dig('FirstActiveEmail') || raw_response.dig('Emails', 'Email', 0, 'Address')
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_emails(raw_response)
|
29
|
+
# find_person returns an array of `Emails`
|
30
|
+
# list_person return `FirstActiveEmail`
|
31
|
+
raw_response.dig('Emails', 'Email')&.map { |email| email.dig('Address') } || []
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/shelby_arena.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
$:.push File.expand_path('../lib', __FILE__)
|
2
|
+
require 'shelby_arena/version'
|
3
|
+
require 'base64'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'shelby_arena'
|
7
|
+
s.version = ShelbyArena::VERSION
|
8
|
+
s.authors = ['Taylor Brooks']
|
9
|
+
s.email = ['dGJyb29rc0BnbWFpbC5jb20='].map { |e| Base64.decode64(e) }
|
10
|
+
s.homepage = 'https://github.com/taylorbrooks/shelby_arena'
|
11
|
+
s.summary = 'A Ruby wrapper for the Shelby Arena API'
|
12
|
+
s.description = 'A Ruby wrapper for the Shelby Arena API -- a church management platform.'
|
13
|
+
s.license = 'MIT'
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split($/)
|
16
|
+
s.executables = s.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
17
|
+
s.test_files = s.files.grep(%r{^(test)/})
|
18
|
+
|
19
|
+
s.required_ruby_version = '>= 2.7'
|
20
|
+
|
21
|
+
s.require_paths = ['lib']
|
22
|
+
|
23
|
+
s.add_runtime_dependency 'faraday', '> 2.0'
|
24
|
+
s.add_runtime_dependency 'faraday-multipart'
|
25
|
+
|
26
|
+
s.add_development_dependency 'bundler', '~> 2.3'
|
27
|
+
s.add_development_dependency 'dotenv'
|
28
|
+
s.add_development_dependency 'pry'
|
29
|
+
s.add_development_dependency 'rake', '~> 12.3.3'
|
30
|
+
s.add_development_dependency 'rspec', '~> 3.7'
|
31
|
+
s.add_development_dependency 'sinatra', '~> 2.0'
|
32
|
+
s.add_development_dependency 'webmock', '~> 3.1'
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shelby_arena
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Taylor Brooks
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-02-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday-multipart
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dotenv
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 12.3.3
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 12.3.3
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.7'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.7'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: sinatra
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '2.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '2.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.1'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3.1'
|
139
|
+
description: A Ruby wrapper for the Shelby Arena API -- a church management platform.
|
140
|
+
email:
|
141
|
+
- tbrooks@gmail.com
|
142
|
+
executables:
|
143
|
+
- rspec
|
144
|
+
extensions: []
|
145
|
+
extra_rdoc_files: []
|
146
|
+
files:
|
147
|
+
- ".github/workflows/test.yml"
|
148
|
+
- ".gitignore"
|
149
|
+
- ".ruby-version"
|
150
|
+
- ".travis.yml"
|
151
|
+
- Gemfile
|
152
|
+
- LICENSE
|
153
|
+
- README.md
|
154
|
+
- Rakefile
|
155
|
+
- bin/rspec
|
156
|
+
- lib/shelby_arena.rb
|
157
|
+
- lib/shelby_arena/client.rb
|
158
|
+
- lib/shelby_arena/error.rb
|
159
|
+
- lib/shelby_arena/resources/batch.rb
|
160
|
+
- lib/shelby_arena/resources/contribution.rb
|
161
|
+
- lib/shelby_arena/resources/fund.rb
|
162
|
+
- lib/shelby_arena/resources/person.rb
|
163
|
+
- lib/shelby_arena/response/base.rb
|
164
|
+
- lib/shelby_arena/response/batch.rb
|
165
|
+
- lib/shelby_arena/response/contribution.rb
|
166
|
+
- lib/shelby_arena/response/contribution_fund.rb
|
167
|
+
- lib/shelby_arena/response/fund.rb
|
168
|
+
- lib/shelby_arena/response/person.rb
|
169
|
+
- lib/shelby_arena/version.rb
|
170
|
+
- shelby_arena.gemspec
|
171
|
+
homepage: https://github.com/taylorbrooks/shelby_arena
|
172
|
+
licenses:
|
173
|
+
- MIT
|
174
|
+
metadata: {}
|
175
|
+
post_install_message:
|
176
|
+
rdoc_options: []
|
177
|
+
require_paths:
|
178
|
+
- lib
|
179
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
180
|
+
requirements:
|
181
|
+
- - ">="
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: '2.7'
|
184
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
requirements: []
|
190
|
+
rubygems_version: 3.1.6
|
191
|
+
signing_key:
|
192
|
+
specification_version: 4
|
193
|
+
summary: A Ruby wrapper for the Shelby Arena API
|
194
|
+
test_files: []
|