Git Product home page Git Product logo

gosparkpost's Introduction

image

Sign up for a SparkPost account and visit our Developer Hub for even more content.

SparkPost Go API client

Build Status

Code Coverage

Go Doc

The official Go package for using the SparkPost API.

Installation

Install from GitHub using go get:

Get a key

Go to API & SMTP in the SparkPost app and create an API key. We recommend using the SPARKPOST_API_KEY environment variable. The example code below shows how to set this up.

Send a message

Here at SparkPost, our "send some messages" api is called the transmissions API - let's use it to send a friendly test message:

Documentation

Contribute

TL;DR:

  1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.
  2. Fork the repository.
  3. Go get the original code - go get https://github.com/SparkPost/gosparkpost
  4. Add your fork as a remote - git remote add fork http://github.com/YOURID/gosparkpost
  5. Make your changes in a branch on your fork
  6. Write a test which shows that the bug was fixed or that the feature works as expected.
  7. Push your changes - git push fork HEAD
  8. Send a pull request. Make sure to add yourself to AUTHORS.

More on the contribution process

gosparkpost's People

Contributors

avezina-ubik avatar aydrian avatar cbroglie avatar damianopetrungaro avatar deelawn avatar jen20 avatar jfriedland-atlassian avatar jgzamora avatar kakysha avatar macfisherman avatar mostafah avatar nexweb avatar richleland avatar vojtechvitek avatar yargevad avatar yepher avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gosparkpost's Issues

Removing `ErrWebhookValidation`?

Validation is not an error. It’s just an empty request and should return an empty list of events with no error. An empty list means the user won’t do anything, after all.

Returning an error when there is not one forces the user to check for this particular error and ignore it, which is not nice code. Removing this error makes it easier to use the events package.

So, what is the use of this special error? Is there a reason for keeping it? (Don’t know about compatibility policy of this package.)

I can send a PR for its removal if you agree with this.

support new suppression list fields; tests

The SparkPost Suppression List API endpoint will soon return separate entries for the transactional and non_transactional suppression types. A new field, type, will also be added.

This issue tracks making sure this library handles those changes gracefully.

See this blog post for more details.

Transmission.Options.StartTime formatting Error

Tried sending an transmission like the following:

tx := &sp.Transmission {
    Recipients: []string{email},
    Content: map[string]string {
        "template_id": templateId,
    },
    Options: &sp.TxOptions {
        StartTime: time.Now().Add(time.Minute * 5),
    }
}

and client.Send(tx) returns the following error:

{ "errors": [ { "message": "invalid data format\/type", "description": "Error parsing scheduled start_time", "code": "1300" } ] }

The docs seem to imply that the start_time should be RFC3339 formatted in the request body. Seems like this format should be applied before marshalling.

Segfault due to broken example and missing check

I did copy & paste from README example and got a segfault:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x69b3f6]

goroutine 60 [running]:
net/http.(*Client).deadline(0x0, 0xc42000e928, 0x410612, 0xc4202469c0)
	/usr/local/go/src/net/http/client.go:186 +0x26
net/http.(*Client).Do(0x0, 0xc420181800, 0xc4200101f0, 0xc420181800, 0x0)
	/usr/local/go/src/net/http/client.go:497 +0x89
github.com/SparkPost/gosparkpost.(*Client).DoRequest(0xc4200f5be8, 0xc15440, 0xc4200101f0, 0x9a19f8, 0x4, 0xc42029b7d0, 0x2e, 0xc4200aa800, 0xb47, 0x1612, ...)
	/home/email/lib/go/src/github.com/SparkPost/gosparkpost/common.go:196 +0x609
github.com/SparkPost/gosparkpost.(*Client).HttpPost(0xc4200f5be8, 0xc15440, 0xc4200101f0, 0xc42029b7d0, 0x2e, 0xc4200aa800, 0xb47, 0x1612, 0x30, 0xc42029ade0, ...)
	/home/email/lib/go/src/github.com/SparkPost/gosparkpost/common.go:112 +0x9f
github.com/SparkPost/gosparkpost.(*Client).SendContext(0xc4200f5be8, 0xc15440, 0xc4200101f0, 0xc4205883c0, 0x40e57f, 0x979400, 0xc420188e60, 0xc4200f5c18, 0xc420188e60)
	/home/email/lib/go/src/github.com/SparkPost/gosparkpost/transmissions.go:227 +0x292
github.com/SparkPost/gosparkpost.(*Client).Send(0xc4200f5be8, 0xc4205883c0, 0x979400, 0xc420188e60, 0x0, 0x0, 0x0)
	/home/email/lib/go/src/github.com/SparkPost/gosparkpost/transmissions.go:205 +0x5

The cause of this is https://github.com/SparkPost/gosparkpost/blob/master/common.go#L196 and the fact that README never initializes the c.Client unlike its unit test https://github.com/SparkPost/gosparkpost/blob/master/common_test.go#L30.

If I modify common.go line 196 to

        if c.Client == nil {
                c.Client = http.DefaultClient
        }                
        res, err := c.Client.Do(req)

the segfault goes away.

My suggestions are:

  1. Append tests to include what README does.
  2. Apply my common.go modification to guarantee client existence. Note that as c.Client is exported it can be set outside of init and thus my modification in DoRequest. Or perhaps make Client be client and force use of NewClient() which would then always do return &client{Client: http.DefaultClient}.

Document Client thread safety

Hello,

Are we supposed to create a new client per routine, or can the same client be re-used concurrently between multiple goroutines?

Sending Struct for SubstitutionData

Disclaimer: I'm very new to Go, so this could be a mistake / misunderstanding on my behalf.

I'm trying to send a struct type as the data for the SubstitutionData parameter in the Transmission struct but it fails at the AssertObject phase within the common.go file. This is because it doesn't match any of the accepted Types.

However, if I remove the limitation (and just have it return nil), this works as expected (since the struct has the JSON structure to Marshal from a struct to JSON).

Am I passing the data incorrectly, or is it a deficiency in the assertion?

Any suggestions would be appreciated.

Set up coveralls

  • we use coveralls.io for code coverage
  • need to do this after the repo is public

Support Cursor in Suppress List Search API

The suppression list search API uses a cursor to page through all results.

The JSON has the following structure:

{
  "results": [
   ... RESULT OBJEC....
  ],
  "links": [
    {
      "href": "/api/v1/suppression-list?cursor=initial&per_page=1000",
      "rel": "first"
    },
    {
      "href": "/api/v1/suppression-list?cursor=curserValuew&per_page=1000",
      "rel": "next"
    }
  ],
  "total_count": 1111469
}

This relates to SparkPost/sparkpost-cli#15 in the SparkPost CLI.

Suppression List `SuppressionList` does not work

The function suppression_list::SuppressionList(...) does not pass parameters so it is not possible to step through pages etc.

The method suppression_list::SuppressionSearch(...) is the same thing suppression_list::SuppressionList(...) should do.

Either suppression_list::SuppressionList(...) should be removed or it should be mapped to the suppression_list::SuppressionSearch(...) function.

Notice in the API there is no differentiation between Search and List: Suppression List API

allow setting arbitrary headers on requests

In addition to having the map[string]string as a part of the Client, this will add Headers *map[string]string on the various objects that are encoded to JSON and passed to endpoints, like Transmissions.

The idea would be to build a map[string]string with your (for example) subaccount-specific details - even api key in the Authorization header if that's part of your use case), and reference that map to include those headers on requests using that object.

Impossible to publish a draft template

I've created a draft template using this library. However, it is literally impossible to publish it using the provided APIs. Mostly getting the [{"message":"Resource could not be found","code":"","description":""}] error from the server.

A simplified version of what I'm doing, is more or less like so:

tmpl := sp.Template{
    ID: "my-template-id",
}

// Get draft
_, err := spClient.TemplateGet(&tmpl, true)
if err != nil {
    panic(err)
}

// Publish draft
tmpl.Published = true
_, err := spClient.TemplateUpdate(&tmpl)
if err != nil {
    panic(err)
}

It appears that this library is setting the update_published GET parameter in addition to passing in the published field as JSON. Which seem to make the SparkPost API very much confused. Thus it ends up returning the misleading error above.

Though, according to the API docs, this shouldn't really happen as the update_published should be ignored when published field is true. But, eh...

Removing the update_published from the TemplateUpdateContext function seems to make things work as they should. Inspecting the web-app it doesn't use the update_published query parameter either.

Long story short: it would be nice to be able to publish draft templates using this library. 😃

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.