api

package
v0.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CipherBinAPIClient

type CipherBinAPIClient interface {
	Do(req *http.Request) (*http.Response, error)
}

CipherBinAPIClient is used with http.Client and MockClient to allow mocking of services

type Client

type Client struct {
	CipherBinAPIClient
	APIBaseURL     string
	BrowserBaseURL string
}

Client makes network API calls to cipherb.in

func NewClient

func NewClient(browserBaseURL, apiBaseURL string, client CipherBinAPIClient) (*Client, error)

NewClient is a constructor for the ApiClient and satifies the CipherBinAPIClient interface

func (*Client) GetMessage

func (c *Client) GetMessage(url string) (*app.MessageResponse, error)

GetMessage simply takes a cipherb.in public URL string and returns the appropriate encrypted message

func (*Client) PostMessage

func (c *Client) PostMessage(msg *db.Message) error

PostMessage takes a msg of type *db.Message (this is what the server uses and will expect) and posts it to the live cipherbin api

type ClosingBuffer

type ClosingBuffer struct {
	*bytes.Buffer
}

ClosingBuffer embeds a bytes.Buffer, giving it a Read method required for a Response Body ReadCloser body

func MockBody

func MockBody(b []byte) *ClosingBuffer

MockBody creates a mock body that can be added to a response

func (ClosingBuffer) Close

func (cb ClosingBuffer) Close() (err error)

Close allows a ClosingBuffer to Close, implementing a net/http Response Body ReadCloser interface

type MockClient

type MockClient struct {
	Response   []byte
	Responses  [][]byte
	Requests   []*http.Request
	StatusCode int
}

MockClient is responsible for stubbing requests in tests. If the Response field is set, the mock client will respond to each request with the Response. If Responses is set, the mock client will match subsequent requests to subsequent responses, moving along the array of Responses once for each request

func MockResponse

func MockResponse(body string) *MockClient

MockResponse creates a mock client that will return the given response on the body

func MockResponses

func MockResponses(bodies ...string) *MockClient

MockResponses creates a mock client with a series of canned responses

func (*MockClient) Do

func (mock *MockClient) Do(req *http.Request) (*http.Response, error)

Do saves the HTTP Request, returning 200 and no error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL