Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/mindee/v2/parsing/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
require_relative 'search/search_model'
require_relative 'search/search_models'
require_relative 'search/search_response'
require_relative 'search/model_webhook'
38 changes: 38 additions & 0 deletions lib/mindee/v2/parsing/search/model_webhook.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

module Mindee
module V2
module Parsing
module Search
# Individual webhook information.
class ModelWebhook
# @return [String] ID of the webhook.
attr_reader :id

# @return [String] Name of the webhook.
attr_reader :name

# @return [String] URL of the webhook.
attr_reader :url

# @param payload [Hash] The parsed JSON payload mapping to the search model.
def initialize(payload)
@id = payload['id']
@name = payload['name']
@url = payload['url']
end

# String representation of the model.
# @return [String]
def to_s
[
":Name: #{@name}",
":ID: #{@id}",
":URL: #{@url}",
].join("\n")
end
end
end
end
end
end
7 changes: 7 additions & 0 deletions lib/mindee/v2/parsing/search/search_model.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require_relative 'model_webhook'

module Mindee
module V2
module Parsing
Expand All @@ -15,11 +17,15 @@ class SearchModel
# @return [String] Type of the model.
attr_reader :model_type

# @return [Array<ModelWebhook>] List of webhooks associated with the model.
attr_reader :webhooks

# @param payload [Hash] The parsed JSON payload mapping to the search model.
def initialize(payload)
@id = payload['id']
@name = payload['name']
@model_type = payload['model_type']
@webhooks = (payload['webhooks'] || []).map { |w| ModelWebhook.new(w) }
end

# String representation of the model.
Expand All @@ -29,6 +35,7 @@ def to_s
":Name: #{@name}",
":ID: #{@id}",
":Model Type: #{@model_type}",
":Webhooks: #{@webhooks.join("\n")}",
].join("\n")
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/mindee/v2/parsing/search/search_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def to_s
"* :Name: #{model.name}",
" :ID: #{model.id}",
" :Model Type: #{model.model_type}",
" :Webhooks: #{model.webhooks.size}",
]
end

Expand Down
4 changes: 2 additions & 2 deletions lib/mindee/v2/parsing/search/search_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def to_s
[
'Models',
'######',
models.to_s,
@models.to_s,
'Pagination Metadata',
'###################',
pagination_metadata.to_s,
@pagination_metadata.to_s,
'',
].join("\n")
end
Expand Down
19 changes: 19 additions & 0 deletions sig/mindee/v2/parsing/search/model_webhook.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# lib/mindee/v2/parsing/search/model_webhook.rb

module Mindee
module V2
module Parsing
module Search
class ModelWebhook
attr_reader id: String
attr_reader name: String
attr_reader url: String

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

def to_s: -> String
end
end
end
end
end
1 change: 1 addition & 0 deletions sig/mindee/v2/parsing/search/search_model.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Mindee
attr_reader id: String
attr_reader model_type: String
attr_reader name: String
attr_reader webhooks: Array[ModelWebhook]

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

Expand Down
2 changes: 1 addition & 1 deletion spec/data
Submodule data updated 1 files
+57 −0 v2/search/models.json
19 changes: 19 additions & 0 deletions spec/v2/parsing/search_models_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require 'mindee'
require 'mindee/v2/parsing/search'

describe Mindee::V2::Parsing::Search::SearchResponse do
it 'initializes' do
json_file_path = File.join(V2_DATA_DIR, 'search', 'models.json')

response = described_class.new(JSON.parse(File.read(json_file_path)))

expect(response).not_to be_nil
expect(response.models.size).to eq(5)
model0 = response.models[0]
expect(model0.name).to eq('Extraction With Webhooks')
expect(model0.webhooks.size).to eq(2)
expect(model0.webhooks[0].url).to eq('https://failure.mindee.com')
end
end