hcbv4 0.1.0

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.
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HCBV4
4
+ # An inter-organization fund transfer.
5
+ # @attr_reader transaction_id [String, nil] associated ledger entry
6
+ # @attr_reader from [Organization, nil] source organization
7
+ # @attr_reader to [Organization, nil] destination organization
8
+ # @attr_reader sender [User, nil] user who initiated the transfer
9
+ # @attr_reader card_grant_id [String, nil] associated card grant
10
+ # @attr_reader organization [Organization, nil] organization context for fetching transaction
11
+ class Transfer < BaseTransactionDetail
12
+ attr_reader :transaction_id, :from, :to, :sender, :card_grant_id, :organization, :_client
13
+
14
+ def initialize(id:, amount_cents: nil, memo: nil, status: nil, transaction_id: nil, from: nil, to: nil,
15
+ sender: nil, card_grant_id: nil, organization: nil, client: nil)
16
+ super(id:, amount_cents:, memo:, status:)
17
+ @transaction_id = transaction_id
18
+ @from = from
19
+ @to = to
20
+ @sender = sender
21
+ @card_grant_id = card_grant_id
22
+ @organization = organization
23
+ @_client = client
24
+ end
25
+
26
+ # Fetches the associated transaction.
27
+ # @return [Transaction]
28
+ def transaction
29
+ raise Error, "No client attached to this Transfer" unless _client
30
+ raise Error, "No transaction_id on this Transfer" unless transaction_id
31
+
32
+ _client.transaction(transaction_id)
33
+ end
34
+
35
+ # Stubs a Transaction with the associated transaction ID and organization.
36
+ # @return [Transaction]
37
+ def transaction!
38
+ raise Error, "No client attached to this Transfer" unless _client
39
+ raise Error, "No transaction_id on this Transfer" unless transaction_id
40
+
41
+ Transaction.of_id(transaction_id, client: _client, organization:)
42
+ end
43
+
44
+ # @param hash [Hash] API response
45
+ # @param client [Client, nil]
46
+ # @param organization [Organization, nil] organization context
47
+ # @return [Transfer]
48
+ def self.from_hash(hash, client: nil, organization: nil)
49
+ new(
50
+ id: hash["id"],
51
+ amount_cents: hash["amount_cents"],
52
+ memo: hash["memo"],
53
+ status: hash["status"],
54
+ transaction_id: hash["transaction_id"],
55
+ from: hash["from"] ? Organization.from_hash(hash["from"]) : nil,
56
+ to: hash["to"] ? Organization.from_hash(hash["to"]) : nil,
57
+ sender: hash["sender"] ? User.from_hash(hash["sender"]) : nil,
58
+ card_grant_id: hash["card_grant_id"],
59
+ organization:,
60
+ client:
61
+ )
62
+ end
63
+ end
64
+
65
+ # Alias for Transfer.
66
+ Disbursement = Transfer
67
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HCBV4
4
+ # Mailing address for physical card delivery.
5
+ ShippingAddress = Data.define(:address_line1, :address_line2, :city, :state, :country, :postal_code) do
6
+ def self.from_hash(hash)
7
+ return nil unless hash
8
+
9
+ new(
10
+ address_line1: hash["address_line1"],
11
+ address_line2: hash["address_line2"],
12
+ city: hash["city"],
13
+ state: hash["state"],
14
+ country: hash["country"],
15
+ postal_code: hash["postal_code"]
16
+ )
17
+ end
18
+ end
19
+
20
+ # An HCB user account.
21
+ # @attr_reader id [String] unique user id
22
+ # @attr_reader name [String, nil] display name
23
+ # @attr_reader email [String, nil] email address
24
+ # @attr_reader avatar [String, nil] avatar URL
25
+ # @attr_reader admin [Boolean, nil] HCB admin flag
26
+ # @attr_reader auditor [Boolean, nil] HCB auditor flag
27
+ # @attr_reader birthday [String, nil] ISO date
28
+ # @attr_reader shipping_address [ShippingAddress, nil] mailing address
29
+ class User
30
+ attr_reader :id, :name, :email, :avatar, :admin, :auditor, :birthday, :shipping_address, :_client
31
+
32
+ def initialize(id:, name: nil, email: nil, avatar: nil, admin: nil, auditor: nil, birthday: nil,
33
+ shipping_address: nil, _client: nil)
34
+ @id = id
35
+ @name = name
36
+ @email = email
37
+ @avatar = avatar
38
+ @admin = admin
39
+ @auditor = auditor
40
+ @birthday = birthday
41
+ @shipping_address = shipping_address
42
+ @_client = _client
43
+ end
44
+
45
+ # @param hash [Hash] API response
46
+ # @return [User]
47
+ def self.from_hash(hash, client: nil)
48
+ new(
49
+ id: hash["id"],
50
+ name: hash["name"],
51
+ email: hash["email"],
52
+ avatar: hash["avatar"],
53
+ admin: hash["admin"],
54
+ auditor: hash["auditor"],
55
+ birthday: hash["birthday"],
56
+ shipping_address: ShippingAddress.from_hash(hash["shipping_address"]),
57
+ _client: client
58
+ )
59
+ end
60
+
61
+ # @return [Boolean] true if user is an HCB admin
62
+ def admin? = !!admin
63
+
64
+ # @return [Boolean] true if user is an HCB auditor
65
+ def auditor? = !!auditor
66
+
67
+ def ==(other)
68
+ other.is_a?(User) && id == other.id
69
+ end
70
+ alias eql? ==
71
+
72
+ def hash
73
+ id.hash
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Modules first
4
+ require_relative "models/resource"
5
+ require_relative "models/transaction_type"
6
+
7
+ # Base classes (no dependencies)
8
+ require_relative "models/user"
9
+ require_relative "models/organization_user"
10
+ require_relative "models/tag"
11
+ require_relative "models/merchant"
12
+ require_relative "models/card_design"
13
+ require_relative "models/donation"
14
+
15
+ # Transaction detail base and subtypes
16
+ require_relative "models/base_transaction_detail"
17
+ require_relative "models/check"
18
+ require_relative "models/invoice_transaction"
19
+ require_relative "models/donation_transaction"
20
+ require_relative "models/expense_payout"
21
+
22
+ # Models with Organization/User dependencies
23
+ require_relative "models/organization"
24
+ require_relative "models/transfer"
25
+ require_relative "models/ach_transfer"
26
+ require_relative "models/stripe_card"
27
+ require_relative "models/card_charge"
28
+
29
+ # Models with complex dependencies
30
+ require_relative "models/card_grant"
31
+ require_relative "models/transaction"
32
+ require_relative "models/transaction_list"
33
+ require_relative "models/invoice"
34
+ require_relative "models/sponsor"
35
+ require_relative "models/receipt"
36
+ require_relative "models/comment"
37
+ require_relative "models/invitation"
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HCBV4
4
+ VERSION = "0.1.0"
5
+ end
data/lib/hcbv4.rb ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "hcbv4/version"
4
+ require_relative "hcbv4/errors"
5
+ require_relative "hcbv4/models"
6
+ require_relative "hcbv4/client"
7
+
8
+ module HCBV4
9
+ class Error < StandardError; end
10
+ end
data/sig/hcbv4.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Hcbv4
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hcbv4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - 24c02
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: A Ruby SDK for interacting with the Hack Club Bank (HCB) API v4. Provides
13
+ access to organizations, transactions, cards, and financial operations.
14
+ email:
15
+ - 163450896+24c02@users.noreply.github.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - README.md
21
+ - Rakefile
22
+ - lib/hcbv4.rb
23
+ - lib/hcbv4/client.rb
24
+ - lib/hcbv4/errors.rb
25
+ - lib/hcbv4/models.rb
26
+ - lib/hcbv4/models/ach_transfer.rb
27
+ - lib/hcbv4/models/base_transaction_detail.rb
28
+ - lib/hcbv4/models/card_charge.rb
29
+ - lib/hcbv4/models/card_design.rb
30
+ - lib/hcbv4/models/card_grant.rb
31
+ - lib/hcbv4/models/check.rb
32
+ - lib/hcbv4/models/comment.rb
33
+ - lib/hcbv4/models/donation.rb
34
+ - lib/hcbv4/models/donation_transaction.rb
35
+ - lib/hcbv4/models/expense_payout.rb
36
+ - lib/hcbv4/models/invitation.rb
37
+ - lib/hcbv4/models/invoice.rb
38
+ - lib/hcbv4/models/invoice_transaction.rb
39
+ - lib/hcbv4/models/merchant.rb
40
+ - lib/hcbv4/models/organization.rb
41
+ - lib/hcbv4/models/organization_user.rb
42
+ - lib/hcbv4/models/receipt.rb
43
+ - lib/hcbv4/models/resource.rb
44
+ - lib/hcbv4/models/sponsor.rb
45
+ - lib/hcbv4/models/stripe_card.rb
46
+ - lib/hcbv4/models/tag.rb
47
+ - lib/hcbv4/models/transaction.rb
48
+ - lib/hcbv4/models/transaction_list.rb
49
+ - lib/hcbv4/models/transaction_type.rb
50
+ - lib/hcbv4/models/transfer.rb
51
+ - lib/hcbv4/models/user.rb
52
+ - lib/hcbv4/version.rb
53
+ - sig/hcbv4.rbs
54
+ homepage: https://github.com/hackclub/hcbv4
55
+ licenses: []
56
+ metadata:
57
+ allowed_push_host: https://rubygems.org
58
+ homepage_uri: https://github.com/hackclub/hcbv4
59
+ source_code_uri: https://github.com/hackclub/hcbv4
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 3.2.0
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.6.7
75
+ specification_version: 4
76
+ summary: Ruby client for the HCB API v4.
77
+ test_files: []