Skip to content

Commit

Permalink
Merge pull request #272 from getyoti/SDK-2303-go-support-for-non-lati…
Browse files Browse the repository at this point in the history
…n-documents-when-creating-a-session-using-document-restrictions

SDK-2303:added support-for-non-latin-documents-when-creating-a-sessio…
  • Loading branch information
mehmet-yoti authored May 3, 2023
2 parents 9bf0abd + f159804 commit 3e39bb7
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 14 deletions.
39 changes: 25 additions & 14 deletions docscan/session/create/filter/document_restrictions_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import "encoding/json"

// RequestedDocumentRestrictionsFilter filters for a required document, allowing specification of restrictive parameters
type RequestedDocumentRestrictionsFilter struct {
inclusion string
documents []*RequestedDocumentRestriction
allowExpiredDocuments *bool
inclusion string
documents []*RequestedDocumentRestriction
allowExpiredDocuments *bool
allowNonLatinDocuments *bool
}

// Type is the type of the document restriction filter
Expand All @@ -17,23 +18,26 @@ func (r RequestedDocumentRestrictionsFilter) Type() string {
// MarshalJSON returns the JSON encoding
func (r *RequestedDocumentRestrictionsFilter) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type string `json:"type"`
Inclusion string `json:"inclusion"`
Documents []*RequestedDocumentRestriction `json:"documents"`
AllowExpiredDocuments *bool `json:"allow_expired_documents,omitempty"`
Type string `json:"type"`
Inclusion string `json:"inclusion"`
Documents []*RequestedDocumentRestriction `json:"documents"`
AllowExpiredDocuments *bool `json:"allow_expired_documents,omitempty"`
AllowNonLatinDocuments *bool `json:"allow_non_latin_documents,omitempty"`
}{
Type: r.Type(),
Inclusion: r.inclusion,
Documents: r.documents,
AllowExpiredDocuments: r.allowExpiredDocuments,
Type: r.Type(),
Inclusion: r.inclusion,
Documents: r.documents,
AllowExpiredDocuments: r.allowExpiredDocuments,
AllowNonLatinDocuments: r.allowNonLatinDocuments,
})
}

// RequestedDocumentRestrictionsFilterBuilder builds a RequestedDocumentRestrictionsFilter
type RequestedDocumentRestrictionsFilterBuilder struct {
inclusion string
documents []*RequestedDocumentRestriction
allowExpiredDocuments *bool
inclusion string
documents []*RequestedDocumentRestriction
allowExpiredDocuments *bool
allowNonLatinDocuments *bool
}

// NewRequestedDocumentRestrictionsFilterBuilder creates a new RequestedDocumentRestrictionsFilterBuilder
Expand Down Expand Up @@ -67,11 +71,18 @@ func (b *RequestedDocumentRestrictionsFilterBuilder) WithExpiredDocuments(allowE
return b
}

// WithExpiredDocuments sets a bool value to allowExpiredDocuments on filter
func (b *RequestedDocumentRestrictionsFilterBuilder) WithAllowNonLatinDocuments(allowNonLatinDocuments bool) *RequestedDocumentRestrictionsFilterBuilder {
b.allowNonLatinDocuments = &allowNonLatinDocuments
return b
}

// Build creates a new RequestedDocumentRestrictionsFilter
func (b *RequestedDocumentRestrictionsFilterBuilder) Build() (*RequestedDocumentRestrictionsFilter, error) {
return &RequestedDocumentRestrictionsFilter{
b.inclusion,
b.documents,
b.allowExpiredDocuments,
b.allowNonLatinDocuments,
}, nil
}
38 changes: 38 additions & 0 deletions docscan/session/create/filter/document_restrictions_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,41 @@ func ExampleRequestedDocumentRestrictionsFilterBuilder_withDenyExpiredDocuments(
fmt.Println(string(data))
// Output: {"type":"DOCUMENT_RESTRICTIONS","inclusion":"","documents":[],"allow_expired_documents":false}
}

func ExampleRequestedDocumentRestrictionsFilterBuilder_withAllowNonLatinDocuments() {
restriction, err := NewRequestedDocumentRestrictionsFilterBuilder().
WithAllowNonLatinDocuments(true).
Build()
if err != nil {
fmt.Printf("error: %s", err.Error())
return
}

data, err := json.Marshal(restriction)
if err != nil {
fmt.Printf("error: %s", err.Error())
return
}

fmt.Println(string(data))
// Output: {"type":"DOCUMENT_RESTRICTIONS","inclusion":"","documents":[],"allow_non_latin_documents":true}
}

func ExampleRequestedDocumentRestrictionsFilterBuilder_withDenyNonLatinDocuments() {
restriction, err := NewRequestedDocumentRestrictionsFilterBuilder().
WithAllowNonLatinDocuments(false).
Build()
if err != nil {
fmt.Printf("error: %s", err.Error())
return
}

data, err := json.Marshal(restriction)
if err != nil {
fmt.Printf("error: %s", err.Error())
return
}

fmt.Println(string(data))
// Output: {"type":"DOCUMENT_RESTRICTIONS","inclusion":"","documents":[],"allow_non_latin_documents":false}
}

0 comments on commit 3e39bb7

Please sign in to comment.