chmeetings 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/CHANGELOG.md +19 -0
  6. data/Gemfile +16 -0
  7. data/LICENSE +21 -0
  8. data/README.md +68 -0
  9. data/Rakefile +24 -0
  10. data/chmeetings.gemspec +25 -0
  11. data/lib/chmeetings/client/campaign.rb +9 -0
  12. data/lib/chmeetings/client/contribution.rb +13 -0
  13. data/lib/chmeetings/client/family.rb +25 -0
  14. data/lib/chmeetings/client/family_member.rb +25 -0
  15. data/lib/chmeetings/client/group.rb +9 -0
  16. data/lib/chmeetings/client/person.rb +21 -0
  17. data/lib/chmeetings/client/pledge.rb +9 -0
  18. data/lib/chmeetings/client.rb +41 -0
  19. data/lib/chmeetings/error.rb +58 -0
  20. data/lib/chmeetings/parse_oj.rb +26 -0
  21. data/lib/chmeetings/version.rb +5 -0
  22. data/lib/chmeetings.rb +7 -0
  23. data/spec/chmeetings/client_spec.rb +115 -0
  24. data/spec/chmeetings/error_spec.rb +79 -0
  25. data/spec/chmeetings/resources/campaign_spec.rb +25 -0
  26. data/spec/chmeetings/resources/contribution_spec.rb +39 -0
  27. data/spec/chmeetings/resources/family_member_spec.rb +75 -0
  28. data/spec/chmeetings/resources/family_spec.rb +81 -0
  29. data/spec/chmeetings/resources/group_spec.rb +25 -0
  30. data/spec/chmeetings/resources/person_spec.rb +67 -0
  31. data/spec/chmeetings/resources/pledge_spec.rb +25 -0
  32. data/spec/chmeetings_spec.rb +7 -0
  33. data/spec/spec_helper.rb +25 -0
  34. data/spec/support/chmeetings_mock.rb +63 -0
  35. data/spec/support/client_factory.rb +10 -0
  36. data/spec/support/fixtures/campaigns.json +16 -0
  37. data/spec/support/fixtures/contribution.json +9 -0
  38. data/spec/support/fixtures/contributions.json +22 -0
  39. data/spec/support/fixtures/families.json +14 -0
  40. data/spec/support/fixtures/family.json +5 -0
  41. data/spec/support/fixtures/family_member.json +7 -0
  42. data/spec/support/fixtures/family_members.json +18 -0
  43. data/spec/support/fixtures/groups.json +16 -0
  44. data/spec/support/fixtures/people.json +20 -0
  45. data/spec/support/fixtures/person.json +8 -0
  46. data/spec/support/fixtures/pledges.json +13 -0
  47. data/spec/support/fixtures_helper.rb +5 -0
  48. metadata +117 -0
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Chmeetings::Client::Campaign, type: :model do
4
+ include_context 'resource specs'
5
+
6
+ describe '#list_campaigns' do
7
+ it 'returns a hash' do
8
+ expect(client.list_campaigns).to be_a(Hash)
9
+ end
10
+
11
+ it 'queries campaigns' do
12
+ expect(client).to receive(:get).with('campaigns', {}).and_call_original
13
+
14
+ resource = client.list_campaigns
15
+
16
+ expect(resource['data'].first['campaign_id']).to eq(1)
17
+ end
18
+
19
+ it 'passes options' do
20
+ expect(client).to receive(:get).with('campaigns', { page: 1 }).and_call_original
21
+
22
+ client.list_campaigns(page: 1)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Chmeetings::Client::Contribution, type: :model do
4
+ include_context 'resource specs'
5
+
6
+ describe '#list_contributions' do
7
+ it 'returns a hash' do
8
+ expect(client.list_contributions).to be_a(Hash)
9
+ end
10
+
11
+ it 'queries contributions' do
12
+ expect(client).to receive(:get).with('contributions', {}).and_call_original
13
+
14
+ resource = client.list_contributions
15
+
16
+ expect(resource['data'].first['contribution_id']).to eq(1)
17
+ end
18
+
19
+ it 'passes options' do
20
+ expect(client).to receive(:get).with('contributions', { page: 1 }).and_call_original
21
+
22
+ client.list_contributions(page: 1)
23
+ end
24
+ end
25
+
26
+ describe '#create_contribution' do
27
+ it 'returns a hash' do
28
+ expect(client.create_contribution(person_id: 1, amount: 100.0)).to be_a(Hash)
29
+ end
30
+
31
+ it 'passes data' do
32
+ expect(client).to receive(:post)
33
+ .with('contributions', { person_id: 1, amount: 100.0 })
34
+ .and_call_original
35
+
36
+ client.create_contribution(person_id: 1, amount: 100.0)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Chmeetings::Client::FamilyMember, type: :model do
4
+ include_context 'resource specs'
5
+
6
+ describe '#list_family_members' do
7
+ it 'returns a hash' do
8
+ expect(client.list_family_members(family_id: 1)).to be_a(Hash)
9
+ end
10
+
11
+ it 'queries family members' do
12
+ expect(client).to receive(:get).with('family-members', { family_id: 1 }).and_call_original
13
+
14
+ resource = client.list_family_members(family_id: 1)
15
+
16
+ expect(resource['data'].first['id']).to eq(1)
17
+ end
18
+ end
19
+
20
+ describe '#create_family_member' do
21
+ it 'returns a hash' do
22
+ expect(client.create_family_member(family_id: 1, person_id: 1)).to be_a(Hash)
23
+ end
24
+
25
+ it 'passes data' do
26
+ expect(client).to receive(:post)
27
+ .with('family-members', { family_id: 1, person_id: 1 })
28
+ .and_call_original
29
+
30
+ client.create_family_member(family_id: 1, person_id: 1)
31
+ end
32
+ end
33
+
34
+ describe '#update_family_member' do
35
+ it 'returns a hash' do
36
+ expect(client.update_family_member(id: 1, family_id: 1, person_id: 2)).to be_a(Hash)
37
+ end
38
+
39
+ it 'passes data' do
40
+ expect(client).to receive(:put)
41
+ .with('family-members', { id: 1, family_id: 1, person_id: 2 })
42
+ .and_call_original
43
+
44
+ client.update_family_member(id: 1, family_id: 1, person_id: 2)
45
+ end
46
+ end
47
+
48
+ describe '#patch_family_member' do
49
+ it 'returns a hash' do
50
+ expect(client.patch_family_member(id: 1, role: 'Head')).to be_a(Hash)
51
+ end
52
+
53
+ it 'passes data' do
54
+ expect(client).to receive(:patch)
55
+ .with('family-members', { id: 1, role: 'Head' })
56
+ .and_call_original
57
+
58
+ client.patch_family_member(id: 1, role: 'Head')
59
+ end
60
+ end
61
+
62
+ describe '#delete_family_member' do
63
+ it 'returns a hash' do
64
+ expect(client.delete_family_member(id: 1)).to be_a(Hash)
65
+ end
66
+
67
+ it 'passes data' do
68
+ expect(client).to receive(:post)
69
+ .with('family-members/delete', { id: 1 })
70
+ .and_call_original
71
+
72
+ client.delete_family_member(id: 1)
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Chmeetings::Client::Family, type: :model do
4
+ include_context 'resource specs'
5
+
6
+ describe '#list_families' do
7
+ it 'returns a hash' do
8
+ expect(client.list_families).to be_a(Hash)
9
+ end
10
+
11
+ it 'queries families' do
12
+ expect(client).to receive(:get).with('families', {}).and_call_original
13
+
14
+ resource = client.list_families
15
+
16
+ expect(resource['data'].first['family_id']).to eq(1)
17
+ end
18
+
19
+ it 'passes options' do
20
+ expect(client).to receive(:get).with('families', { page: 1 }).and_call_original
21
+
22
+ client.list_families(page: 1)
23
+ end
24
+ end
25
+
26
+ describe '#create_family' do
27
+ it 'returns a hash' do
28
+ expect(client.create_family(name: 'Doe Family')).to be_a(Hash)
29
+ end
30
+
31
+ it 'passes data' do
32
+ expect(client).to receive(:post)
33
+ .with('families', { name: 'Doe Family' })
34
+ .and_call_original
35
+
36
+ client.create_family(name: 'Doe Family')
37
+ end
38
+ end
39
+
40
+ describe '#get_family' do
41
+ it 'returns a hash' do
42
+ expect(client.get_family(family_id: 1)).to be_a(Hash)
43
+ end
44
+
45
+ it 'passes options' do
46
+ expect(client).to receive(:get)
47
+ .with('families/show', { family_id: 1 })
48
+ .and_call_original
49
+
50
+ client.get_family(family_id: 1)
51
+ end
52
+ end
53
+
54
+ describe '#update_family' do
55
+ it 'returns a hash' do
56
+ expect(client.update_family(family_id: 1, name: 'Smith Family')).to be_a(Hash)
57
+ end
58
+
59
+ it 'passes data' do
60
+ expect(client).to receive(:put)
61
+ .with('families', { family_id: 1, name: 'Smith Family' })
62
+ .and_call_original
63
+
64
+ client.update_family(family_id: 1, name: 'Smith Family')
65
+ end
66
+ end
67
+
68
+ describe '#delete_family' do
69
+ it 'returns a hash' do
70
+ expect(client.delete_family(family_id: 1)).to be_a(Hash)
71
+ end
72
+
73
+ it 'passes data' do
74
+ expect(client).to receive(:post)
75
+ .with('families/delete', { family_id: 1 })
76
+ .and_call_original
77
+
78
+ client.delete_family(family_id: 1)
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Chmeetings::Client::Group, type: :model do
4
+ include_context 'resource specs'
5
+
6
+ describe '#list_groups' do
7
+ it 'returns a hash' do
8
+ expect(client.list_groups).to be_a(Hash)
9
+ end
10
+
11
+ it 'queries groups' do
12
+ expect(client).to receive(:get).with('groups', {}).and_call_original
13
+
14
+ resource = client.list_groups
15
+
16
+ expect(resource['data'].first['group_id']).to eq(1)
17
+ end
18
+
19
+ it 'passes options' do
20
+ expect(client).to receive(:get).with('groups', { page: 1 }).and_call_original
21
+
22
+ client.list_groups(page: 1)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Chmeetings::Client::Person, type: :model do
4
+ include_context 'resource specs'
5
+
6
+ describe '#list_people' do
7
+ it 'returns a hash' do
8
+ expect(client.list_people).to be_a(Hash)
9
+ end
10
+
11
+ it 'queries people' do
12
+ expect(client).to receive(:get).with('people', {}).and_call_original
13
+
14
+ resource = client.list_people
15
+
16
+ expect(resource['data'].first['person_id']).to eq(1)
17
+ end
18
+
19
+ it 'passes options' do
20
+ expect(client).to receive(:get).with('people', { page: 1 }).and_call_original
21
+
22
+ client.list_people(page: 1)
23
+ end
24
+ end
25
+
26
+ describe '#create_person' do
27
+ it 'returns a hash' do
28
+ expect(client.create_person(first_name: 'John', last_name: 'Doe')).to be_a(Hash)
29
+ end
30
+
31
+ it 'passes data' do
32
+ expect(client).to receive(:post)
33
+ .with('people', { first_name: 'John', last_name: 'Doe' })
34
+ .and_call_original
35
+
36
+ client.create_person(first_name: 'John', last_name: 'Doe')
37
+ end
38
+ end
39
+
40
+ describe '#update_person' do
41
+ it 'returns a hash' do
42
+ expect(client.update_person(person_id: 1, first_name: 'Jane')).to be_a(Hash)
43
+ end
44
+
45
+ it 'passes data' do
46
+ expect(client).to receive(:put)
47
+ .with('people', { person_id: 1, first_name: 'Jane' })
48
+ .and_call_original
49
+
50
+ client.update_person(person_id: 1, first_name: 'Jane')
51
+ end
52
+ end
53
+
54
+ describe '#delete_person' do
55
+ it 'returns a hash' do
56
+ expect(client.delete_person(person_id: 1)).to be_a(Hash)
57
+ end
58
+
59
+ it 'passes data' do
60
+ expect(client).to receive(:post)
61
+ .with('people/delete', { person_id: 1 })
62
+ .and_call_original
63
+
64
+ client.delete_person(person_id: 1)
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Chmeetings::Client::Pledge, type: :model do
4
+ include_context 'resource specs'
5
+
6
+ describe '#list_pledges' do
7
+ it 'returns a hash' do
8
+ expect(client.list_pledges).to be_a(Hash)
9
+ end
10
+
11
+ it 'queries pledges' do
12
+ expect(client).to receive(:get).with('pledges', {}).and_call_original
13
+
14
+ resource = client.list_pledges
15
+
16
+ expect(resource['data'].first['pledge_id']).to eq(1)
17
+ end
18
+
19
+ it 'passes options' do
20
+ expect(client).to receive(:get).with('pledges', { page: 1 }).and_call_original
21
+
22
+ client.list_pledges(page: 1)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Chmeetings do
4
+ it 'has a version number' do
5
+ expect(described_class::VERSION).to_not be_nil
6
+ end
7
+ end
@@ -0,0 +1,25 @@
1
+ $LOAD_PATH.unshift(File.join(__FILE__, '..', '..', 'lib'))
2
+
3
+ SPEC_DIR = File.dirname(__FILE__)
4
+ FIXTURES_DIR = File.join(SPEC_DIR, 'support', 'fixtures')
5
+
6
+ require 'chmeetings'
7
+ require 'webmock/rspec'
8
+ require_relative 'support/fixtures_helper'
9
+ require_relative 'support/chmeetings_mock'
10
+ require_relative 'support/client_factory'
11
+
12
+ RSpec.configure do |config|
13
+ config.before :suite do
14
+ WebMock.disable_net_connect!
15
+ end
16
+
17
+ config.before :each do
18
+ stub_request(:any, /chmeetings/).to_rack(ChmeetingsMock)
19
+ end
20
+
21
+ config.run_all_when_everything_filtered = true
22
+ config.filter_run :focus
23
+
24
+ config.order = 'random'
25
+ end
@@ -0,0 +1,63 @@
1
+ require 'sinatra/base'
2
+ require_relative 'fixtures_helper'
3
+
4
+ class ChmeetingsMock < Sinatra::Base
5
+ # GET requests
6
+ {
7
+ 'people' => :people,
8
+ 'families' => :families,
9
+ 'families/show' => :family,
10
+ 'family-members' => :family_members,
11
+ 'groups' => :groups,
12
+ 'contributions' => :contributions,
13
+ 'pledges' => :pledges,
14
+ 'campaigns' => :campaigns
15
+ }.each do |end_point, json|
16
+ get "/api/v1/#{end_point}" do
17
+ json_response 200, "#{json}.json"
18
+ end
19
+ end
20
+
21
+ # POST requests
22
+ {
23
+ 'people' => :person,
24
+ 'people/delete' => :person,
25
+ 'families' => :family,
26
+ 'families/delete' => :family,
27
+ 'family-members' => :family_member,
28
+ 'family-members/delete' => :family_member,
29
+ 'contributions' => :contribution
30
+ }.each do |end_point, json|
31
+ post "/api/v1/#{end_point}" do
32
+ json_response 200, "#{json}.json"
33
+ end
34
+ end
35
+
36
+ # PUT requests
37
+ {
38
+ 'people' => :person,
39
+ 'families' => :family,
40
+ 'family-members' => :family_member
41
+ }.each do |end_point, json|
42
+ put "/api/v1/#{end_point}" do
43
+ json_response 200, "#{json}.json"
44
+ end
45
+ end
46
+
47
+ # PATCH requests
48
+ {
49
+ 'family-members' => :family_member
50
+ }.each do |end_point, json|
51
+ patch "/api/v1/#{end_point}" do
52
+ json_response 200, "#{json}.json"
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def json_response(response_code, file_name)
59
+ content_type :json
60
+ status response_code
61
+ FixturesHelper.read(file_name)
62
+ end
63
+ end
@@ -0,0 +1,10 @@
1
+ RSpec.shared_context 'resource specs' do
2
+ let(:attrs) do
3
+ {
4
+ api_key: 'test_api_key',
5
+ base_url: 'http://api.chmeetings.com/api/v1/'
6
+ }
7
+ end
8
+
9
+ let(:client) { Chmeetings::Client.new(**attrs) }
10
+ end
@@ -0,0 +1,16 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "campaign_id": 1,
5
+ "name": "General Fund",
6
+ "description": "General donations",
7
+ "created_at": "2026-01-15T10:00:00"
8
+ },
9
+ {
10
+ "campaign_id": 2,
11
+ "name": "Building Fund",
12
+ "description": "New building project",
13
+ "created_at": "2026-01-16T10:00:00"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "contribution_id": 1,
3
+ "person_id": 1,
4
+ "amount": 100.0,
5
+ "date": "2026-01-15",
6
+ "campaign_id": 1,
7
+ "method": "Credit Card",
8
+ "created_at": "2026-01-15T10:00:00"
9
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "contribution_id": 1,
5
+ "person_id": 1,
6
+ "amount": 100.0,
7
+ "date": "2026-01-15",
8
+ "campaign_id": 1,
9
+ "method": "Credit Card",
10
+ "created_at": "2026-01-15T10:00:00"
11
+ },
12
+ {
13
+ "contribution_id": 2,
14
+ "person_id": 2,
15
+ "amount": 50.0,
16
+ "date": "2026-01-16",
17
+ "campaign_id": 1,
18
+ "method": "Check",
19
+ "created_at": "2026-01-16T10:00:00"
20
+ }
21
+ ]
22
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "family_id": 1,
5
+ "name": "Doe Family",
6
+ "created_at": "2026-01-15T10:00:00"
7
+ },
8
+ {
9
+ "family_id": 2,
10
+ "name": "Smith Family",
11
+ "created_at": "2026-01-16T10:00:00"
12
+ }
13
+ ]
14
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "family_id": 1,
3
+ "name": "Doe Family",
4
+ "created_at": "2026-01-15T10:00:00"
5
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "id": 1,
3
+ "family_id": 1,
4
+ "person_id": 1,
5
+ "role": "Head",
6
+ "created_at": "2026-01-15T10:00:00"
7
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "id": 1,
5
+ "family_id": 1,
6
+ "person_id": 1,
7
+ "role": "Head",
8
+ "created_at": "2026-01-15T10:00:00"
9
+ },
10
+ {
11
+ "id": 2,
12
+ "family_id": 1,
13
+ "person_id": 2,
14
+ "role": "Spouse",
15
+ "created_at": "2026-01-16T10:00:00"
16
+ }
17
+ ]
18
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "group_id": 1,
5
+ "name": "Youth Group",
6
+ "description": "Youth ministry group",
7
+ "created_at": "2026-01-15T10:00:00"
8
+ },
9
+ {
10
+ "group_id": 2,
11
+ "name": "Worship Team",
12
+ "description": "Sunday worship team",
13
+ "created_at": "2026-01-16T10:00:00"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "person_id": 1,
5
+ "first_name": "John",
6
+ "last_name": "Doe",
7
+ "email": "john@example.com",
8
+ "phone": "555-1234",
9
+ "created_at": "2026-01-15T10:00:00"
10
+ },
11
+ {
12
+ "person_id": 2,
13
+ "first_name": "Jane",
14
+ "last_name": "Doe",
15
+ "email": "jane@example.com",
16
+ "phone": "555-5678",
17
+ "created_at": "2026-01-16T10:00:00"
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "person_id": 1,
3
+ "first_name": "John",
4
+ "last_name": "Doe",
5
+ "email": "john@example.com",
6
+ "phone": "555-1234",
7
+ "created_at": "2026-01-15T10:00:00"
8
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "pledge_id": 1,
5
+ "person_id": 1,
6
+ "amount": 1200.0,
7
+ "campaign_id": 1,
8
+ "start_date": "2026-01-01",
9
+ "end_date": "2026-12-31",
10
+ "created_at": "2026-01-15T10:00:00"
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,5 @@
1
+ class FixturesHelper
2
+ def self.read(path)
3
+ File.binread(File.join(FIXTURES_DIR, path))
4
+ end
5
+ end