Skip to content

Commit 7a9e197

Browse files
authored
✨ add webhook info to model searches (#250)
1 parent a67f40a commit 7a9e197

9 files changed

Lines changed: 89 additions & 3 deletions

File tree

lib/mindee/v2/parsing/search.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
require_relative 'search/search_model'
55
require_relative 'search/search_models'
66
require_relative 'search/search_response'
7+
require_relative 'search/model_webhook'
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# frozen_string_literal: true
2+
3+
module Mindee
4+
module V2
5+
module Parsing
6+
module Search
7+
# Individual webhook information.
8+
class ModelWebhook
9+
# @return [String] ID of the webhook.
10+
attr_reader :id
11+
12+
# @return [String] Name of the webhook.
13+
attr_reader :name
14+
15+
# @return [String] URL of the webhook.
16+
attr_reader :url
17+
18+
# @param payload [Hash] The parsed JSON payload mapping to the search model.
19+
def initialize(payload)
20+
@id = payload['id']
21+
@name = payload['name']
22+
@url = payload['url']
23+
end
24+
25+
# String representation of the model.
26+
# @return [String]
27+
def to_s
28+
[
29+
":Name: #{@name}",
30+
":ID: #{@id}",
31+
":URL: #{@url}",
32+
].join("\n")
33+
end
34+
end
35+
end
36+
end
37+
end
38+
end

lib/mindee/v2/parsing/search/search_model.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require_relative 'model_webhook'
4+
35
module Mindee
46
module V2
57
module Parsing
@@ -15,11 +17,15 @@ class SearchModel
1517
# @return [String] Type of the model.
1618
attr_reader :model_type
1719

20+
# @return [Array<ModelWebhook>] List of webhooks associated with the model.
21+
attr_reader :webhooks
22+
1823
# @param payload [Hash] The parsed JSON payload mapping to the search model.
1924
def initialize(payload)
2025
@id = payload['id']
2126
@name = payload['name']
2227
@model_type = payload['model_type']
28+
@webhooks = (payload['webhooks'] || []).map { |w| ModelWebhook.new(w) }
2329
end
2430

2531
# String representation of the model.
@@ -29,6 +35,7 @@ def to_s
2935
":Name: #{@name}",
3036
":ID: #{@id}",
3137
":Model Type: #{@model_type}",
38+
":Webhooks: #{@webhooks.join("\n")}",
3239
].join("\n")
3340
end
3441
end

lib/mindee/v2/parsing/search/search_models.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def to_s
2020
"* :Name: #{model.name}",
2121
" :ID: #{model.id}",
2222
" :Model Type: #{model.model_type}",
23+
" :Webhooks: #{model.webhooks.size}",
2324
]
2425
end
2526

lib/mindee/v2/parsing/search/search_response.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ def to_s
2424
[
2525
'Models',
2626
'######',
27-
models.to_s,
27+
@models.to_s,
2828
'Pagination Metadata',
2929
'###################',
30-
pagination_metadata.to_s,
30+
@pagination_metadata.to_s,
3131
'',
3232
].join("\n")
3333
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# lib/mindee/v2/parsing/search/model_webhook.rb
2+
3+
module Mindee
4+
module V2
5+
module Parsing
6+
module Search
7+
class ModelWebhook
8+
attr_reader id: String
9+
attr_reader name: String
10+
attr_reader url: String
11+
12+
def initialize: (Hash[String | Symbol, untyped]) -> void
13+
14+
def to_s: -> String
15+
end
16+
end
17+
end
18+
end
19+
end

sig/mindee/v2/parsing/search/search_model.rbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Mindee
88
attr_reader id: String
99
attr_reader model_type: String
1010
attr_reader name: String
11+
attr_reader webhooks: Array[ModelWebhook]
1112

1213
def initialize: (Hash[String|Symbol, untyped]) -> void
1314

spec/data

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
require 'mindee'
4+
require 'mindee/v2/parsing/search'
5+
6+
describe Mindee::V2::Parsing::Search::SearchResponse do
7+
it 'initializes' do
8+
json_file_path = File.join(V2_DATA_DIR, 'search', 'models.json')
9+
10+
response = described_class.new(JSON.parse(File.read(json_file_path)))
11+
12+
expect(response).not_to be_nil
13+
expect(response.models.size).to eq(5)
14+
model0 = response.models[0]
15+
expect(model0.name).to eq('Extraction With Webhooks')
16+
expect(model0.webhooks.size).to eq(2)
17+
expect(model0.webhooks[0].url).to eq('https://failure.mindee.com')
18+
end
19+
end

0 commit comments

Comments
 (0)