lara-sdk 1.2.2 → 1.4.3

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: 3a959c719f2393f4626f029c7116d426f1402889baeaea48a16800fbb58cd229
4
- data.tar.gz: 54b9f604df73458c8abebb16ecce4389dcf4486f255d53187e3ad8dd7d2145c4
3
+ metadata.gz: 99781bcccbdde09ccc8c153f32683bf08e57be3aee65d82a0037f2d3e7daaf3a
4
+ data.tar.gz: 21041bbad4d3d3b2d269d40daded257d3b1879fdf9eea347314cec81b8618dd0
5
5
  SHA512:
6
- metadata.gz: 0d29539cdb0b1fe5add2b2f3200b812666d1edd1c0ebac1d77604f9c696f1f791cac76a791a0fedf7d75d6c263086090b57116705c477f1d9455ae27bb2e4c67
7
- data.tar.gz: 29de437c146d524cca9b29a198ebbdb3426e8bf258a073d72e9740efedcd84edb83d01156870f3a461b1d62fcb144cb52b27c178bb51a8d7b7b521593d60ecff
6
+ metadata.gz: '01785a1e0afe2ce5de1e6f49a617ccd7d43749109e818957c984bca81598e170da652830fbf8662366a6217cf328ded0eafd76cd266d26ab90e31492add28dbf'
7
+ data.tar.gz: 65de8ac4120d2ef3af4e5e584da1bc337b70d6abd8848dc41c3dd21dafe9e511b0519a2a4bc60c7a91b744eb39a0739340c8c18bbe9f20b59b033618d806c616
data/lib/lara/client.rb CHANGED
@@ -228,12 +228,7 @@ module Lara
228
228
  def parse_json(body)
229
229
  return {} if body.nil? || body.empty?
230
230
 
231
- parsed = JSON.parse(body)
232
- if parsed.is_a?(Hash) && parsed.key?("content")
233
- inner = parsed["content"]
234
- return inner if inner.is_a?(Hash) || inner.is_a?(Array)
235
- end
236
- parsed
231
+ JSON.parse(body)
237
232
  end
238
233
 
239
234
  def parse_stream_response(body, &block)
@@ -252,8 +247,7 @@ module Lara
252
247
  next if trimmed_line.empty?
253
248
 
254
249
  begin
255
- parsed = JSON.parse(trimmed_line)
256
- result = parsed["content"] || parsed
250
+ result = JSON.parse(trimmed_line)
257
251
  block.call(result) if block
258
252
  last_result = result
259
253
  rescue JSON::ParserError
@@ -263,8 +257,7 @@ module Lara
263
257
 
264
258
  if !buffer.empty? && buffer.strip != ""
265
259
  begin
266
- parsed = JSON.parse(buffer.strip)
267
- result = parsed["content"] || parsed
260
+ result = JSON.parse(buffer.strip)
268
261
  block.call(result) if block
269
262
  last_result = result
270
263
  rescue JSON::ParserError
data/lib/lara/errors.rb CHANGED
@@ -17,19 +17,14 @@ module Lara
17
17
  class LaraApiError < LaraError
18
18
  attr_reader :type
19
19
 
20
- # Builds an error from an HTTP response with JSON body.
21
- # Supports both { "error": { "type": "...", "message": "..." } }
22
- # and { "type": "...", "message": "..." } response formats.
20
+ # Builds an error from an HTTP response with JSON body { "type": "...", "message": "..." }.
23
21
  def self.from_response(response)
24
22
  data = begin
25
23
  JSON.parse(response.body)
26
24
  rescue StandardError
27
25
  {}
28
26
  end
29
- error = data["error"] || data
30
- error_type = error["type"] || "UnknownError"
31
- error_message = error["message"] || "An unknown error occurred"
32
- new(response.status, error_type, error_message)
27
+ new(response.status, data["type"] || "UnknownError", data["message"] || "An unknown error occurred")
33
28
  end
34
29
 
35
30
  # @param status_code [Integer]
data/lib/lara/memories.rb CHANGED
@@ -2,6 +2,23 @@
2
2
 
3
3
  module Lara
4
4
  class Memories
5
+ # Supported memory export formats
6
+ module ExportFormat
7
+ TMX = "tmx"
8
+ JTM = "jtm"
9
+
10
+ # @return [Array<String>] All supported formats
11
+ def self.all
12
+ [TMX, JTM]
13
+ end
14
+
15
+ # @param format [String] The format to validate
16
+ # @return [Boolean] True if the format is supported
17
+ def self.valid?(format)
18
+ all.include?(format)
19
+ end
20
+ end
21
+
5
22
  def initialize(client)
6
23
  @client = client
7
24
  @polling_interval = 2
@@ -99,7 +116,7 @@ module Lara
99
116
  end
100
117
 
101
118
  # @return [Lara::Models::MemoryImport]
102
- def import_tmx(id, tmx_path)
119
+ def import_tmx(id, tmx_path, callback_url: nil)
103
120
  require "stringio"
104
121
  require "zlib"
105
122
  basename = File.basename(tmx_path)
@@ -111,8 +128,22 @@ module Lara
111
128
  buffer.rewind
112
129
 
113
130
  files = { "tmx" => Faraday::UploadIO.new(buffer, "application/gzip", "#{basename}.gz") }
131
+ body = { "compression" => "gzip" }
132
+ body["callback_url"] = callback_url if callback_url
114
133
  Lara::Models::MemoryImport.new(**@client.post("/v2/memories/#{id}/import",
115
- body: { "compression" => "gzip" }, files: files).transform_keys(&:to_sym))
134
+ body: body, files: files).transform_keys(&:to_sym))
135
+ end
136
+
137
+ # @param format [String,nil] One of Lara::Memories::ExportFormat constants
138
+ # @return [Lara::Models::MemoryExport]
139
+ def export_async(id, format: nil, callback_url:)
140
+ if format && !ExportFormat.valid?(format)
141
+ raise ArgumentError, "Invalid format '#{format}'. Must be one of: #{ExportFormat.all.join(', ')}"
142
+ end
143
+
144
+ params = { callback_url: callback_url }
145
+ params[:format] = format if format
146
+ Lara::Models::MemoryExport.new(**@client.get("/v2/memories/#{id}/export/async", params: params).transform_keys(&:to_sym))
116
147
  end
117
148
 
118
149
  # @return [Lara::Models::MemoryImport]
@@ -16,7 +16,7 @@ module Lara
16
16
  @created_at = Base.parse_time(created_at)
17
17
  @updated_at = Base.parse_time(updated_at)
18
18
  @shared_at = Base.parse_time(shared_at)
19
- @is_personal = is_personal.nil? ? _kwargs[:isPersonal] : is_personal
19
+ @is_personal = is_personal
20
20
  end
21
21
  end
22
22
 
@@ -21,7 +21,7 @@ module Lara
21
21
  @secret = secret
22
22
  @collaborators_count = collaborators_count
23
23
  @shared_at = Base.parse_time(shared_at)
24
- @is_personal = is_personal.nil? ? _kwargs[:isPersonal] : is_personal
24
+ @is_personal = is_personal
25
25
  end
26
26
  end
27
27
 
@@ -38,5 +38,14 @@ module Lara
38
38
  @progress = progress
39
39
  end
40
40
  end
41
+
42
+ class MemoryExport < Base
43
+ attr_reader :job_id
44
+
45
+ def initialize(job_id:, **_kwargs)
46
+ super()
47
+ @job_id = job_id
48
+ end
49
+ end
41
50
  end
42
51
  end
@@ -115,9 +115,10 @@ module Lara
115
115
  end
116
116
 
117
117
  class Styleguide < Base
118
- attr_reader :id, :name, :content, :owner_id, :created_at, :updated_at
118
+ attr_reader :id, :name, :content, :owner_id, :created_at, :updated_at, :is_personal
119
119
 
120
- def initialize(id:, name:, content: nil, owner_id: nil, created_at: nil, updated_at: nil, **_kwargs)
120
+ def initialize(id:, name:, content: nil, owner_id: nil, created_at: nil, updated_at: nil,
121
+ is_personal: nil, **_kwargs)
121
122
  super()
122
123
  @id = id
123
124
  @name = name
@@ -125,6 +126,7 @@ module Lara
125
126
  @owner_id = owner_id
126
127
  @created_at = Base.parse_time(created_at)
127
128
  @updated_at = Base.parse_time(updated_at)
129
+ @is_personal = is_personal
128
130
  end
129
131
 
130
132
  def to_s
@@ -108,7 +108,7 @@ module Lara
108
108
  ->(partial) { callback.call(Lara::Models::TextResult.from_hash(partial)) }
109
109
  end
110
110
 
111
- result = @client.post("/translate", body: body, headers: request_headers, &stream_callback)
111
+ result = @client.post("/v2/translate", body: body, headers: request_headers, &stream_callback)
112
112
  Lara::Models::TextResult.from_hash(result) if result
113
113
  end
114
114
 
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.2.2"
4
+ VERSION = "1.4.3"
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.2.2
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Translated
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-04-28 00:00:00.000000000 Z
11
+ date: 2026-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday