mamatech_external_sdk 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.
- checksums.yaml +7 -0
- data/lib/mamatech_external_sdk/client.rb +101 -0
- data/lib/mamatech_external_sdk/error.rb +13 -0
- data/lib/mamatech_external_sdk.rb +2 -0
- metadata +44 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: c7d3d1744027cd9f7cfaf6778d027ceaa89a5aef3476417b98d0935f3b52b666
|
|
4
|
+
data.tar.gz: 90e2ec1a39df046d8e10b3c2b8a235a61750a75acd41759ec192db0ed21484b2
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 67640a4c505246e863f3edcd60693f9b771d1707df044e7da837c962f7488376fc5bf67c326ff41a97eb3290bad320589c6c739ebf787cfe7c6101f3e5c5a141
|
|
7
|
+
data.tar.gz: 1393772e7d01340541830233dc3bd39a8217e0b6c3486c8db7a57ff8945906435d97914441cf86e649221d5e3930c8ed2d802cbb30837223c725e865a835ff3a
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
require "net/http"
|
|
3
|
+
require "uri"
|
|
4
|
+
|
|
5
|
+
module Mamatech
|
|
6
|
+
module ExternalSdk
|
|
7
|
+
class Client
|
|
8
|
+
DEFAULT_BASE_URL = "https://api.fin.io".freeze
|
|
9
|
+
|
|
10
|
+
def initialize(base_url: nil, app_code: nil, secret_key: nil)
|
|
11
|
+
@base_url = base_url || ENV.fetch("FIN_BASE_URL", DEFAULT_BASE_URL)
|
|
12
|
+
@app_code = app_code || ENV.fetch("FIN_APP_CODE", "")
|
|
13
|
+
@secret_key = secret_key || ENV.fetch("FIN_SECRET_KEY", "")
|
|
14
|
+
raise ArgumentError, "FIN_APP_CODE and FIN_SECRET_KEY are required" if @app_code.empty? || @secret_key.empty?
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def create_external_user(first_name:, last_name:, third_party_id:, language: nil)
|
|
18
|
+
payload = {
|
|
19
|
+
firstName: first_name,
|
|
20
|
+
lastName: last_name,
|
|
21
|
+
thirdPartyId: third_party_id,
|
|
22
|
+
code: @app_code,
|
|
23
|
+
secretKey: @secret_key
|
|
24
|
+
}
|
|
25
|
+
payload[:language] = language unless language.nil?
|
|
26
|
+
request_json("/auth/v1/external/user", "POST", payload)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def login_external_user(third_party_id:)
|
|
30
|
+
request_json("/auth/v1/external/login", "POST", {
|
|
31
|
+
thirdPartyId: third_party_id,
|
|
32
|
+
code: @app_code,
|
|
33
|
+
secretKey: @secret_key
|
|
34
|
+
})
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def renew_token(token:)
|
|
38
|
+
request_json("/api/v1/external/renew", "POST", nil, token: token)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def get_context(token:)
|
|
42
|
+
request_json("/api/v1/external/context", "GET", nil, token: token)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def list_people(token:)
|
|
46
|
+
request_json("/api/v1/person/all", "GET", nil, token: token)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def get_messages(token:, limit: 20, offset: 0)
|
|
50
|
+
request_json("/api/v1/conversations/external/messages?limit=#{limit}&offset=#{offset}", "GET", nil, token: token)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def send_message(token:, text:, security_header: nil)
|
|
54
|
+
request_stream("/api/v1/conversations/external/message", { text: text }, token: token, security_header: security_header)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def submit_secure_input(token:, field:, value:, security_header: nil)
|
|
58
|
+
request_stream("/api/v1/conversations/external/secure-input", { field: field, value: value }, token: token, security_header: security_header)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
|
|
63
|
+
def request_json(path, method, payload, token: nil, security_header: nil)
|
|
64
|
+
body = send_request(path, method, payload, token: token, security_header: security_header)
|
|
65
|
+
body.nil? || body.empty? ? {} : JSON.parse(body)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def request_stream(path, payload, token:, security_header: nil)
|
|
69
|
+
body = send_request(path, "POST", payload, token: token, security_header: security_header)
|
|
70
|
+
body.lines.map(&:strip).reject(&:empty?)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def send_request(path, method, payload, token: nil, security_header: nil)
|
|
74
|
+
uri = URI.join(@base_url, path)
|
|
75
|
+
request = build_request(uri, method, payload)
|
|
76
|
+
request["Authorization"] = "Bearer #{token}" unless token.nil? || token.empty?
|
|
77
|
+
request["life-graph"] = security_header unless security_header.nil? || security_header.empty?
|
|
78
|
+
request["Content-Type"] = "application/json"
|
|
79
|
+
|
|
80
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
|
|
81
|
+
http.request(request)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
return response.body if response.code.to_i.between?(200, 299)
|
|
85
|
+
|
|
86
|
+
raise Error.new("FIN request failed for #{path}", response.code.to_i, response.body.to_s)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def build_request(uri, method, payload)
|
|
90
|
+
request_class = case method
|
|
91
|
+
when "GET" then Net::HTTP::Get
|
|
92
|
+
when "POST" then Net::HTTP::Post
|
|
93
|
+
else raise ArgumentError, "unsupported method #{method}"
|
|
94
|
+
end
|
|
95
|
+
request = request_class.new(uri)
|
|
96
|
+
request.body = JSON.generate(payload) unless payload.nil?
|
|
97
|
+
request
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: mamatech_external_sdk
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- FIN Connect
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-04-01 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description:
|
|
14
|
+
email:
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/mamatech_external_sdk.rb
|
|
20
|
+
- lib/mamatech_external_sdk/client.rb
|
|
21
|
+
- lib/mamatech_external_sdk/error.rb
|
|
22
|
+
homepage:
|
|
23
|
+
licenses: []
|
|
24
|
+
metadata: {}
|
|
25
|
+
post_install_message:
|
|
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.1.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: 3.4.19
|
|
41
|
+
signing_key:
|
|
42
|
+
specification_version: 4
|
|
43
|
+
summary: Server-side SDK for FIN external APIs
|
|
44
|
+
test_files: []
|