diff --git a/helpers.go b/helpers.go index 37914e1..aeabd39 100644 --- a/helpers.go +++ b/helpers.go @@ -7,22 +7,19 @@ import ( // GetTelegraphClient returns a new TelegraphClient using the specified options. func GetTelegraphClient(options *ClientOpt) *TelegraphClient { if options == nil { - options = GetDefaultOptions() + options = &ClientOpt{} + } + if options.HttpClient == nil { + options.HttpClient = http.DefaultClient + } + if options.ApiUrl == "" { + options.ApiUrl = "https://api.telegra.ph/" } - return &TelegraphClient{ HttpClient: options.HttpClient, } } -// GetDefaultOptions returns the default-options used for constructing a -// TelegraphClient. -func GetDefaultOptions() *ClientOpt { - return &ClientOpt{ - HttpClient: http.DefaultClient, - } -} - // EditInfo is a helper method to easily call EditAccountInfo by an account. func (a *Account) EditInfo(client *TelegraphClient, opts *EditAccountInfoOpts) (*Account, error) { return client.EditAccountInfo(a.AccessToken, opts) diff --git a/requests.go b/requests.go index 0416903..2ba4cc4 100644 --- a/requests.go +++ b/requests.go @@ -19,7 +19,7 @@ type Body struct { } func (c *TelegraphClient) InvokeRequest(method string, params url.Values) (json.RawMessage, error) { - r, err := http.NewRequest(http.MethodPost, "https://api.telegra.ph/"+method, strings.NewReader(params.Encode())) + r, err := http.NewRequest(http.MethodPost, c.ApiUrl+method, strings.NewReader(params.Encode())) if err != nil { return nil, fmt.Errorf("failed to build POST request to %s: %w", method, err) } diff --git a/types.go b/types.go index fd44bab..fc5d12e 100644 --- a/types.go +++ b/types.go @@ -6,12 +6,17 @@ import ( // TelegraphClient is the client that contains all library methods implemented on it. type TelegraphClient struct { + // Api URL of the Telegraph API. + ApiUrl string // HttpClient is the http client used to send http requests to the Telegraph API. HttpClient *http.Client } // ClientOpt is the options used to construct the TelegraphClient value. type ClientOpt struct { + // Api URL of the Telegraph API. + ApiUrl string + // HttpClient is the http client used to send http requests to the Telegraph API. HttpClient *http.Client }