本文整理汇总了Golang中github.com/mbanzon/simplehttp.NewHTTPRequest函数的典型用法代码示例。如果您正苦于以下问题:Golang NewHTTPRequest函数的具体用法?Golang NewHTTPRequest怎么用?Golang NewHTTPRequest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewHTTPRequest函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DeleteComplaint
// DeleteComplaint removes a previously registered e-mail address from the list of people who complained
// of receiving spam from your domain.
func (m *MailgunImpl) DeleteComplaint(address string) error {
r := simplehttp.NewHTTPRequest(generateApiUrl(m, complaintsEndpoint) + "/" + address)
r.SetClient(m.client)
r.SetBasicAuth(basicAuthUser, m.ApiKey())
_, err := makeDeleteRequest(r)
return err
}
示例2: UpdateRoute
// UpdateRoute provides an "in-place" update of the specified route.
// Only those route fields which are non-zero or non-empty are updated.
// All other fields remain as-is.
func (mg *MailgunImpl) UpdateRoute(id string, route Route) (Route, error) {
r := simplehttp.NewHTTPRequest(generatePublicApiUrl(routesEndpoint) + "/" + id)
r.SetClient(mg.Client())
r.SetBasicAuth(basicAuthUser, mg.ApiKey())
p := simplehttp.NewUrlEncodedPayload()
if route.Priority != 0 {
p.AddValue("priority", strconv.Itoa(route.Priority))
}
if route.Description != "" {
p.AddValue("description", route.Description)
}
if route.Expression != "" {
p.AddValue("expression", route.Expression)
}
if route.Actions != nil {
for _, action := range route.Actions {
p.AddValue("action", action)
}
}
// For some reason, this API function just returns a bare Route on success.
// Unsure why this is the case; it seems like it ought to be a bug.
var envelope Route
err := putResponseFromJSON(r, p, &envelope)
return envelope, err
}
示例3: RemoveUnsubscribe
// RemoveUnsubscribe removes the e-mail address given from the domain's unsubscription table.
// If passing in an ID (discoverable from, e.g., GetUnsubscribes()), the e-mail address associated
// with the given ID will be removed.
func (mg *MailgunImpl) RemoveUnsubscribe(a string) error {
r := simplehttp.NewHTTPRequest(generateApiUrlWithTarget(mg, unsubscribesEndpoint, a))
r.SetClient(mg.Client())
r.SetBasicAuth(basicAuthUser, mg.ApiKey())
_, err := makeDeleteRequest(r)
return err
}
示例4: GetLists
// GetLists returns the specified set of mailing lists administered by your account.
func (mg *MailgunImpl) GetLists(limit, skip int, filter string) (int, []List, error) {
r := simplehttp.NewHTTPRequest(generatePublicApiUrl(listsEndpoint))
r.SetClient(mg.Client())
r.SetBasicAuth(basicAuthUser, mg.ApiKey())
p := simplehttp.NewUrlEncodedPayload()
if limit != DefaultLimit {
p.AddValue("limit", strconv.Itoa(limit))
}
if skip != DefaultSkip {
p.AddValue("skip", strconv.Itoa(skip))
}
if filter != "" {
p.AddValue("address", filter)
}
var envelope struct {
Items []List `json:"items"`
TotalCount int `json:"total_count"`
}
response, err := makeRequest(r, "GET", p)
if err != nil {
return -1, nil, err
}
err = response.ParseFromJSON(&envelope)
return envelope.TotalCount, envelope.Items, err
}
示例5: CreateList
// CreateList creates a new mailing list under your Mailgun account.
// You need specify only the Address and Name members of the prototype;
// Description, and AccessLevel are optional.
// If unspecified, Description remains blank,
// while AccessLevel defaults to Everyone.
func (mg *MailgunImpl) CreateList(prototype List) (List, error) {
r := simplehttp.NewHTTPRequest(generatePublicApiUrl(listsEndpoint))
r.SetClient(mg.Client())
r.SetBasicAuth(basicAuthUser, mg.ApiKey())
p := simplehttp.NewUrlEncodedPayload()
if prototype.Address != "" {
p.AddValue("address", prototype.Address)
}
if prototype.Name != "" {
p.AddValue("name", prototype.Name)
}
if prototype.Description != "" {
p.AddValue("description", prototype.Description)
}
if prototype.AccessLevel != "" {
p.AddValue("access_level", prototype.AccessLevel)
}
response, err := makePostRequest(r, p)
if err != nil {
return List{}, err
}
var l List
err = response.ParseFromJSON(&l)
return l, err
}
示例6: GetMembers
// GetMembers returns the list of members belonging to the indicated mailing list.
// The s parameter can be set to one of three settings to help narrow the returned data set:
// All indicates that you want both Members and unsubscribed members alike, while
// Subscribed and Unsubscribed indicate you want only those eponymous subsets.
func (mg *MailgunImpl) GetMembers(limit, skip int, s *bool, addr string) (int, []Member, error) {
r := simplehttp.NewHTTPRequest(generateMemberApiUrl(listsEndpoint, addr))
r.SetClient(mg.Client())
r.SetBasicAuth(basicAuthUser, mg.ApiKey())
p := simplehttp.NewUrlEncodedPayload()
if limit != DefaultLimit {
p.AddValue("limit", strconv.Itoa(limit))
}
if skip != DefaultSkip {
p.AddValue("skip", strconv.Itoa(skip))
}
if s != nil {
p.AddValue("subscribed", yesNo(*s))
}
var envelope struct {
TotalCount int `json:"total_count"`
Items []Member `json:"items"`
}
response, err := makeRequest(r, "GET", p)
if err != nil {
return -1, nil, err
}
err = response.ParseFromJSON(&envelope)
return envelope.TotalCount, envelope.Items, err
}
示例7: DeleteMember
// DeleteMember removes the member from the list.
func (mg *MailgunImpl) DeleteMember(member, addr string) error {
r := simplehttp.NewHTTPRequest(generateMemberApiUrl(listsEndpoint, addr) + "/" + member)
r.SetClient(mg.Client())
r.SetBasicAuth(basicAuthUser, mg.ApiKey())
_, err := makeDeleteRequest(r)
return err
}
示例8: GetStats
// GetStats returns a basic set of statistics for different events.
// Events start at the given start date, if one is provided.
// If not, this function will consider all stated events dating to the creation of the sending domain.
func (m *MailgunImpl) GetStats(limit int, skip int, startDate *time.Time, event ...string) (int, []Stat, error) {
r := simplehttp.NewHTTPRequest(generateApiUrl(m, statsEndpoint))
if limit != -1 {
r.AddParameter("limit", strconv.Itoa(limit))
}
if skip != -1 {
r.AddParameter("skip", strconv.Itoa(skip))
}
if startDate != nil {
r.AddParameter("start-date", startDate.Format(time.RFC3339))
}
for _, e := range event {
r.AddParameter("event", e)
}
r.SetBasicAuth(basicAuthUser, m.ApiKey())
var res statsEnvelope
err := getResponseFromJSON(r, &res)
if err != nil {
return -1, nil, err
} else {
return res.TotalCount, res.Items, nil
}
}
示例9: DeleteStoredMessage
// DeleteStoredMessage removes a previously stored message.
// Note that Mailgun institutes a policy of automatically deleting messages after a set time.
// Consult the current Mailgun API documentation for more details.
func (mg *MailgunImpl) DeleteStoredMessage(id string) error {
url := generateStoredMessageUrl(mg, messagesEndpoint, id)
r := simplehttp.NewHTTPRequest(url)
r.SetBasicAuth(basicAuthUser, mg.ApiKey())
_, err := makeDeleteRequest(r)
return err
}
示例10: DeleteList
// DeleteList removes all current members of the list, then removes the list itself.
// Attempts to send e-mail to the list will fail subsequent to this call.
func (mg *MailgunImpl) DeleteList(addr string) error {
r := simplehttp.NewHTTPRequest(generatePublicApiUrl(listsEndpoint) + "/" + addr)
r.SetClient(mg.client)
r.SetBasicAuth(basicAuthUser, mg.ApiKey())
_, err := makeDeleteRequest(r)
return err
}
示例11: DeleteWebhook
// DeleteWebhook removes the specified webhook from your domain's configuration.
func (mg *MailgunImpl) DeleteWebhook(t string) error {
r := simplehttp.NewHTTPRequest(generateDomainApiUrl(mg, webhooksEndpoint) + "/" + t)
r.SetClient(mg.Client())
r.SetBasicAuth(basicAuthUser, mg.ApiKey())
_, err := makeDeleteRequest(r)
return err
}
示例12: DeleteTag
// DeleteTag removes all counters for a particular tag, including the tag itself.
func (m *MailgunImpl) DeleteTag(tag string) error {
r := simplehttp.NewHTTPRequest(generateApiUrl(m, deleteTagEndpoint) + "/" + tag)
r.SetClient(m.Client())
r.SetBasicAuth(basicAuthUser, m.ApiKey())
_, err := makeDeleteRequest(r)
return err
}
示例13: UpdateMember
// UpdateMember lets you change certain details about the indicated mailing list member.
// Address, Name, Vars, and Subscribed fields may be changed.
func (mg *MailgunImpl) UpdateMember(s, l string, prototype Member) (Member, error) {
r := simplehttp.NewHTTPRequest(generateMemberApiUrl(listsEndpoint, l) + "/" + s)
r.SetBasicAuth(basicAuthUser, mg.ApiKey())
p := simplehttp.NewFormDataPayload()
if prototype.Address != "" {
p.AddValue("address", prototype.Address)
}
if prototype.Name != "" {
p.AddValue("name", prototype.Name)
}
if prototype.Vars != nil {
vs, err := json.Marshal(prototype.Vars)
if err != nil {
return Member{}, err
}
p.AddValue("vars", string(vs))
}
if prototype.Subscribed != nil {
p.AddValue("subscribed", yesNo(*prototype.Subscribed))
}
response, err := makePutRequest(r, p)
if err != nil {
return Member{}, err
}
var envelope struct {
Member Member `json:"member"`
}
err = response.ParseFromJSON(&envelope)
return envelope.Member, err
}
示例14: GetSingleDomain
// Retrieve detailed information about the named domain.
func (m *MailgunImpl) GetSingleDomain(domain string) (Domain, []DNSRecord, []DNSRecord, error) {
r := simplehttp.NewHTTPRequest(generatePublicApiUrl(domainsEndpoint) + "/" + domain)
r.SetBasicAuth(basicAuthUser, m.ApiKey())
var envelope singleDomainEnvelope
err := getResponseFromJSON(r, &envelope)
return envelope.Domain, envelope.ReceivingDNSRecords, envelope.SendingDNSRecords, err
}
示例15: fetch
// GetFirstPage, GetPrevious, and GetNext all have a common body of code.
// fetch completes the API fetch common to all three of these functions.
func (ei *EventIterator) fetch(url string) error {
r := simplehttp.NewHTTPRequest(url)
r.SetClient(ei.mg.Client())
r.SetBasicAuth(basicAuthUser, ei.mg.ApiKey())
var response map[string]interface{}
err := getResponseFromJSON(r, &response)
if err != nil {
return err
}
items := response["items"].([]interface{})
ei.events = make([]Event, len(items))
for i, item := range items {
ei.events[i] = item.(map[string]interface{})
}
pagings := response["paging"].(map[string]interface{})
links := make(map[string]string, len(pagings))
for key, page := range pagings {
links[key] = page.(string)
}
ei.nextURL = links["next"]
ei.prevURL = links["previous"]
return err
}