alidayu

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefCommonParams is default common parameters of alidayu APIs
	DefCommonParams = map[string]string{
		"format":      "json",
		"v":           "2.0",
		"sign_method": "md5",
	}
)

Functions

func GetSortedQueryStr

func GetSortedQueryStr(params map[string]string) (sortedQueryStr string)

GetSortedQueryStr sorts the keys of parameters and generate sorted query string which can be used to sign(MD5 or HMAC_MD5).

Types

type Client

type Client struct {
	AppKey    string // App Key
	AppSecret string // App Secret
	UseHTTPS  bool   // Use HTTPS URL or not
	http.Client
}

Client contains app key and secret and provides method to post HTTP request like http.Request.

func (*Client) Exec

func (c *Client) Exec(params map[string]string) (success bool, result string, err error)

Exec executes the REST API and get the response. It's a wrapper of Post().

Params:
  params: map that contains parameters of REST API. See official docs to fill the parameters.
Returns:
  success: If REST API succeeds.
  result: Raw response string of REST API.

func (*Client) IsValid

func (c *Client) IsValid() bool

IsValid checks if a client is valid.

func (*Client) MakeRequestBody

func (c *Client) MakeRequestBody(params map[string]string) (body io.Reader, err error)

MakeRequestBody makes the HTTP request body by given parameters for each REST API.

func (*Client) Post

func (c *Client) Post(params map[string]string) (resp *http.Response, err error)

Post does the HTTP post for each REST API.

Params:
  params: map that contains parameters of REST API. See official docs to fill the parameters.
Returns:
  resp: HTTP Response. Do not forget to call resp.Body.Close() after use.

func (*Client) SignHMAC

func (c *Client) SignHMAC(params map[string]string) (signature string)

SignHMAC gets the sorted query string and sign it using HMAC_MD5.

func (*Client) SignMD5

func (c *Client) SignMD5(params map[string]string) (signature string)

SignMD5 gets the sorted query string and sign it using MD5.

func (*Client) UpdateCommonParams

func (c *Client) UpdateCommonParams(params map[string]string)

UpdateCommonParams updates the given parameters by merge default common parameters.

Jump to

Keyboard shortcuts

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