pusher 1.3.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/.gemtest DELETED
File without changes
data/.travis.yml DELETED
@@ -1,16 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- rvm:
4
- - 1.9.3
5
- - 2.0
6
- - 2.1
7
- - 2.2
8
- - 2.3.0
9
- - 2.4.1
10
- - jruby
11
- - rbx-2
12
-
13
- matrix:
14
- allow_failures:
15
- - rvm: jruby
16
- - rvm: rbx-2
@@ -1,69 +0,0 @@
1
- module Pusher
2
- module NativeNotification
3
- class Client
4
- attr_reader :app_id, :host
5
-
6
- API_PREFIX = "server_api"
7
- API_VERSION = "v1"
8
-
9
- def initialize(app_id, host, scheme, pusher_client)
10
- @app_id = app_id
11
- @host = host
12
- @scheme = scheme
13
- @pusher_client = pusher_client
14
- end
15
-
16
- # Send a notification via the native notifications API
17
- def notify(interests, data = {})
18
- Request.new(
19
- @pusher_client,
20
- :post,
21
- url("/notifications"),
22
- {},
23
- payload(interests, data)
24
- ).send_sync
25
- end
26
-
27
- private
28
-
29
- # {
30
- # interests: [Array of interests],
31
- # apns: {
32
- # See https://pusher.com/docs/push_notifications/ios/server
33
- # },
34
- # gcm: {
35
- # See https://pusher.com/docs/push_notifications/android/server
36
- # }
37
- # }
38
- #
39
- # @raise [Pusher::Error] if the interests array is empty
40
- # @return [String]
41
- def payload(interests, data)
42
- interests = Array(interests).map(&:to_s)
43
-
44
- raise Pusher::Error, "Interests array must not be empty" if interests.length == 0
45
-
46
- data = deep_symbolize_keys!(data)
47
-
48
- data.merge!(interests: interests)
49
-
50
- MultiJson.encode(data)
51
- end
52
-
53
- def url(path = nil)
54
- URI.parse("#{@scheme}://#{@host}/#{API_PREFIX}/#{API_VERSION}/apps/#{@app_id}#{path}")
55
- end
56
-
57
- # Symbolize all keys in the hash recursively
58
- def deep_symbolize_keys!(hash)
59
- hash.keys.each do |k|
60
- ks = k.respond_to?(:to_sym) ? k.to_sym : k
61
- hash[ks] = hash.delete(k)
62
- deep_symbolize_keys!(hash[ks]) if hash[ks].kind_of?(Hash)
63
- end
64
-
65
- hash
66
- end
67
- end
68
- end
69
- end