| 1 |  |  | package ynote | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | import ( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | 	"net/http" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | 	"strings" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | // Option is options for constructing a client | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | type Option interface { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | 	apply(config *clientConfig) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | type clientOptionFunc func(config *clientConfig) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | func (fn clientOptionFunc) apply(config *clientConfig) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 	fn(config) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | // WithHTTPClient sets the underlying HTTP client used for API requests. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | // By default, http.DefaultClient is used. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | func WithHTTPClient(httpClient *http.Client) Option { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 	return clientOptionFunc(func(config *clientConfig) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 		if httpClient != nil { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 			config.httpClient = httpClient | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 	}) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | // WithTokenURL set's the token URL for the Y-Note API | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | func WithTokenURL(tokenURL string) Option { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	return clientOptionFunc(func(config *clientConfig) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 		if tokenURL != "" { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 			config.tokenURL = strings.TrimRight(tokenURL, "/") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	}) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | // WithAPIURL set's the api URL for the Y-Note API | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | func WithAPIURL(apiURL string) Option { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	return clientOptionFunc(func(config *clientConfig) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 		if apiURL != "" { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 			config.apiURL = strings.TrimRight(apiURL, "/") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	}) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | // WithClientID sets the Y-Note API clientID used to fetch the access token | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | func WithClientID(clientID string) Option { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 	return clientOptionFunc(func(config *clientConfig) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		config.clientID = clientID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 	}) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | // WithClientSecret sets the Y-Note API client secret used to fetch the access token | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | func WithClientSecret(clientSecret string) Option { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 	return clientOptionFunc(func(config *clientConfig) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 		config.clientSecret = clientSecret | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 	}) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | // WithCustomerKey sets the customer key used to make API requests | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | func WithCustomerKey(customerKey string) Option { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	return clientOptionFunc(func(config *clientConfig) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		config.customerKey = customerKey | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	}) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 68 |  |  | // WithCustomerSecret sets the customer secret used to make API requests | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  | func WithCustomerSecret(customerSecret string) Option { | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  | 	return clientOptionFunc(func(config *clientConfig) { | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  | 		config.customerSecret = customerSecret | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 	}) | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 73 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |  |