本文整理汇总了Golang中github.com/pebble/github-digest/Godeps/_workspace/src/github.com/mbanzon/simplehttp.NewHTTPRequest函数的典型用法代码示例。如果您正苦于以下问题:Golang NewHTTPRequest函数的具体用法?Golang NewHTTPRequest怎么用?Golang NewHTTPRequest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewHTTPRequest函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: DeleteCampaign
// Campaigns have been deprecated since development work on this SDK commenced.
// Please refer to http://documentation.mailgun.com/api_reference .
func (m *MailgunImpl) DeleteCampaign(id string) error {
r := simplehttp.NewHTTPRequest(generateApiUrl(m, campaignsEndpoint) + "/" + id)
r.SetClient(m.Client())
r.SetBasicAuth(basicAuthUser, m.ApiKey())
_, err := makeDeleteRequest(r)
return err
}
示例3: DeleteBounce
// DeleteBounce removes all bounces associted with the provided e-mail address.
func (m *MailgunImpl) DeleteBounce(address string) error {
r := simplehttp.NewHTTPRequest(generateApiUrl(m, bouncesEndpoint) + "/" + address)
r.SetClient(m.Client())
r.SetBasicAuth(basicAuthUser, m.ApiKey())
_, err := makeDeleteRequest(r)
return err
}
示例4: 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.SetClient(m.Client())
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
}
}
示例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: 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
}
示例7: 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
}
示例8: 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
}
示例9: 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
}
示例10: 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
}
示例11: 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
}
示例12: DeleteRoute
// DeleteRoute removes the specified route from your domain's configuration.
// To avoid ambiguity, Mailgun identifies the route by unique ID.
// See the Route structure definition and the Mailgun API documentation for more details.
func (mg *MailgunImpl) DeleteRoute(id string) error {
r := simplehttp.NewHTTPRequest(generatePublicApiUrl(routesEndpoint) + "/" + id)
r.SetClient(mg.Client())
r.SetBasicAuth(basicAuthUser, mg.ApiKey())
_, err := makeDeleteRequest(r)
return err
}
示例13: DeleteDomain
// DeleteDomain instructs Mailgun to dispose of the named domain name.
func (m *MailgunImpl) DeleteDomain(name string) error {
r := simplehttp.NewHTTPRequest(generatePublicApiUrl(domainsEndpoint) + "/" + name)
r.SetClient(m.Client())
r.SetBasicAuth(basicAuthUser, m.ApiKey())
_, err := makeDeleteRequest(r)
return err
}
示例14: 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
}
示例15: 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.SetClient(mg.Client())
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
}