Skip to content

Commit 72b04b5

Browse files
authored
Merge pull request #55 from pusher/remove-pn
Remove push notifications from go lib
2 parents a7ce6f7 + 65ffc66 commit 72b04b5

File tree

4 files changed

+8
-259
lines changed

4 files changed

+8
-259
lines changed

client.go

Lines changed: 8 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,16 @@ If you wish to set a time-limit for each HTTP request, set the `Timeout` propert
3838
Changing the `pusher.Client`'s `Host` property will make sure requests are sent to your specified host.
3939
4040
client.Host = "foo.bar.com" // by default this is "api.pusherapp.com".
41-
42-
If you wish to use push notifications, you need to define the Client.PushNotificationHost,
43-
please see Pusher docs for more details: https://pusher.com/docs/push_notifications
4441
*/
4542
type Client struct {
46-
AppId string
47-
Key string
48-
Secret string
49-
Host string // host or host:port pair
50-
PushNotificationHost string
51-
Secure bool // true for HTTPS
52-
Cluster string
53-
HttpClient *http.Client
54-
EncryptionMasterKey string //for E2E
43+
AppId string
44+
Key string
45+
Secret string
46+
Host string // host or host:port pair
47+
Secure bool // true for HTTPS
48+
Cluster string
49+
HttpClient *http.Client
50+
EncryptionMasterKey string //for E2E
5551
}
5652

5753
/*
@@ -490,48 +486,3 @@ func (c *Client) Webhook(header http.Header, body []byte) (*Webhook, error) {
490486
}
491487
return nil, errors.New("Invalid webhook")
492488
}
493-
494-
/*
495-
Notify is used to send native push notifications via Apple APNS or Google GCM/FCM systems. Please make sure that
496-
you have provided a Client.PushNotificationHost, please see Pusher docs for details: https://pusher.com/docs/push_notifications
497-
*/
498-
func (c *Client) Notify(interests []string, pushNotification PushNotification) (*NotifyResponse, error) {
499-
pNRequest := notificationRequest{
500-
interests,
501-
&pushNotification,
502-
}
503-
504-
err := pNRequest.validate()
505-
if err != nil {
506-
return nil, err
507-
}
508-
509-
if c.PushNotificationHost == "" {
510-
return nil, errors.New("PushNotificationHost not provided")
511-
}
512-
513-
requestBody, err := json.Marshal(pNRequest)
514-
if err != nil {
515-
return nil, err
516-
}
517-
518-
path := fmt.Sprintf("/%s/%s/apps/%s/notifications", PushNotifAPIPrefixDefault, PushNotifAPIVersionDefault, c.AppId)
519-
520-
url, err := createRequestURL("POST", c.PushNotificationHost, path, c.Key, c.Secret, authTimestamp(), c.Secure, requestBody, nil, c.Cluster)
521-
if err != nil {
522-
return nil, err
523-
}
524-
525-
byteResponse, err := c.request("POST", url, requestBody)
526-
if err != nil {
527-
return nil, err
528-
}
529-
530-
var response *NotifyResponse
531-
err = json.Unmarshal(byteResponse, &response)
532-
if err != nil {
533-
return nil, err
534-
}
535-
536-
return response, err
537-
}

client_test.go

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -341,99 +341,3 @@ func TestInitialisationFromENV(t *testing.T) {
341341
expectedClient := &Client{Key: "feaf18a411d3cb9216ee", Secret: "fec81108d90e1898e17a", AppId: "104060", Host: "api.pusherapp.com"}
342342
assert.Equal(t, expectedClient, client)
343343
}
344-
345-
func TestNotifySuccess(t *testing.T) {
346-
server := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
347-
res.WriteHeader(http.StatusOK)
348-
res.Write([]byte(`{"number_of_subscribers": 10}`))
349-
}))
350-
defer server.Close()
351-
352-
u, _ := url.Parse(server.URL)
353-
client := Client{AppId: "id", Key: "key", Secret: "secret", PushNotificationHost: u.Host, HttpClient: &http.Client{Timeout: time.Millisecond * 100}}
354-
testPN := PushNotification{
355-
WebhookURL: "testURL",
356-
GCM: []byte(`hello`),
357-
}
358-
interests := []string{"testInterest"}
359-
response, err := client.Notify(interests, testPN)
360-
361-
assert.Equal(t, 10, response.NumSubscribers, "returned response.NumSubscribers should be equal to the server response body amount")
362-
assert.NoError(t, err)
363-
}
364-
365-
func TestNotifySuccessNoSubscribers(t *testing.T) {
366-
server := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
367-
res.WriteHeader(http.StatusAccepted)
368-
res.Write([]byte(`{"number_of_subscribers":0}`))
369-
}))
370-
defer server.Close()
371-
372-
u, _ := url.Parse(server.URL)
373-
client := Client{AppId: "id", Key: "key", Secret: "secret", PushNotificationHost: u.Host, HttpClient: &http.Client{Timeout: time.Millisecond * 100}}
374-
testPN := PushNotification{
375-
WebhookURL: "testURL",
376-
GCM: []byte(`hello`),
377-
}
378-
interests := []string{"testInterest"}
379-
response, err := client.Notify(interests, testPN)
380-
381-
assert.Equal(t, 0, response.NumSubscribers, "returned response.NumSubscribers should be equal to the server response body amount")
382-
assert.NoError(t, err)
383-
}
384-
385-
func TestNotifyServerError(t *testing.T) {
386-
server := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
387-
res.WriteHeader(http.StatusInternalServerError)
388-
}))
389-
defer server.Close()
390-
391-
u, _ := url.Parse(server.URL)
392-
client := Client{AppId: "id", Key: "key", Secret: "secret", PushNotificationHost: u.Host, HttpClient: &http.Client{Timeout: time.Millisecond * 100}}
393-
testPN := PushNotification{
394-
WebhookURL: "testURL",
395-
GCM: []byte(`hello`),
396-
}
397-
398-
interests := []string{"testInterest"}
399-
response, err := client.Notify(interests, testPN)
400-
401-
assert.Nil(t, response, "response should return nil on error")
402-
assert.Error(t, err)
403-
assert.EqualError(t, err, "Status Code: 500 - ")
404-
}
405-
406-
func TestNotifyInvalidPushNotification(t *testing.T) {
407-
server := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
408-
res.WriteHeader(http.StatusInternalServerError)
409-
}))
410-
defer server.Close()
411-
412-
u, _ := url.Parse(server.URL)
413-
client := Client{AppId: "id", Key: "key", Secret: "secret", PushNotificationHost: u.Host, HttpClient: &http.Client{Timeout: time.Millisecond * 100}}
414-
testPN := PushNotification{
415-
WebhookURL: "testURL",
416-
}
417-
interests := []string{"testInterest"}
418-
response, err := client.Notify(interests, testPN)
419-
420-
assert.Nil(t, response, "response should return nil on error")
421-
assert.Error(t, err)
422-
}
423-
424-
func TestNotifyNoPushNotificationHost(t *testing.T) {
425-
server := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
426-
res.WriteHeader(http.StatusInternalServerError)
427-
}))
428-
defer server.Close()
429-
430-
client := Client{AppId: "id", Key: "key", Secret: "secret", HttpClient: &http.Client{Timeout: time.Millisecond * 100}}
431-
testPN := PushNotification{
432-
WebhookURL: "testURL",
433-
}
434-
interests := []string{"testInterest"}
435-
response, err := client.Notify(interests, testPN)
436-
437-
assert.Nil(t, response, "response should return nil on error")
438-
assert.Error(t, err)
439-
}

push_notifications.go

Lines changed: 0 additions & 42 deletions
This file was deleted.

push_notifications_test.go

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)