lara-sdk 1.5.0 → 1.5.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 260e413029ef25a896fb6eb641e9ca827fca770534b9510abf7ce95f6f7f9692
4
- data.tar.gz: 27c8ffbed846d88f167a67ba5ba2c178528fcf47246f3288c25bd2e0e2cb773d
3
+ metadata.gz: 16d7ebfcc581f7cf377274d58579d0d306eb98c83907c28de3de277fefe0c40f
4
+ data.tar.gz: 5ae057fa1538580898d922d41f387fcd6d583726eb98fde453811f0fc0d6a3de
5
5
  SHA512:
6
- metadata.gz: '0874bcc119ba9fb65b3deb2604fc5581b48022b3a4849a5faeeb61c48357baedb77d41d1523b31d5bbdf28e700f21fb2dd63c3e903aae9ed5dd9f47215c52974'
7
- data.tar.gz: 88a93cf1701ba776261cec4dca86ff8468e46aec29e5328babb6912103b392c25c66935bea20c53e3a5ae804e398a5581125d50c5a70b460301fd4f3847d2ae7
6
+ metadata.gz: 61f703c0ac1fa6059d3f58181ba65d1252a687085e7106b808377da35c13aa7b8f1380d612e451e0e1d2d1dbf734e21cce9cae409fc522d8dca113890a19161b
7
+ data.tar.gz: be6e69b110dbeefe2093f47aa8e741dd6d4c8fe014b4b3c0b3e66cc4929d313a8832cf5f93c4d7c0af50e18ba11d6d592f8f0bb5a059d7d71437de5fbd64d7be
@@ -10,7 +10,7 @@ module Lara
10
10
 
11
11
  def initialize(token, refresh_token)
12
12
  @token = token
13
- @refresh_token = refresh_token
13
+ @refresh_token = refresh_token.nil? || refresh_token.empty? ? nil : refresh_token
14
14
  @expires_at_ms = parse_expires_at_ms(token)
15
15
  end
16
16
 
data/lib/lara/client.rb CHANGED
@@ -64,7 +64,8 @@ module Lara
64
64
  # @yield [Hash] Each partial JSON result from the stream (if streaming)
65
65
  # @return [Hash, Array, String, nil] The JSON 'content' from the API, CSV body, or raw bytes.
66
66
  def post(path, body: nil, files: nil, headers: nil, raw_response: false, &callback)
67
- request(:post, path, body: body, files: files, headers: headers, raw_response: raw_response, &callback)
67
+ request(:post, path, body: body, files: files, headers: headers, raw_response: raw_response,
68
+ &callback)
68
69
  end
69
70
 
70
71
  # Sends a PUT request to the Lara API.
@@ -88,17 +89,18 @@ module Lara
88
89
 
89
90
  private
90
91
 
91
- def request(method, path, body: nil, files: nil, headers: nil, params: nil, raw_response: false, &callback)
92
+ def request(method, path, body: nil, files: nil, headers: nil, params: nil,
93
+ raw_response: false, &callback)
92
94
  ensure_valid_token
93
95
 
94
96
  make_request(method, path, body: body, files: files, headers: headers, params: params,
95
- raw_response: raw_response, &callback)
97
+ raw_response: raw_response, &callback)
96
98
  rescue LaraApiError => e
97
99
  raise unless e.status_code == 401
98
100
 
99
101
  @auth_mutex.synchronize { refresh_or_reauthenticate }
100
102
  make_request(method, path, body: body, files: files, headers: headers, params: params,
101
- raw_response: raw_response, &callback)
103
+ raw_response: raw_response, &callback)
102
104
  end
103
105
 
104
106
  def ensure_valid_token
@@ -110,7 +112,7 @@ module Lara
110
112
  end
111
113
 
112
114
  def refresh_or_reauthenticate
113
- if @auth_token&.refresh_token && !@auth_token.refresh_token.empty?
115
+ if @auth_token&.refresh_token
114
116
  begin
115
117
  do_refresh
116
118
  return
@@ -160,8 +162,6 @@ module Lara
160
162
  data = JSON.parse(response.body)
161
163
  refresh_token_value = response.headers["x-lara-refresh-token"]
162
164
 
163
- raise LaraError, "Missing refresh token in authentication response" unless refresh_token_value
164
-
165
165
  AuthToken.new(data["token"], refresh_token_value)
166
166
  end
167
167
 
@@ -186,12 +186,11 @@ module Lara
186
186
  data = JSON.parse(response.body)
187
187
  refresh_token_value = response.headers["x-lara-refresh-token"]
188
188
 
189
- raise LaraError, "Missing refresh token in refresh response" unless refresh_token_value
190
-
191
189
  @auth_token = AuthToken.new(data["token"], refresh_token_value)
192
190
  end
193
191
 
194
- def make_request(method, path, body: nil, files: nil, headers: nil, params: nil, raw_response: false, &callback)
192
+ def make_request(method, path, body: nil, files: nil, headers: nil, params: nil,
193
+ raw_response: false, &callback)
195
194
  path = "/#{path}" unless path.start_with?("/")
196
195
  request_headers = build_request_headers(body, files, headers)
197
196
 
@@ -248,7 +247,7 @@ module Lara
248
247
 
249
248
  begin
250
249
  result = JSON.parse(trimmed_line)
251
- block.call(result) if block
250
+ block&.call(result)
252
251
  last_result = result
253
252
  rescue JSON::ParserError
254
253
  next
@@ -258,7 +257,7 @@ module Lara
258
257
  if !buffer.empty? && buffer.strip != ""
259
258
  begin
260
259
  result = JSON.parse(buffer.strip)
261
- block.call(result) if block
260
+ block&.call(result)
262
261
  last_result = result
263
262
  rescue JSON::ParserError
264
263
  end
@@ -18,6 +18,7 @@ module Lara
18
18
  all.include?(format)
19
19
  end
20
20
  end
21
+
21
22
  def initialize(client)
22
23
  @client = client
23
24
  @polling_interval = 2
@@ -62,26 +63,35 @@ module Lara
62
63
  end
63
64
 
64
65
  # @param content_type [String] Either FileFormat::UNIDIRECTIONAL or FileFormat::MULTIDIRECTIONAL
66
+ # @param gzip [Boolean] When true, compress the CSV before upload and set compression=gzip
67
+ # @param callback_url [String,nil] Optional URL notified when the import completes
65
68
  # @return [Lara::Models::GlossaryImport]
66
- def import_csv(id, csv_path, content_type: FileFormat::UNIDIRECTIONAL, gzip: true)
69
+ def import_csv(id, csv_path, content_type: FileFormat::UNIDIRECTIONAL, gzip: false,
70
+ callback_url: nil)
67
71
  unless FileFormat.valid?(content_type)
68
72
  raise ArgumentError, "Invalid content_type. Supported formats: #{FileFormat.all.join(', ')}"
69
73
  end
70
74
 
71
- require "stringio"
72
- require "zlib"
73
75
  basename = File.basename(csv_path)
76
+ if gzip
77
+ require "stringio"
78
+ require "zlib"
79
+
80
+ buffer = StringIO.new
81
+ gz = Zlib::GzipWriter.new(buffer, 7, Zlib::DEFAULT_STRATEGY)
82
+ File.open(csv_path, "rb") { |_f| IO.copy_stream(_f, gz) }
83
+ gz.finish
84
+ buffer.rewind
85
+
86
+ body = { "compression" => "gzip" }
87
+ files = { "csv" => Faraday::UploadIO.new(buffer, "application/gzip", "#{basename}.gz") }
88
+ else
89
+ body = {}
90
+ files = { "csv" => Faraday::UploadIO.new(csv_path, "text/csv", basename) }
91
+ end
74
92
 
75
- buffer = StringIO.new
76
- gz = Zlib::GzipWriter.new(buffer, 7, Zlib::DEFAULT_STRATEGY)
77
- File.open(csv_path, "rb") { |_f| IO.copy_stream(_f, gz) }
78
- gz.finish
79
- buffer.rewind
80
-
81
- body = { "compression" => "gzip" }
82
93
  body["content_type"] = content_type unless content_type == FileFormat::UNIDIRECTIONAL
83
-
84
- files = { "csv" => Faraday::UploadIO.new(buffer, "application/gzip", "#{basename}.gz") }
94
+ body["callback_url"] = callback_url if callback_url
85
95
  Lara::Models::GlossaryImport.new(**@client.post("/v2/glossaries/#{id}/import",
86
96
  body: body, files: files).transform_keys(&:to_sym))
87
97
  end
@@ -120,6 +130,21 @@ module Lara
120
130
  params: { content_type: content_type, source: source }.compact)
121
131
  end
122
132
 
133
+ # @param callback_url [String] URL notified when the export is ready
134
+ # @param content_type [String] Either FileFormat::UNIDIRECTIONAL or FileFormat::MULTIDIRECTIONAL
135
+ # @param source [String, nil] Optional source language (unidirectional exports only)
136
+ # @return [Lara::Models::GlossaryExport]
137
+ def export_async(id, callback_url:, content_type: FileFormat::UNIDIRECTIONAL, source: nil)
138
+ unless FileFormat.valid?(content_type)
139
+ raise ArgumentError, "Invalid content_type. Supported formats: #{FileFormat.all.join(', ')}"
140
+ end
141
+
142
+ params = { callback_url: callback_url, content_type: content_type }
143
+ params[:source] = source if source
144
+ Lara::Models::GlossaryExport.new(**@client.get("/v2/glossaries/#{id}/export/async",
145
+ params: params).transform_keys(&:to_sym))
146
+ end
147
+
123
148
  # @param glossary_id [String] The glossary ID
124
149
  # @param terms [Array<Hash>] Array of term hashes with :language and :value keys
125
150
  # @param guid [String, nil] Optional unique identifier for multidirectional glossary units
@@ -128,7 +153,8 @@ module Lara
128
153
  body = { terms: terms }
129
154
  body[:guid] = guid if guid
130
155
 
131
- Lara::Models::GlossaryImport.new(**@client.put("/v2/glossaries/#{glossary_id}/content", body: body).transform_keys(&:to_sym))
156
+ Lara::Models::GlossaryImport.new(**@client.put("/v2/glossaries/#{glossary_id}/content",
157
+ body: body).transform_keys(&:to_sym))
132
158
  end
133
159
 
134
160
  # @param glossary_id [String] The glossary ID
@@ -140,7 +166,8 @@ module Lara
140
166
  body[:guid] = guid if guid
141
167
  body[:term] = term if term
142
168
 
143
- Lara::Models::GlossaryImport.new(**@client.delete("/v2/glossaries/#{glossary_id}/content", body: body).transform_keys(&:to_sym))
169
+ Lara::Models::GlossaryImport.new(**@client.delete("/v2/glossaries/#{glossary_id}/content",
170
+ body: body).transform_keys(&:to_sym))
144
171
  end
145
172
  end
146
173
  end
@@ -43,5 +43,14 @@ module Lara
43
43
  @multidirectional = multidirectional
44
44
  end
45
45
  end
46
+
47
+ class GlossaryExport < Base
48
+ attr_reader :job_id
49
+
50
+ def initialize(job_id:, **_kwargs)
51
+ super()
52
+ @job_id = job_id
53
+ end
54
+ end
46
55
  end
47
56
  end
data/lib/lara/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lara
4
- VERSION = "1.5.0"
4
+ VERSION = "1.5.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lara-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Translated
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-06-01 00:00:00.000000000 Z
11
+ date: 2026-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday