Skip to content

Commit

Permalink
Merge pull request #276 from getyoti/SDK-2333-go-support-expanded-doc…
Browse files Browse the repository at this point in the history
…ument-fields-media

Sdk 2333 go support expanded document fields media
  • Loading branch information
mehmet-yoti authored Jun 20, 2023
2 parents 3e39bb7 + f731699 commit 39bd09e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 14 deletions.
Binary file added _examples/idv/idv.exe
Binary file not shown.
38 changes: 31 additions & 7 deletions _examples/idv/models.sessionspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func buildSessionSpec() (sessionSpec *create.SessionSpecification, err error) {
var textExtractionTask *task.RequestedTextExtractionTask
textExtractionTask, err = task.NewRequestedTextExtractionTaskBuilder().
WithManualCheckAlways().
WithExpandedDocumentFields(true).
Build()
if err != nil {
return nil, err
Expand Down Expand Up @@ -102,23 +103,43 @@ func buildSessionSpec() (sessionSpec *create.SessionSpecification, err error) {
return nil, err
}

passportFilter, err := filter.NewRequestedOrthogonalRestrictionsFilterBuilder().
//This section is used for Orthogonal Restriction
/*passportFilter, err := filter.NewRequestedOrthogonalRestrictionsFilterBuilder().
WithIncludedDocumentTypes(
[]string{"PASSPORT"}).
WithNonLatinDocuments(true).
WithExpiredDocuments(false).
Build()
if err != nil {
return nil, err
}*/

docRestriction, err := filter.NewRequestedDocumentRestrictionBuilder().
WithDocumentTypes([]string{"PASSPORT"}).
WithCountryCodes([]string{"GBR"}).
Build()
if err != nil {
return nil, err
}
passportDoc, err := filter.NewRequiredIDDocumentBuilder().

/*passportDoc, err := filter.NewRequiredIDDocumentBuilder().
WithFilter(passportFilter).
Build()
if err != nil {
return nil, err
}*/

docFilter, err := filter.NewRequestedDocumentRestrictionsFilterBuilder().
ForIncludeList().
WithDocumentRestriction(docRestriction).
WithAllowNonLatinDocuments(true).
WithExpiredDocuments(false).
Build()
if err != nil {
return nil, err
}

idDoc, err := filter.NewRequiredIDDocumentBuilder().Build()
idDoc, err := filter.NewRequiredIDDocumentBuilder().WithFilter(docFilter).Build()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -149,14 +170,20 @@ func buildSessionSpec() (sessionSpec *create.SessionSpecification, err error) {
WithRequestedTask(textExtractionTask).
WithRequestedTask(supplementaryDocTextExtractionTask).
WithSDKConfig(sdkConfig).
WithRequiredDocument(passportDoc).
//Below line will be enabled when orthogonal Restriction is Needed
//WithRequiredDocument(passportDoc).
WithRequiredDocument(idDoc).
WithRequiredDocument(supplementaryDoc).
Build()

if err != nil {
return nil, err
}

if err != nil {
return nil, err
}

return sessionSpec, nil
}

Expand Down Expand Up @@ -207,8 +234,5 @@ func buildDBSSessionSpec() (sessionSpec *create.SessionSpecification, err error)
WithImportToken(importToken).
Build()

if err != nil {
return nil, err
}
return sessionSpec, nil
}
17 changes: 13 additions & 4 deletions docscan/session/create/task/text_extraction.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ func NewRequestedTextExtractionTask(config RequestedTextExtractionTaskConfig) *R

// RequestedTextExtractionTaskConfig is the configuration applied when creating a Text Extraction Task
type RequestedTextExtractionTaskConfig struct {
ManualCheck string `json:"manual_check,omitempty"`
ChipData string `json:"chip_data,omitempty"`
ManualCheck string `json:"manual_check,omitempty"`
ChipData string `json:"chip_data,omitempty"`
CreateExpandedDocumentFields bool `json:"create_expanded_document_fields,omitempty"`
}

// NewRequestedTextExtractionTaskBuilder creates a new RequestedTextExtractionTaskBuilder
Expand All @@ -50,8 +51,9 @@ func NewRequestedTextExtractionTaskBuilder() *RequestedTextExtractionTaskBuilder

// RequestedTextExtractionTaskBuilder builds a RequestedTextExtractionTask
type RequestedTextExtractionTaskBuilder struct {
manualCheck string
chipData string
manualCheck string
chipData string
createExpandedDocumentFields bool
}

// WithManualCheckAlways sets the value of manual check to "ALWAYS"
Expand Down Expand Up @@ -84,11 +86,18 @@ func (builder *RequestedTextExtractionTaskBuilder) WithChipDataIgnore() *Request
return builder
}

// withExpandedDocumentFields sets the value of expanded document fields whether its true or false
func (builder *RequestedTextExtractionTaskBuilder) WithExpandedDocumentFields(expandedDocumentFields bool) *RequestedTextExtractionTaskBuilder {
builder.createExpandedDocumentFields = expandedDocumentFields
return builder
}

// Build builds the RequestedTextExtractionTask
func (builder *RequestedTextExtractionTaskBuilder) Build() (*RequestedTextExtractionTask, error) {
config := RequestedTextExtractionTaskConfig{
builder.manualCheck,
builder.chipData,
builder.createExpandedDocumentFields,
}

return NewRequestedTextExtractionTask(config), nil
Expand Down
12 changes: 12 additions & 0 deletions docscan/session/create/task/text_extraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,15 @@ func TestRequestedTextExtractionTaskBuilder_WithChipDataIgnore(t *testing.T) {
config := task.Config().(RequestedTextExtractionTaskConfig)
assert.Equal(t, "IGNORE", config.ChipData)
}

func TestRequestedTextExtractionTaskBuilder_WithExpandedDocumentFields(t *testing.T) {
task, err := NewRequestedTextExtractionTaskBuilder().
WithExpandedDocumentFields(true).
Build()
if err != nil {
t.Fail()
}

config := task.Config().(RequestedTextExtractionTaskConfig)
assert.Equal(t, true, config.CreateExpandedDocumentFields)
}
6 changes: 6 additions & 0 deletions docscan/session/retrieve/expanded_document_fields_response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package retrieve

// DocumentFieldsResponse represents the document fields in a document
type ExpandedDocumentFieldsResponse struct {
Media *MediaResponse `json:"media"`
}
7 changes: 4 additions & 3 deletions docscan/session/retrieve/id_document_resource_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ type IDDocumentResourceResponse struct {
// Pages are the individual pages of the identity document
Pages []*PageResponse `json:"pages"`
// DocumentFields are the associated document fields of a document
DocumentFields *DocumentFieldsResponse `json:"document_fields"`
DocumentIDPhoto *DocumentIDPhotoResponse `json:"document_id_photo"`
textExtractionTasks []*TextExtractionTaskResponse
DocumentFields *DocumentFieldsResponse `json:"document_fields"`
ExpandedDocumentFields *ExpandedDocumentFieldsResponse `json:"expanded_document_fields"`
DocumentIDPhoto *DocumentIDPhotoResponse `json:"document_id_photo"`
textExtractionTasks []*TextExtractionTaskResponse
}

// TextExtractionTasks returns a slice of text extraction tasks associated with the ID document
Expand Down

0 comments on commit 39bd09e

Please sign in to comment.