-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient_number.go
More file actions
111 lines (100 loc) · 3.78 KB
/
client_number.go
File metadata and controls
111 lines (100 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package epo_ops
import (
"context"
"fmt"
"net/http"
"github.com/patent-dev/epo-ops/generated"
)
// Number Conversion Service - Patent number format conversion.
//
// This file contains methods for converting patent numbers between formats.
// ConvertPatentNumber converts a patent number between formats and returns parsed data.
//
// Parameters:
// - refType: Reference type (e.g., RefTypePublication, RefTypeApplication, RefTypePriority)
// - inputFormat: Input format ("original", "epodoc", "docdb")
// - number: Patent number in input format
// - outputFormat: Output format ("original", "epodoc", "docdb")
//
// Returns parsed NumberConversionData with Country, DocNumber, Kind, and Date fields.
func (c *Client) ConvertPatentNumber(ctx context.Context, refType, inputFormat, number, outputFormat string) (*NumberConversionData, error) {
xmlData, err := c.ConvertPatentNumberRaw(ctx, refType, inputFormat, number, outputFormat)
if err != nil {
return nil, err
}
return ParseNumberConversion(xmlData)
}
func (c *Client) ConvertPatentNumberRaw(ctx context.Context, refType, inputFormat, number, outputFormat string) (string, error) {
if err := ValidateRefType(refType); err != nil {
return "", err
}
if err := ValidateFormat(inputFormat, number); err != nil {
return "", err
}
// Validate output format (just check it's valid, not number specific)
if outputFormat != FormatDocDB && outputFormat != FormatEPODOC && outputFormat != FormatOriginal {
return "", &ValidationError{
Field: "outputFormat",
Value: outputFormat,
Message: "must be 'docdb', 'epodoc', or 'original'",
}
}
return c.makeRequest(ctx, func() (*http.Response, error) {
return c.generated.NumberService(ctx,
generated.NumberServiceParamsType(refType),
generated.NumberServiceParamsInputFormat(inputFormat),
number,
generated.NumberServiceParamsOutputFormat(outputFormat))
})
}
// ConvertPatentNumberMultiple converts multiple patent numbers from one format to another.
// Uses POST endpoint for efficient batch conversion of up to 100 patents in one request.
//
// Parameters:
// - refType: Reference type (e.g., RefTypePublication, RefTypeApplication, RefTypePriority)
// - inputFormat: Input format ("original", "epodoc", "docdb")
// - numbers: Slice of patent numbers in input format (max 100)
// - outputFormat: Output format ("original", "epodoc", "docdb")
//
// Returns XML containing converted patent numbers for all requested patents.
func (c *Client) ConvertPatentNumberMultipleRaw(ctx context.Context, refType, inputFormat string, numbers []string, outputFormat string) (string, error) {
if err := ValidateRefType(refType); err != nil {
return "", err
}
if len(numbers) == 0 {
return "", &ValidationError{
Field: "numbers",
Message: "at least one patent number required",
}
}
if len(numbers) > 100 {
return "", &ValidationError{
Field: "numbers",
Value: fmt.Sprintf("%d", len(numbers)),
Message: "maximum 100 patent numbers per request",
}
}
// Validate output format
if outputFormat != FormatDocDB && outputFormat != FormatEPODOC && outputFormat != FormatOriginal {
return "", &ValidationError{
Field: "outputFormat",
Value: outputFormat,
Message: "must be 'docdb', 'epodoc', or 'original'",
}
}
// Validate each patent number
for i, number := range numbers {
if err := ValidateFormat(inputFormat, number); err != nil {
return "", fmt.Errorf("numbers[%d]: %w", i, err)
}
}
// Use generated POST method
body := formatBulkBody(numbers)
return c.makeRequest(ctx, func() (*http.Response, error) {
return c.generated.NumberServicePOSTWithTextBody(ctx,
generated.NumberServicePOSTParamsType(refType),
generated.NumberServicePOSTParamsInputFormat(inputFormat),
generated.NumberServicePOSTParamsOutputFormat(outputFormat),
body)
})
}