getstream-ruby 1.0.0 → 1.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.
- checksums.yaml +4 -4
- data/lib/getstream_ruby/client.rb +81 -0
- data/lib/getstream_ruby/version.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ce0f245a0b8be58cf1e478a72dc3035ba1cce617c4464c61234acf9c46102440
|
|
4
|
+
data.tar.gz: e9d31a1ad40a5940df8c9fd87903b9496596da295d3c729537b41a42106c8662
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ab7a5de6de5fd53ef7519e9847b91bf54abafcdfc8c17a74806004cc8f75ac02522a0eb16e1cf266339dbbd4691e3f5e98a2234b7de548e2da169dbe0d6235e2
|
|
7
|
+
data.tar.gz: a9232d180dcdd741c2c5dc399ea521db72efe6c9d5dff6591aa7d9d03d3528e61c0dafdb2ece14ec8338eb5f4a48b2c9f114b6e6d719905db35868a33e79c1b0
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'faraday'
|
|
4
4
|
require 'faraday/retry'
|
|
5
|
+
require 'faraday/multipart'
|
|
5
6
|
require 'json'
|
|
6
7
|
require 'jwt'
|
|
7
8
|
require_relative 'generated/base_model'
|
|
@@ -86,6 +87,10 @@ module GetStreamRuby
|
|
|
86
87
|
def request(method, path, data = {})
|
|
87
88
|
# Add API key to query parameters
|
|
88
89
|
query_params = { api_key: @configuration.api_key }
|
|
90
|
+
|
|
91
|
+
# Check if this is a file upload request that needs multipart
|
|
92
|
+
return make_multipart_request(method, path, query_params, data) if multipart_request?(data)
|
|
93
|
+
|
|
89
94
|
response = @connection.send(method) do |req|
|
|
90
95
|
|
|
91
96
|
req.url path, query_params
|
|
@@ -105,6 +110,7 @@ module GetStreamRuby
|
|
|
105
110
|
def build_connection
|
|
106
111
|
Faraday.new(url: @configuration.base_url) do |conn|
|
|
107
112
|
|
|
113
|
+
conn.request :multipart
|
|
108
114
|
conn.request :retry, {
|
|
109
115
|
max: 3,
|
|
110
116
|
interval: 0.05,
|
|
@@ -159,6 +165,81 @@ module GetStreamRuby
|
|
|
159
165
|
end
|
|
160
166
|
end
|
|
161
167
|
|
|
168
|
+
def multipart_request?(data)
|
|
169
|
+
return false if data.nil? || data == {}
|
|
170
|
+
|
|
171
|
+
# Check if data is a FileUploadRequest or ImageUploadRequest
|
|
172
|
+
data.is_a?(GetStream::Generated::Models::FileUploadRequest) ||
|
|
173
|
+
data.is_a?(GetStream::Generated::Models::ImageUploadRequest)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def make_multipart_request(method, path, query_params, data)
|
|
177
|
+
# Build multipart form data
|
|
178
|
+
payload = {}
|
|
179
|
+
|
|
180
|
+
# Handle file field
|
|
181
|
+
raise APIError, 'file name must be provided' if data.file.nil? || data.file.empty?
|
|
182
|
+
|
|
183
|
+
file_path = data.file
|
|
184
|
+
raise APIError, "file not found: #{file_path}" unless File.exist?(file_path)
|
|
185
|
+
|
|
186
|
+
# Determine content type
|
|
187
|
+
content_type = detect_content_type(file_path)
|
|
188
|
+
|
|
189
|
+
# Add file as multipart (FilePart handles file opening/closing)
|
|
190
|
+
payload[:file] = Faraday::Multipart::FilePart.new(
|
|
191
|
+
file_path,
|
|
192
|
+
content_type,
|
|
193
|
+
File.basename(file_path),
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
# Add user field if present (as JSON string)
|
|
197
|
+
if data.user
|
|
198
|
+
user_json = data.user.to_json
|
|
199
|
+
payload[:user] = user_json
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
# Add upload_sizes field for ImageUploadRequest (as JSON string)
|
|
203
|
+
if data.is_a?(GetStream::Generated::Models::ImageUploadRequest) && data.upload_sizes
|
|
204
|
+
upload_sizes_json = data.upload_sizes.to_json
|
|
205
|
+
payload[:upload_sizes] = upload_sizes_json
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
response = @connection.send(method) do |req|
|
|
209
|
+
|
|
210
|
+
req.url path, query_params
|
|
211
|
+
req.headers['Authorization'] = generate_auth_header
|
|
212
|
+
req.headers['stream-auth-type'] = 'jwt'
|
|
213
|
+
req.headers['X-Stream-Client'] = user_agent
|
|
214
|
+
req.body = payload
|
|
215
|
+
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
handle_response(response)
|
|
219
|
+
rescue Faraday::Error => e
|
|
220
|
+
raise APIError, "Request failed: #{e.message}"
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def detect_content_type(file_path)
|
|
224
|
+
ext = File.extname(file_path).downcase
|
|
225
|
+
case ext
|
|
226
|
+
when '.png'
|
|
227
|
+
'image/png'
|
|
228
|
+
when '.jpg', '.jpeg'
|
|
229
|
+
'image/jpeg'
|
|
230
|
+
when '.gif'
|
|
231
|
+
'image/gif'
|
|
232
|
+
when '.pdf'
|
|
233
|
+
'application/pdf'
|
|
234
|
+
when '.txt'
|
|
235
|
+
'text/plain'
|
|
236
|
+
when '.json'
|
|
237
|
+
'application/json'
|
|
238
|
+
else
|
|
239
|
+
'application/octet-stream'
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
|
|
162
243
|
end
|
|
163
244
|
|
|
164
245
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: getstream-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- GetStream
|
|
@@ -38,6 +38,20 @@ dependencies:
|
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '2.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: faraday-multipart
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '1.0'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '1.0'
|
|
41
55
|
- !ruby/object:Gem::Dependency
|
|
42
56
|
name: faraday-retry
|
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|