pusher 1.2.0.rc3 → 1.2.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc20df33b1edef141b85a41f44b5d48bd1a622ac
4
- data.tar.gz: 1f8bb9ade6ae7531c9f780eb36bea7f5421da2de
3
+ metadata.gz: 8b9efdaf822f5abafd54a89499c0475fd75dfde4
4
+ data.tar.gz: 698e043ffa4116cde7f9951631c865a4c191fff6
5
5
  SHA512:
6
- metadata.gz: 61130fb7ea38cea25bb9a7639c209bff888e722d2b2b488c5510b414a32b867cf91eb8be670d76767dd2a3b2d3f57a094a856a3011f86184b84943a18e99d3ec
7
- data.tar.gz: 1a68e7135cdaf15f34864f836b20c2130a041512f2651eacfc76794d87cacf12421c9442456a79a7497ad0a0a7f6bd5420a3657fc5dbf43074803d4fab60c4e8
6
+ metadata.gz: 8aea046a40212d7b8bcc6467bea3e9ec142dce1917259e86dedadc3919e8cd396d4809bd18626d7ca392a0aea2878156802178d0e9af9a1ef5c9a190161b5d7b
7
+ data.tar.gz: fb590812921456d724f116482ca55195ef19af01eff2b6481a1030afe65064de9798f1c5038cb8f3b09dfc2721af8f3368e0446d50aa204266591786a8d787b2
@@ -5,9 +5,6 @@ module Pusher
5
5
 
6
6
  API_PREFIX = "server_api"
7
7
  API_VERSION = "v1"
8
- GCM_TTL = 241920
9
- RESTRICTED_GCM_PAYLOAD_KEYS = [:to, :registration_ids]
10
- WEBHOOK_LEVELS = ["DEBUG", "INFO"]
11
8
 
12
9
  def initialize(app_id, host, scheme, pusher_client)
13
10
  @app_id = app_id
@@ -45,14 +42,8 @@ module Pusher
45
42
  # @return [String]
46
43
  def payload(interests, data)
47
44
  interests = Array(interests).map(&:to_s)
48
-
49
45
  raise Pusher::Error, "Too many interests provided" if interests.length > 1
50
-
51
- data = deep_symbolize_keys!(data)
52
- validate_payload(data)
53
-
54
- data.merge!(interests: interests)
55
-
46
+ data = deep_symbolize_keys!(data).merge(interests: interests)
56
47
  MultiJson.encode(data)
57
48
  end
58
49
 
@@ -60,54 +51,6 @@ module Pusher
60
51
  URI.parse("#{@scheme}://#{@host}/#{API_PREFIX}/#{API_VERSION}/apps/#{@app_id}#{path}")
61
52
  end
62
53
 
63
- # Validate payload
64
- # `time_to_live` -> value b/w 0 and 241920
65
- # If the `notification` key is provided, ensure
66
- # that there is an accompanying `title` and `icon`
67
- # field
68
- def validate_payload(payload)
69
- unless (payload.has_key?(:apns) || payload.has_key?(:gcm))
70
- raise Pusher::Error, "GCM or APNS data must be provided"
71
- end
72
-
73
- if (gcm_payload = payload[:gcm])
74
- # Restricted keys
75
- RESTRICTED_GCM_PAYLOAD_KEYS.each { |k| gcm_payload.delete(k) }
76
- if (ttl = gcm_payload[:time_to_live])
77
-
78
- if ttl.to_i < 0 || ttl.to_i > GCM_TTL
79
- raise Pusher::Error, "Time to live must be between 0 and 241920 (4 weeks)"
80
- end
81
- end
82
-
83
- # If the notification key is provided
84
- # validate the `icon` and `title`keys
85
- if (notification = gcm_payload[:notification])
86
- notification_title, notification_icon = notification.values_at(:title, :icon)
87
-
88
- if (!notification_title || notification_title.empty?)
89
- raise Pusher::Error, "Notification title is a required field"
90
- end
91
-
92
- if (!notification_icon || notification_icon.empty?)
93
- raise Pusher::Error, "Notification icon is a required field"
94
- end
95
- end
96
- end
97
-
98
- if (webhook_url = payload[:webhook_url])
99
- raise Pusher::Error, "Webhook url is invalid" unless webhook_url =~ /\A#{URI::regexp(['http', 'https'])}\z/
100
- end
101
-
102
- if (webhook_level = payload[:webhook_level])
103
- raise Pusher::Error, "Webhook level cannot be used without a webhook url" if !payload.has_key?(:webhook_url)
104
-
105
- unless WEBHOOK_LEVELS.include?(webhook_level.upcase)
106
- raise Pusher::Error, "Webhook level must either be INFO or DEBUG"
107
- end
108
- end
109
- end
110
-
111
54
  # Symbolize all keys in the hash recursively
112
55
  def deep_symbolize_keys!(hash)
113
56
  hash.keys.each do |k|
@@ -85,7 +85,7 @@ module Pusher
85
85
  when 200
86
86
  return symbolize_first_level(MultiJson.decode(body))
87
87
  when 202
88
- return true
88
+ return body.empty? ? true : symbolize_first_level(MultiJson.decode(body))
89
89
  when 400
90
90
  raise Error, "Bad request: #{body}"
91
91
  when 401
@@ -1,3 +1,3 @@
1
1
  module Pusher
2
- VERSION = '1.2.0.rc3'
2
+ VERSION = '1.2.0.rc4'
3
3
  end
data/spec/client_spec.rb CHANGED
@@ -550,10 +550,6 @@ describe Pusher do
550
550
  expect(@client.notification_host).to eq(@client.notification_client.host)
551
551
  end
552
552
 
553
- it "should raise an error if the gcm or apns key isn't provided in the payload" do
554
- expect { @client.notify(["test"], { foo: "bar" }) }.to raise_error(Pusher::Error)
555
- end
556
-
557
553
  it "should raise an error if more than one interest is provided" do
558
554
  payload = {
559
555
  gcm: {
@@ -567,70 +563,6 @@ describe Pusher do
567
563
  expect { @client.notify(["test1", "test2"], payload) }.to raise_error(Pusher::Error)
568
564
  end
569
565
 
570
- it "should raise an error if the notification hash is missing the title field" do
571
- payload = {
572
- gcm: {
573
- notification: {
574
- icon: "someicon"
575
- }
576
- }
577
- }
578
-
579
- expect{ @client.notify(["test"], payload) }.to raise_error(Pusher::Error)
580
- end
581
-
582
- it "should raise an error if the notification title is empty" do
583
- payload = {
584
- gcm: {
585
- notification: {
586
- title: "",
587
- icon: "myicon"
588
- }
589
- }
590
- }
591
-
592
- expect { @client.notify(["test"], payload) }.to raise_error(Pusher::Error)
593
- end
594
-
595
- it "should raise an error if the notification hash is missing the icon field" do
596
- payload = {
597
- gcm: {
598
- notification: {
599
- title: "sometitle"
600
- }
601
- }
602
- }
603
-
604
- expect{ @client.notify(["test"], payload) }.to raise_error(Pusher::Error)
605
- end
606
-
607
- it "should raise an error if the notification icon is empty" do
608
- payload = {
609
- gcm: {
610
- notification: {
611
- title: "title",
612
- icon: ""
613
- }
614
- }
615
- }
616
-
617
- expect { @client.notify(["test"], payload) }.to raise_error(Pusher::Error)
618
- end
619
-
620
- it "should raise an error if the ttl field is provided and has an illegal value" do
621
- payload = {
622
- gcm: {
623
- time_to_live: 98091283,
624
- notification: {
625
- title: "title",
626
- icon: "icon",
627
- }
628
- }
629
- }
630
-
631
- expect{ @client.notify(["test"], payload) }.to raise_error(Pusher::Error)
632
- end
633
-
634
566
  it "should send a request to the notifications endpoint" do
635
567
  notification_host_regexp = %r{nativepush-cluster1.pusher.com}
636
568
  payload = {
@@ -653,76 +585,8 @@ describe Pusher do
653
585
  :body => MultiJson.encode({ :foo => "bar" })
654
586
  })
655
587
 
656
- @client.notify(["test"], payload)
657
- end
658
-
659
- it "should delete restricted gcm keys before sending a notification" do
660
- notification_host_regexp = %r{nativepush-cluster1.pusher.com}
661
- payload = {
662
- interests: ["test"],
663
- gcm: {
664
- notification: {
665
- title: "Hello",
666
- icon: "icon",
667
- }
668
- }
669
- }
670
-
671
- stub_request(
672
- :post,
673
- notification_host_regexp,
674
- ).with(
675
- body: MultiJson.encode(payload)
676
- ).to_return({
677
- :status => 200,
678
- :body => MultiJson.encode({ :foo => "bar" })
679
- })
680
-
681
- payload[:gcm].merge!(to: "blah", registration_ids: ["reg1", "reg2"])
682
- @client.notify(["test"], payload)
683
- end
684
-
685
- it "should raise an error for an invalid webhook url field" do
686
- payload = {
687
- gcm: {
688
- notification: {
689
- title: "Hello",
690
- icon: "icon"
691
- }
692
- },
693
- webhook_url: "totallyinvalid"
694
- }
695
-
696
- expect { @client.notify(["test"], payload) }.to raise_error(Pusher::Error)
697
- end
698
-
699
- it "should raise an error if the webhook level is not supported" do
700
- payload = {
701
- gcm: {
702
- notification: {
703
- title: "Hello",
704
- icon: "icon"
705
- }
706
- },
707
- webhook_url: "http://test.com/wh",
708
- webhook_level: "meh"
709
- }
710
-
711
- expect { @client.notify(["test"], payload) }.to raise_error(Pusher::Error)
712
- end
713
-
714
- it "should raise an error if the webhook level is used without the webhook url" do
715
- payload = {
716
- gcm: {
717
- notification: {
718
- title: "Hello",
719
- icon: "icon"
720
- }
721
- },
722
- webhook_level: "meh"
723
- }
724
-
725
- expect { @client.notify(["test"], payload) }.to raise_error(Pusher::Error)
588
+ res = @client.notify(["test"], payload)
589
+ expect(res).to eq({foo: "bar"})
726
590
  end
727
591
  end
728
592
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pusher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0.rc3
4
+ version: 1.2.0.rc4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pusher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-02 00:00:00.000000000 Z
11
+ date: 2016-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
186
  version: 1.3.1
187
187
  requirements: []
188
188
  rubyforge_project:
189
- rubygems_version: 2.5.1
189
+ rubygems_version: 2.4.2
190
190
  signing_key:
191
191
  specification_version: 4
192
192
  summary: Pusher API client