Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Safari Push and Mobile Device Management #9

Merged
merged 5 commits into from
Feb 13, 2015
Merged

Support Safari Push and Mobile Device Management #9

merged 5 commits into from
Feb 13, 2015

Conversation

nathany
Copy link
Contributor

@nathany nathany commented Nov 26, 2014

Rounding out support different types push notifications:

  • Title, Action and URLArgs are for Safari Push notifications.
  • MDM is for Mobile Device Management.

This just allows these types of notifications through, it doesn't ensure that they are fully valid. I'm doing validations in advance.

@bdotdub
Copy link
Contributor

bdotdub commented Dec 3, 2014

Can we add a test case around this?

@nathany
Copy link
Contributor Author

nathany commented Dec 3, 2014

I'd like to. Still test failures on master though, even after #8. I'm new to Ginkgo.

@nathany
Copy link
Contributor Author

nathany commented Dec 10, 2014

@bdotdub I'm not sure how to fix the existing failing tests (#12), but I've now added tests for my additions.

@@ -85,7 +90,11 @@ func (p *Payload) SetCustomValue(key string, value interface{}) error {
}

func (p *Payload) MarshalJSON() ([]byte, error) {
p.customValues["aps"] = p.APS
if len(p.MDM) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry on the delay on this.

This feels a little awkward – there is some implicit behavior that isn't clear from the API. It feels like it should only be the if and no else. Whether or not "aps" is included shouldn't really depend on whether "mdm" exists.

My suggestion is:

if len(p.MDM) != 0 {
    p.customValues["mdm"] = p.MDM
}

p.customValues["aps"] = p.APS

And then including the approach for APS in this PR https://github.com/nathany/apns/pull/1 – it'll make the code much cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bdotdub The thing is the json shouldn't include an empty "aps" node when using MDM.

Perhaps it makes more sense to check if aps is empty? Of course APS isn't just a string, so that's a deep check to ensure the entirety of APS is zero values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bdotdub So I looked into your suggestion because I agree it's awkward as is.

But as far as I know, for Passbook notifications, the JSON should be {"aps":{}} even though there is nothing in the APS struct (aps.isZero() returns true).

For Mobile Device Management, there should be no aps key, as in {"mdm":"00000000-1111-3333-4444-555555555555"}.

So unfortunately there is a dependency there, at least as far as I can tell based on the documentation and other implementations. :-(

Conflicts:
	notification.go
@nathany
Copy link
Contributor Author

nathany commented Dec 17, 2014

I merged #14 into this. Once that's merged, I can rebase so that you can see just these changes.

if aps.Category != "" {
data["category"] = aps.Category
}
if aps.URLArgs != nil && len(aps.URLArgs) != 0 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The need for this confuses me a bit, but it was crashing tests without both.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first condition is redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so, but I was getting crashes later on after adding URLArgs in here. Weird. I can play with it a little more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's odd... I'm guessing it's something else. http://play.golang.org/p/lGAUCTAjGz

@nathany nathany mentioned this pull request Jan 19, 2015
@bdotdub
Copy link
Contributor

bdotdub commented Feb 13, 2015

Merging this!

bdotdub added a commit that referenced this pull request Feb 13, 2015
Support Safari Push and Mobile Device Management
@bdotdub bdotdub merged commit 80d1440 into timehop:master Feb 13, 2015
@nathany
Copy link
Contributor Author

nathany commented Feb 13, 2015

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants