leash-sdk 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/LICENSE +200 -21
- data/README.md +29 -109
- data/leash-sdk.gemspec +1 -1
- data/lib/leash/custom_integration.rb +32 -0
- data/lib/leash/integrations.rb +114 -1
- data/lib/leash.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 326ce87e27b0aec22d2cf9175c3ed7b170b493a7e7eb86b55fc115806b5c84a1
|
|
4
|
+
data.tar.gz: a4cced54f08f447c0dc703524c6ce84fcd07173f685f6a8ee0e76dc3dda1065a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fba497998357aaaa579aec3d3c3539f73c1a2871b8dfc9922dc9ce7e7d238f3587bd12c4a6ccf50e0cf9a149e1926915218aa270f775091d39cb6c2d9025d059
|
|
7
|
+
data.tar.gz: db78fcf8d0e38fc9f575dc03d0612d2e3ce228dbc0869e23d609e18604f1b634929e3215ac66c480f0730c50e2c8c666203b67eb31dd960d461eadb7ccc66a03
|
data/LICENSE
CHANGED
|
@@ -1,21 +1,200 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. Please do not remove or edit
|
|
186
|
+
this header other than to update the information in brackets.
|
|
187
|
+
|
|
188
|
+
Copyright 2026 Leash
|
|
189
|
+
|
|
190
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
191
|
+
you may not use this file except in compliance with the License.
|
|
192
|
+
You may obtain a copy of the License at
|
|
193
|
+
|
|
194
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
195
|
+
|
|
196
|
+
Unless required by applicable law or agreed to in writing, software
|
|
197
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
198
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
199
|
+
See the License for the specific language governing permissions and
|
|
200
|
+
limitations under the License.
|
data/README.md
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# Leash SDK for Ruby
|
|
2
2
|
|
|
3
|
-
Ruby SDK for
|
|
3
|
+
Ruby SDK for Leash-hosted integrations.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Use it to call Gmail, Google Calendar, Google Drive, and custom provider actions through the Leash platform proxy.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Installation
|
|
8
8
|
|
|
9
9
|
```ruby
|
|
10
10
|
gem "leash-sdk"
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
or:
|
|
14
14
|
|
|
15
|
-
```
|
|
15
|
+
```bash
|
|
16
16
|
gem install leash-sdk
|
|
17
17
|
```
|
|
18
18
|
|
|
@@ -21,120 +21,40 @@ gem install leash-sdk
|
|
|
21
21
|
```ruby
|
|
22
22
|
require "leash"
|
|
23
23
|
|
|
24
|
-
client = Leash::Integrations.new(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
messages = client.gmail.list_messages(query: "is:unread", max_results: 10)
|
|
28
|
-
message = client.gmail.get_message("msg_id_123")
|
|
29
|
-
client.gmail.send_message(to: "friend@example.com", subject: "Hello", body: "Hi there!")
|
|
30
|
-
labels = client.gmail.list_labels
|
|
31
|
-
|
|
32
|
-
# Google Calendar
|
|
33
|
-
calendars = client.calendar.list_calendars
|
|
34
|
-
events = client.calendar.list_events(
|
|
35
|
-
time_min: "2026-04-10T00:00:00Z",
|
|
36
|
-
time_max: "2026-04-17T00:00:00Z",
|
|
37
|
-
single_events: true,
|
|
38
|
-
order_by: "startTime"
|
|
39
|
-
)
|
|
40
|
-
client.calendar.create_event(
|
|
41
|
-
summary: "Team standup",
|
|
42
|
-
start: { "dateTime" => "2026-04-11T09:00:00-04:00" },
|
|
43
|
-
end_time: { "dateTime" => "2026-04-11T09:30:00-04:00" }
|
|
24
|
+
client = Leash::Integrations.new(
|
|
25
|
+
auth_token: ENV["LEASH_AUTH_TOKEN"],
|
|
26
|
+
api_key: ENV["LEASH_API_KEY"]
|
|
44
27
|
)
|
|
45
28
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
## Connection Management
|
|
53
|
-
|
|
54
|
-
```ruby
|
|
55
|
-
# Check if a provider is connected
|
|
56
|
-
client.connected?("gmail") # => true/false
|
|
57
|
-
|
|
58
|
-
# Get all connections
|
|
59
|
-
client.connections # => [{ "providerId" => "gmail", "status" => "active", ... }]
|
|
60
|
-
|
|
61
|
-
# Get OAuth connect URL (for UI buttons)
|
|
62
|
-
url = client.connect_url("gmail", return_url: "https://myapp.com/settings")
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## Error Handling
|
|
66
|
-
|
|
67
|
-
```ruby
|
|
68
|
-
begin
|
|
69
|
-
client.gmail.list_messages
|
|
70
|
-
rescue Leash::NotConnectedError => e
|
|
71
|
-
# Redirect user to connect: e.connect_url
|
|
72
|
-
puts "Please connect Gmail: #{e.connect_url}"
|
|
73
|
-
rescue Leash::TokenExpiredError => e
|
|
74
|
-
# Token needs refresh: e.connect_url
|
|
75
|
-
puts "Token expired, reconnect: #{e.connect_url}"
|
|
76
|
-
rescue Leash::Error => e
|
|
77
|
-
# General API error
|
|
78
|
-
puts "Error (#{e.code}): #{e.message}"
|
|
29
|
+
if client.connected?("gmail")
|
|
30
|
+
messages = client.gmail.list_messages(max_results: 5)
|
|
31
|
+
puts messages
|
|
32
|
+
else
|
|
33
|
+
puts client.connect_url("gmail", return_url: "https://myapp.example.com/settings")
|
|
79
34
|
end
|
|
80
35
|
```
|
|
81
36
|
|
|
82
|
-
##
|
|
83
|
-
|
|
84
|
-
```ruby
|
|
85
|
-
# Custom platform URL
|
|
86
|
-
client = Leash::Integrations.new(
|
|
87
|
-
auth_token: "your-token",
|
|
88
|
-
platform_url: "https://your-instance.leash.build"
|
|
89
|
-
)
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
## API Reference
|
|
93
|
-
|
|
94
|
-
### `Leash::Integrations.new(auth_token:, platform_url: "https://leash.build")`
|
|
95
|
-
|
|
96
|
-
Creates a new client instance.
|
|
97
|
-
|
|
98
|
-
### Gmail (`client.gmail`)
|
|
99
|
-
|
|
100
|
-
| Method | Description |
|
|
101
|
-
|--------|-------------|
|
|
102
|
-
| `list_messages(query:, max_results:, label_ids:, page_token:)` | List messages |
|
|
103
|
-
| `get_message(message_id, format:)` | Get a message by ID |
|
|
104
|
-
| `send_message(to:, subject:, body:, cc:, bcc:)` | Send an email |
|
|
105
|
-
| `search_messages(query, max_results:)` | Search messages |
|
|
106
|
-
| `list_labels` | List all labels |
|
|
107
|
-
|
|
108
|
-
### Calendar (`client.calendar`)
|
|
109
|
-
|
|
110
|
-
| Method | Description |
|
|
111
|
-
|--------|-------------|
|
|
112
|
-
| `list_calendars` | List all calendars |
|
|
113
|
-
| `list_events(calendar_id:, time_min:, time_max:, max_results:, single_events:, order_by:)` | List events |
|
|
114
|
-
| `create_event(summary:, start:, end_time:, calendar_id:, description:, location:, attendees:)` | Create an event |
|
|
115
|
-
| `get_event(event_id, calendar_id:)` | Get an event by ID |
|
|
116
|
-
|
|
117
|
-
### Drive (`client.drive`)
|
|
37
|
+
## Default Platform URL
|
|
118
38
|
|
|
119
|
-
|
|
120
|
-
|--------|-------------|
|
|
121
|
-
| `list_files(query:, max_results:, folder_id:)` | List files |
|
|
122
|
-
| `get_file(file_id)` | Get file metadata |
|
|
123
|
-
| `search_files(query, max_results:)` | Search files |
|
|
39
|
+
- `https://leash.build`
|
|
124
40
|
|
|
125
|
-
|
|
41
|
+
## Features
|
|
126
42
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
43
|
+
- Gmail
|
|
44
|
+
- Google Calendar
|
|
45
|
+
- Google Drive
|
|
46
|
+
- connection status lookup
|
|
47
|
+
- connect URL generation
|
|
48
|
+
- generic provider calls
|
|
49
|
+
- custom integration calls
|
|
50
|
+
- app env fetch and caching
|
|
132
51
|
|
|
133
|
-
##
|
|
52
|
+
## Notes
|
|
134
53
|
|
|
135
|
-
-
|
|
136
|
-
-
|
|
54
|
+
- `auth_token` should be a valid Leash platform JWT
|
|
55
|
+
- `api_key` is optional, but useful for app-scoped access
|
|
56
|
+
- OAuth token handling remains a platform concern
|
|
137
57
|
|
|
138
58
|
## License
|
|
139
59
|
|
|
140
|
-
|
|
60
|
+
Apache-2.0
|
data/leash-sdk.gemspec
CHANGED
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
|
11
11
|
spec.summary = "Ruby SDK for the Leash platform integrations API"
|
|
12
12
|
spec.description = "Access Gmail, Google Calendar, Google Drive, and more through the Leash platform proxy. No API keys needed -- uses your Leash auth token."
|
|
13
13
|
spec.homepage = "https://github.com/leash-build/leash-sdk-ruby"
|
|
14
|
-
spec.license = "
|
|
14
|
+
spec.license = "Apache-2.0"
|
|
15
15
|
spec.required_ruby_version = ">= 3.0"
|
|
16
16
|
|
|
17
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Leash
|
|
4
|
+
# Untyped client for a custom integration.
|
|
5
|
+
#
|
|
6
|
+
# Obtained via {Integrations#integration}. Proxies requests through the
|
|
7
|
+
# Leash platform at +/api/integrations/custom/{name}+.
|
|
8
|
+
#
|
|
9
|
+
# @example
|
|
10
|
+
# stripe = client.integration("stripe")
|
|
11
|
+
# charges = stripe.call("/v1/charges", method: "GET")
|
|
12
|
+
class CustomIntegration
|
|
13
|
+
# @param name [String] the custom integration name
|
|
14
|
+
# @param call_fn [Method] internal callable that performs the HTTP request
|
|
15
|
+
def initialize(name, call_fn)
|
|
16
|
+
@name = name
|
|
17
|
+
@call_fn = call_fn
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Invoke the custom integration proxy.
|
|
21
|
+
#
|
|
22
|
+
# @param path [String] the endpoint path to forward (e.g. "/users")
|
|
23
|
+
# @param method [String] HTTP method (default "GET")
|
|
24
|
+
# @param body [Hash, nil] optional JSON body to forward
|
|
25
|
+
# @param headers [Hash, nil] optional extra headers to forward
|
|
26
|
+
# @return [Object] the "data" field from the platform response
|
|
27
|
+
# @raise [Leash::Error] if the platform returns a non-success response
|
|
28
|
+
def call(path, method: "GET", body: nil, headers: nil)
|
|
29
|
+
@call_fn.call(@name, path, method, body, headers)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
data/lib/leash/integrations.rb
CHANGED
|
@@ -5,6 +5,7 @@ require "json"
|
|
|
5
5
|
require "uri"
|
|
6
6
|
|
|
7
7
|
require_relative "errors"
|
|
8
|
+
require_relative "custom_integration"
|
|
8
9
|
require_relative "gmail"
|
|
9
10
|
require_relative "calendar"
|
|
10
11
|
require_relative "drive"
|
|
@@ -22,9 +23,11 @@ module Leash
|
|
|
22
23
|
class Integrations
|
|
23
24
|
# @param auth_token [String] the leash-auth JWT token
|
|
24
25
|
# @param platform_url [String] base URL of the Leash platform API
|
|
25
|
-
|
|
26
|
+
# @param api_key [String, nil] optional API key for server-to-server auth
|
|
27
|
+
def initialize(auth_token:, platform_url: DEFAULT_PLATFORM_URL, api_key: nil)
|
|
26
28
|
@auth_token = auth_token
|
|
27
29
|
@platform_url = platform_url.chomp("/")
|
|
30
|
+
@api_key = api_key || ENV["LEASH_API_KEY"]
|
|
28
31
|
end
|
|
29
32
|
|
|
30
33
|
# Gmail integration client.
|
|
@@ -48,6 +51,18 @@ module Leash
|
|
|
48
51
|
@drive ||= DriveClient.new(method(:call))
|
|
49
52
|
end
|
|
50
53
|
|
|
54
|
+
# Access a custom integration by name. Returns an untyped client.
|
|
55
|
+
#
|
|
56
|
+
# @param name [String] the custom integration name
|
|
57
|
+
# @return [CustomIntegration]
|
|
58
|
+
#
|
|
59
|
+
# @example
|
|
60
|
+
# stripe = client.integration("stripe")
|
|
61
|
+
# charges = stripe.call("/v1/charges", method: "GET")
|
|
62
|
+
def integration(name)
|
|
63
|
+
CustomIntegration.new(name, method(:call_custom))
|
|
64
|
+
end
|
|
65
|
+
|
|
51
66
|
# Generic proxy call for any provider action.
|
|
52
67
|
#
|
|
53
68
|
# @param provider [String] integration provider name (e.g. "gmail")
|
|
@@ -63,6 +78,7 @@ module Leash
|
|
|
63
78
|
request = Net::HTTP::Post.new(uri)
|
|
64
79
|
request["Content-Type"] = "application/json"
|
|
65
80
|
request["Authorization"] = "Bearer #{@auth_token}"
|
|
81
|
+
request["X-API-Key"] = @api_key if @api_key
|
|
66
82
|
request.body = (params || {}).to_json
|
|
67
83
|
|
|
68
84
|
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
|
|
@@ -97,6 +113,7 @@ module Leash
|
|
|
97
113
|
|
|
98
114
|
request = Net::HTTP::Get.new(uri)
|
|
99
115
|
request["Authorization"] = "Bearer #{@auth_token}"
|
|
116
|
+
request["X-API-Key"] = @api_key if @api_key
|
|
100
117
|
|
|
101
118
|
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
|
|
102
119
|
http.request(request)
|
|
@@ -122,8 +139,104 @@ module Leash
|
|
|
122
139
|
url
|
|
123
140
|
end
|
|
124
141
|
|
|
142
|
+
# Call any MCP server tool directly.
|
|
143
|
+
#
|
|
144
|
+
# @param package_name [String] the npm package name of the MCP server
|
|
145
|
+
# @param tool [String] the tool name to invoke
|
|
146
|
+
# @param args [Hash] optional arguments to pass to the tool
|
|
147
|
+
# @return [Object] the "data" field from the platform response
|
|
148
|
+
# @raise [Leash::Error] if the platform returns a non-success response
|
|
149
|
+
def mcp(package_name, tool, args = {})
|
|
150
|
+
uri = URI("#{@platform_url}/api/mcp/run")
|
|
151
|
+
|
|
152
|
+
request = Net::HTTP::Post.new(uri)
|
|
153
|
+
request["Content-Type"] = "application/json"
|
|
154
|
+
request["Authorization"] = "Bearer #{@auth_token}" if @auth_token
|
|
155
|
+
request["X-API-Key"] = @api_key if @api_key
|
|
156
|
+
|
|
157
|
+
payload = { package: package_name, tool: tool }
|
|
158
|
+
payload[:args] = args unless args.nil? || args.empty?
|
|
159
|
+
request.body = payload.to_json
|
|
160
|
+
|
|
161
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
|
|
162
|
+
http.request(request)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
data = JSON.parse(response.body)
|
|
166
|
+
|
|
167
|
+
unless data["success"]
|
|
168
|
+
raise_error(data)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
data["data"]
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
# Fetch env vars from the platform. Cached after first call.
|
|
175
|
+
#
|
|
176
|
+
# @param key [String, nil] optional key to look up
|
|
177
|
+
# @return [Hash, String, nil] all env vars as a Hash, or a single value if key given
|
|
178
|
+
# @raise [Leash::Error] if the platform returns a non-success response
|
|
179
|
+
def get_env(key = nil)
|
|
180
|
+
@env_cache ||= begin
|
|
181
|
+
uri = URI("#{@platform_url}/api/apps/env")
|
|
182
|
+
|
|
183
|
+
request = Net::HTTP::Get.new(uri)
|
|
184
|
+
request["Authorization"] = "Bearer #{@auth_token}" if @auth_token
|
|
185
|
+
request["X-API-Key"] = @api_key if @api_key
|
|
186
|
+
|
|
187
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
|
|
188
|
+
http.request(request)
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
data = JSON.parse(response.body)
|
|
192
|
+
|
|
193
|
+
unless data["success"]
|
|
194
|
+
raise_error(data)
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
data["data"] || {}
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
key ? @env_cache[key] : @env_cache
|
|
201
|
+
end
|
|
202
|
+
|
|
125
203
|
private
|
|
126
204
|
|
|
205
|
+
# Call the custom integration proxy endpoint.
|
|
206
|
+
#
|
|
207
|
+
# @param name [String] the custom integration name
|
|
208
|
+
# @param path [String] the endpoint path to forward
|
|
209
|
+
# @param method [String] HTTP method
|
|
210
|
+
# @param body [Hash, nil] optional JSON body to forward
|
|
211
|
+
# @param headers [Hash, nil] optional extra headers to forward
|
|
212
|
+
# @return [Object] the "data" field from the platform response
|
|
213
|
+
# @raise [Leash::Error] if the platform returns a non-success response
|
|
214
|
+
def call_custom(name, path, method = "GET", body = nil, headers = nil)
|
|
215
|
+
uri = URI("#{@platform_url}/api/integrations/custom/#{name}")
|
|
216
|
+
|
|
217
|
+
payload = { path: path, method: method }
|
|
218
|
+
payload[:body] = body if body
|
|
219
|
+
payload[:headers] = headers if headers
|
|
220
|
+
|
|
221
|
+
request = Net::HTTP::Post.new(uri)
|
|
222
|
+
request["Content-Type"] = "application/json"
|
|
223
|
+
request["Authorization"] = "Bearer #{@auth_token}"
|
|
224
|
+
request["X-API-Key"] = @api_key if @api_key
|
|
225
|
+
request.body = payload.to_json
|
|
226
|
+
|
|
227
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
|
|
228
|
+
http.request(request)
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
data = JSON.parse(response.body)
|
|
232
|
+
|
|
233
|
+
unless data["success"]
|
|
234
|
+
raise_error(data)
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
data["data"]
|
|
238
|
+
end
|
|
239
|
+
|
|
127
240
|
# Map error codes to specific exception classes.
|
|
128
241
|
#
|
|
129
242
|
# @param data [Hash] the parsed error response
|
data/lib/leash.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: leash-sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Leash
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Access Gmail, Google Calendar, Google Drive, and more through the Leash
|
|
14
14
|
platform proxy. No API keys needed -- uses your Leash auth token.
|
|
@@ -24,13 +24,14 @@ files:
|
|
|
24
24
|
- leash-sdk.gemspec
|
|
25
25
|
- lib/leash.rb
|
|
26
26
|
- lib/leash/calendar.rb
|
|
27
|
+
- lib/leash/custom_integration.rb
|
|
27
28
|
- lib/leash/drive.rb
|
|
28
29
|
- lib/leash/errors.rb
|
|
29
30
|
- lib/leash/gmail.rb
|
|
30
31
|
- lib/leash/integrations.rb
|
|
31
32
|
homepage: https://github.com/leash-build/leash-sdk-ruby
|
|
32
33
|
licenses:
|
|
33
|
-
-
|
|
34
|
+
- Apache-2.0
|
|
34
35
|
metadata:
|
|
35
36
|
homepage_uri: https://github.com/leash-build/leash-sdk-ruby
|
|
36
37
|
source_code_uri: https://github.com/leash-build/leash-sdk-ruby
|