-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from jon4hz/test-better-req
request function with interface arguments
- Loading branch information
Showing
17 changed files
with
752 additions
and
1,368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,45 @@ | ||
package btcpay | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
func (c *Client) RevokeAPIKey(ctx context.Context, apiKey *APIKey) (int, error) { | ||
endpoint := fmt.Sprintf("%s/api/v1/api-keys/%s", c.URL, *apiKey) | ||
req, err := http.NewRequestWithContext(ctx, "DELETE", endpoint, nil) | ||
if err != nil { | ||
return 0, err | ||
} | ||
_, statusCode, err := c.doRequest(req) | ||
statusCode, err := c.doRequest(ctx, endpoint, "DELETE", nil, nil) | ||
if err != nil { | ||
return statusCode, err | ||
} | ||
return statusCode, nil | ||
} | ||
|
||
type APIKeyResponse struct { | ||
APIKey APIKey `json:"apiKey"` | ||
Label string `json:"label"` | ||
Permissions []BTCPayPermission `json:"permissions"` | ||
} | ||
|
||
func (c *Client) GetCurrentAPIKey(ctx context.Context) (*APIKeyResponse, int, error) { | ||
endpoint := fmt.Sprintf("%s/api/v1/api-keys/current", c.URL) | ||
req, err := http.NewRequestWithContext(ctx, "GET", endpoint, nil) | ||
if err != nil { | ||
return nil, 0, err | ||
} | ||
bytes, statusCode, err := c.doRequest(req) | ||
if err != nil { | ||
return nil, statusCode, err | ||
} | ||
var dataRes APIKeyResponse | ||
err = json.Unmarshal(bytes, &dataRes) | ||
statusCode, err := c.doRequest(ctx, endpoint, "GET", &dataRes, nil) | ||
if err != nil { | ||
return nil, 0, err | ||
return nil, statusCode, err | ||
} | ||
return &dataRes, statusCode, nil | ||
} | ||
|
||
func (c *Client) RevokeCurrentAPIKey(ctx context.Context) (*APIKeyResponse, int, error) { | ||
endpoint := fmt.Sprintf("%s/api/v1/api-keys/current", c.URL) | ||
req, err := http.NewRequestWithContext(ctx, "DELETE", endpoint, nil) | ||
if err != nil { | ||
return nil, 0, err | ||
} | ||
bytes, statusCode, err := c.doRequest(req) | ||
var dataRes APIKeyResponse | ||
statusCode, err := c.doRequest(ctx, endpoint, "DELETE", &dataRes, nil) | ||
if err != nil { | ||
return nil, statusCode, err | ||
} | ||
var data APIKeyResponse | ||
err = json.Unmarshal(bytes, &data) | ||
if err != nil { | ||
return nil, 0, err | ||
} | ||
return &data, statusCode, nil | ||
} | ||
|
||
type APIKeyRequest struct { | ||
Label string `json:"label,omitempty"` | ||
Permissions []BTCPayPermission `json:"permissions,omitempty"` | ||
return &dataRes, statusCode, nil | ||
} | ||
|
||
func (c *Client) CreateAPIKey(ctx context.Context, apiKeyRequest *APIKeyRequest) (*APIKeyResponse, int, error) { | ||
endpoint := fmt.Sprintf("%s/api/v1/api-keys", c.URL) | ||
dataReq, err := json.Marshal(apiKeyRequest) | ||
if err != nil { | ||
return nil, 0, err | ||
} | ||
req, err := http.NewRequestWithContext(ctx, "POST", endpoint, bytes.NewBuffer(dataReq)) | ||
if err != nil { | ||
return nil, 0, err | ||
} | ||
bytes, statusCode, err := c.doRequest(req) | ||
if err != nil { | ||
return nil, statusCode, err | ||
} | ||
var dataRes APIKeyResponse | ||
err = json.Unmarshal(bytes, &dataRes) | ||
statusCode, err := c.doRequest(ctx, endpoint, "POST", &dataRes, apiKeyRequest) | ||
if err != nil { | ||
return nil, 0, err | ||
return nil, statusCode, err | ||
} | ||
return &dataRes, statusCode, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
package btcpay | ||
|
||
// Enums SpeedPolicy | ||
type BTCPaySpeedPolicy string | ||
|
||
type SpeedPolicy struct { | ||
HighSpeed BTCPaySpeedPolicy | ||
MediumSpeed BTCPaySpeedPolicy | ||
LowMediumSpeed BTCPaySpeedPolicy | ||
LowSpeed BTCPaySpeedPolicy | ||
} | ||
|
||
func GetSpeedPolicy() *SpeedPolicy { | ||
return &SpeedPolicy{ | ||
HighSpeed: "HighSpeed", | ||
MediumSpeed: "MediumSpeed", | ||
LowMediumSpeed: "LowMediumSpeed", | ||
LowSpeed: "LowSpeed", | ||
} | ||
} | ||
|
||
// Enums InvoiceStatus | ||
type BTCPayInvoiceStatus string | ||
|
||
type InvoiceStatus struct { | ||
New BTCPayInvoiceStatus | ||
Processing BTCPayInvoiceStatus | ||
Expired BTCPayInvoiceStatus | ||
Invalid BTCPayInvoiceStatus | ||
Settled BTCPayInvoiceStatus | ||
} | ||
|
||
func GetInvoiceStatus() *InvoiceStatus { | ||
return &InvoiceStatus{ | ||
New: "New", | ||
Processing: "Processing", | ||
Expired: "Expired", | ||
Invalid: "Invalid", | ||
Settled: "Settled", | ||
} | ||
} | ||
|
||
// Enums InvoiceAdditionalStatus | ||
type BTCPayInvoiceAdditionalStatus string | ||
|
||
type InvoiceAdditionalStatus struct { | ||
None BTCPayInvoiceAdditionalStatus | ||
PaidLate BTCPayInvoiceAdditionalStatus | ||
PaidPartial BTCPayInvoiceAdditionalStatus | ||
Marked BTCPayInvoiceAdditionalStatus | ||
AddInvalid BTCPayInvoiceAdditionalStatus | ||
PaidOver BTCPayInvoiceAdditionalStatus | ||
} | ||
|
||
func GetInvoiceAdditionalStatus() *InvoiceAdditionalStatus { | ||
return &InvoiceAdditionalStatus{ | ||
None: "None", | ||
PaidLate: "PaidLate", | ||
PaidPartial: "PaidPartial", | ||
Marked: "Marked", | ||
AddInvalid: "Invalid", | ||
PaidOver: "PaidOver", | ||
} | ||
|
||
} | ||
|
||
// Enums InvoiceStatusMark | ||
type BTCPayInvoiceStatusMark string | ||
|
||
type InvoiceStatusMark struct { | ||
MarkInvalid BTCPayInvoiceStatusMark | ||
MarkComplete BTCPayInvoiceStatusMark | ||
} | ||
|
||
func GetInvoiceStatusMark() *InvoiceStatusMark { | ||
return &InvoiceStatusMark{ | ||
MarkInvalid: "Invalid", | ||
MarkComplete: "Complete", | ||
} | ||
} | ||
|
||
// Enums PaymentStatus | ||
type BTCPayPaymentStatus string | ||
|
||
type PaymentStatus struct { | ||
New BTCPayPaymentStatus | ||
Processing BTCPayPaymentStatus | ||
Expired BTCPayPaymentStatus | ||
Invalid BTCPayPaymentStatus | ||
Settled BTCPayPaymentStatus | ||
} | ||
|
||
func GetPaymentStatus() *PaymentStatus { | ||
return &PaymentStatus{ | ||
Processing: "Processing", | ||
Invalid: "Invalid", | ||
Settled: "Settled", | ||
} | ||
} | ||
|
||
// Enums PaymentRequestStatus | ||
type BTCPayPaymentRequestStatus string | ||
|
||
type PaymentRequestStatus struct { | ||
Pending BTCPayInvoiceStatus | ||
Completed BTCPayInvoiceStatus | ||
Expired BTCPayInvoiceStatus | ||
} | ||
|
||
func GetPaymentRequestStatus() *PaymentRequestStatus { | ||
return &PaymentRequestStatus{ | ||
Pending: "Pending", | ||
Completed: "Completed", | ||
Expired: "Expired", | ||
} | ||
} | ||
|
||
// Enums NetworkFeeMode | ||
type BTCPayPayoutStatus string | ||
|
||
type PayoutStatus struct { | ||
AwaitingApproval BTCPayPayoutStatus | ||
AwaitingPayment BTCPayPayoutStatus | ||
InProgress BTCPayPayoutStatus | ||
Completed BTCPayPayoutStatus | ||
Cancelled BTCPayPayoutStatus | ||
} | ||
|
||
func GetPayoutStatus() *PayoutStatus { | ||
return &PayoutStatus{ | ||
AwaitingApproval: "AwaitingApproval", | ||
AwaitingPayment: "AwaitingPayment", | ||
InProgress: "InProgress", | ||
Completed: "Completed", | ||
Cancelled: "Cancelled", | ||
} | ||
} | ||
|
||
// Enums NetworkFeeMode | ||
type BTCPayNetworkFeeMode string | ||
|
||
type NetworkFeeMode struct { | ||
MultiplePaymentsOnly BTCPayNetworkFeeMode | ||
Always BTCPayNetworkFeeMode | ||
Never BTCPayNetworkFeeMode | ||
} | ||
|
||
func GetNetworkFeeMode() *NetworkFeeMode { | ||
return &NetworkFeeMode{ | ||
MultiplePaymentsOnly: "MultiplePaymentsOnly", | ||
Always: "Always", | ||
Never: "Never", | ||
} | ||
} |
Oops, something went wrong.