Comments (4)
Added a fix here:
Commit: 85d31e2 [85d31e2]
Parents: fe82e99
Author: Chris Wilson [email protected]
Date: February 11, 2016 at 9:23:22 AM CST
Labels: HEAD master
• Fixes problem where Timestamp was getting decoded as int64
instead of String
.
• Changes imports to be relative so it is easier to test local changes or changes on a branch.
from gosparkpost.
#35 parses timestamps into native golang time.Time
values via custom JSON Unmarshaller. I noticed that Webhook Event API returns Unix timestamps (int64) and Event Samples API returns string of RFC 3339-like format.
Snippet:
type Timestamp time.Time
func (t *Timestamp) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprint(time.Time(*t).Unix())), nil
}
func (t *Timestamp) UnmarshalJSON(data []byte) error {
// Timestamps coming from Webhook Events are Unix timestamps.
unix, err := strconv.ParseInt(string(data), 10, 64)
if err == nil {
*t = Timestamp(time.Unix(unix, 0))
return nil
}
// Timestamps coming from Event Samples are in this RFC 3339-like format.
customTime, err := time.Parse("\"2006-01-02T15:04:05.000-07:00\"", string(data))
if err != nil {
return err
}
*t = Timestamp(customTime)
return nil
}
from gosparkpost.
Seems like the API changed or something in the last few days -- and instead of pure Unix timestamp integers, the Webhook API now returns strings. I had to add another commit https://github.com/pressly/gosparkpost/commit/c848d16a4f77aec77fb6e89d5fffd94441632a1a to trim the quotes.
from gosparkpost.
@yepher this can be closed, since Timestamps are now time.Time
values
from gosparkpost.
Related Issues (20)
- user-defined templating macros HOT 1
- workaround for servername/cert mismatches HOT 2
- Cannot send HTML in SubstitutionData HOT 2
- oobgen to/from the wrong way around? HOT 1
- support campaign_id in sparks HOT 1
- missing transmission options HOT 1
- Feature: Add Account Info
- Add "Validate a Webhook" endpoint
- allow overriding host that oobgen and fblgen deliver to HOT 1
- Events endpoint support
- Recipient Validation endpoint support
- Transactional option declared in two places HOT 2
- Add TODOs Badge to README
- Use go modules HOT 1
- Fix license to make docs work on pkg.go.dev HOT 2
- Bounce Class Constants
- Proposal: Please start using Semantic Versioning HOT 8
- Bug: Wrong names when using multiple recipients HOT 1
- Add support for setting initial_open tracking option HOT 1
- SuppressionEntry type is missing sub-account ID JSON as returned by the API
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gosparkpost.