finswitz 1.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 54616ae6e0c27453ac0bec222a63a10352624e4f27e40f061de18e271bb967ab
4
+ data.tar.gz: 243f2e913bfc0b05850f0d9d6c4d40f173e57d09662618b1c28591a9929557e9
5
+ SHA512:
6
+ metadata.gz: db5db1fe3248c3f3fd5e643e4bd981cbabcc121214077ab4d526779f8664229d2ab888fff788b24ced65932320a1b3549310f305f4b40e950269ff172d62c225
7
+ data.tar.gz: a74e0b7c30517790226d03d928a02c83c5030fc573ece590f6996ebfa8f39093f82b2a41dab3a0f5947a36fd22cfacfd3951c3e17347e9956bb1f17b7282ee70
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Finswitz
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/finswitz`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ ```bash
14
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
+ ```
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ ```bash
20
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/finswitz.
@@ -0,0 +1,3 @@
1
+ module Finswitz
2
+ VERSION = "1.0.0"
3
+ end
data/lib/finswitz.rb ADDED
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "finswitz/version"
4
+
5
+ require "json"
6
+ require "net/http"
7
+ require "uri"
8
+
9
+ module Finswitz
10
+ DEFAULT_BASE_URL = "https://api.finswitz.com"
11
+
12
+ class ApiError < StandardError
13
+ attr_reader :status, :response
14
+
15
+ def initialize(message, status: nil, response: nil)
16
+ super(message)
17
+ @status = status
18
+ @response = response
19
+ end
20
+ end
21
+
22
+ class Client
23
+ def initialize(api_key: nil, dashboard_token: nil, base_url: DEFAULT_BASE_URL)
24
+ @api_key = api_key
25
+ @dashboard_token = dashboard_token
26
+ @base_url = base_url.sub(%r{/+$}, "")
27
+ end
28
+
29
+ def request(method, path, body: nil, query: nil, idempotency_key: nil, token_type: :api, token: nil)
30
+ bearer = token || (token_type == :dashboard ? @dashboard_token : @api_key)
31
+ raise ArgumentError, token_type == :dashboard ? "Missing dashboard_token." : "Missing api_key." if token_type != :none && !bearer
32
+
33
+ uri = URI(@base_url + path)
34
+ uri.query = URI.encode_www_form(query.reject { |_key, value| value.nil? }) if query && !query.empty?
35
+
36
+ klass = Net::HTTP.const_get(method.to_s.capitalize)
37
+ req = klass.new(uri)
38
+ req["Accept"] = "application/json"
39
+ req["Authorization"] = "Bearer #{bearer}" unless token_type == :none
40
+ req["Idempotency-Key"] = idempotency_key if idempotency_key
41
+ if body
42
+ req["Content-Type"] = "application/json"
43
+ req.body = JSON.generate(body)
44
+ end
45
+
46
+ res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https", read_timeout: 30) do |http|
47
+ http.request(req)
48
+ end
49
+
50
+ data = res.body && !res.body.empty? ? JSON.parse(res.body) : nil
51
+ unless res.code.to_i.between?(200, 299)
52
+ message = data.is_a?(Hash) && data["error"] ? data["error"] : "Finswitz API request failed with #{res.code}"
53
+ raise ApiError.new(message, status: res.code.to_i, response: data)
54
+ end
55
+ data
56
+ end
57
+
58
+ def get(path, **options) = request(:get, path, **options)
59
+ def post(path, body = {}, **options) = request(:post, path, body: body, **options)
60
+ def patch(path, body = {}, **options) = request(:patch, path, body: body, **options)
61
+
62
+ def transfer(payload, idempotency_key: nil) = post("/payments/transfer", payload, idempotency_key: idempotency_key)
63
+ def verify_account(payload) = post("/payments/verify-account", payload)
64
+ def create_payment_link(payload, idempotency_key: nil) = post("/payments/payment-links", payload, idempotency_key: idempotency_key)
65
+ def mobile_money(payload, idempotency_key: nil) = post("/payments/mobile-money", payload, idempotency_key: idempotency_key)
66
+ def mock_charge(payload) = post("/payments/mock/charge", payload)
67
+ def get_transaction(reference) = get("/payments/#{URI.encode_www_form_component(reference)}")
68
+ def list_transactions(query: nil) = get("/payments", query: query)
69
+ def refund(reference, payload = {}, idempotency_key: nil) = post("/payments/#{URI.encode_www_form_component(reference)}/refund", payload, idempotency_key: idempotency_key)
70
+ def list_banks(query: nil) = get("/payments/banks", query: query)
71
+
72
+ def card_pricing = get("/cards/pricing")
73
+ def issue_card(payload, idempotency_key: nil) = post("/cards/issue", payload, idempotency_key: idempotency_key)
74
+ def list_cards(query: nil) = get("/cards", query: query)
75
+ def list_card_transactions(card_id, query: nil) = get("/cards/#{URI.encode_www_form_component(card_id)}/transactions", query: query)
76
+ def get_card_transaction(card_id, transaction_id) = get("/cards/#{URI.encode_www_form_component(card_id)}/transactions/#{URI.encode_www_form_component(transaction_id)}")
77
+
78
+ def dashboard_options(options = {}) = options.merge(token_type: :dashboard)
79
+ def me = get("/developers/me", **dashboard_options)
80
+ def list_api_keys = get("/developers/keys", **dashboard_options)
81
+ def create_api_key(payload) = post("/developers/keys", payload, **dashboard_options)
82
+ def revoke_api_key(id) = post("/developers/keys/#{URI.encode_www_form_component(id)}/revoke", {}, **dashboard_options)
83
+ def update_webhooks(payload) = request(:put, "/developers/webhooks", body: payload, **dashboard_options)
84
+ def list_webhook_logs(query: nil) = get("/developers/webhooks/logs", **dashboard_options(query: query))
85
+ def simulate_webhook(payload) = post("/developers/webhooks/simulate", payload, **dashboard_options)
86
+ def wallets = get("/developers/wallets", **dashboard_options)
87
+ def fund_wallet(payload) = post("/developers/wallets/fund", payload, **dashboard_options)
88
+ def wallet_funding_status(query: nil) = get("/developers/wallets/fund/status", **dashboard_options(query: query))
89
+ def convert_wallet(payload) = post("/developers/wallets/convert", payload, **dashboard_options)
90
+ def treasury = get("/developers/treasury", **dashboard_options)
91
+ def list_split_rules = get("/developers/treasury/split-rules", **dashboard_options)
92
+ def create_split_rule(payload, idempotency_key: nil) = post("/developers/treasury/split-rules", payload, **dashboard_options(idempotency_key: idempotency_key))
93
+ def update_split_rule(id, payload) = patch("/developers/treasury/split-rules/#{URI.encode_www_form_component(id)}", payload, **dashboard_options)
94
+ def list_escrow_holds = get("/developers/treasury/escrow", **dashboard_options)
95
+ def create_escrow_hold(payload, idempotency_key: nil) = post("/developers/treasury/escrow", payload, **dashboard_options(idempotency_key: idempotency_key))
96
+ def release_escrow_hold(id, payload = {}, idempotency_key: nil) = post("/developers/treasury/escrow/#{URI.encode_www_form_component(id)}/release", payload, **dashboard_options(idempotency_key: idempotency_key))
97
+ def list_vendor_settlements = get("/developers/treasury/settlements", **dashboard_options)
98
+ def execute_vendor_settlement(id, payload = {}, idempotency_key: nil) = post("/developers/treasury/settlements/#{URI.encode_www_form_component(id)}/execute", payload, **dashboard_options(idempotency_key: idempotency_key))
99
+ def list_collections = get("/developers/collections", **dashboard_options)
100
+ def create_collection(payload) = post("/developers/collections", payload, **dashboard_options)
101
+ def update_collection(id, payload) = patch("/developers/collections/#{URI.encode_www_form_component(id)}", payload, **dashboard_options)
102
+ def list_collection_payments(id) = get("/developers/collections/#{URI.encode_www_form_component(id)}/payments", **dashboard_options)
103
+ def public_collection(slug) = get("/public/collections/#{URI.encode_www_form_component(slug)}", token_type: :none)
104
+ def pay_collection(slug, payload) = post("/public/collections/#{URI.encode_www_form_component(slug)}/pay", payload, token_type: :none)
105
+ def update_settlement(payload) = post("/developers/settlement", payload, **dashboard_options)
106
+ def verify_settlement_account(payload) = post("/developers/verify-account", payload, **dashboard_options)
107
+ def kyc = get("/developers/kyc", **dashboard_options)
108
+ def submit_kyc(payload) = post("/developers/kyc", payload, **dashboard_options)
109
+ def request_compliance_review(payload = {}) = post("/developers/compliance/request-review", payload, **dashboard_options)
110
+
111
+ def self.parse_webhook(raw_body)
112
+ raw_body.is_a?(String) ? JSON.parse(raw_body) : raw_body
113
+ end
114
+ end
115
+ end
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: finswitz
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Taiwo Ayomide TBWLJ
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Ruby SDK for interacting with the Finswitz API.
13
+ email:
14
+ - taiwoayomide202@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - README.md
20
+ - lib/finswitz.rb
21
+ - lib/finswitz/version.rb
22
+ homepage: https://finswitz.com
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubygems_version: 4.0.10
41
+ specification_version: 4
42
+ summary: Official Ruby SDK for the Finswitz API
43
+ test_files: []