pusher 1.3.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/stale.yml +26 -0
- data/.github/workflows/gh-release.yml +35 -0
- data/.github/workflows/publish.yml +17 -0
- data/.github/workflows/release.yml +71 -0
- data/.github/workflows/test.yml +31 -0
- data/CHANGELOG.md +84 -66
- data/README.md +76 -24
- data/examples/presence_channels/presence_channels.rb +56 -0
- data/examples/presence_channels/public/presence_channels.html +28 -0
- data/lib/pusher.rb +0 -3
- data/lib/pusher/channel.rb +9 -0
- data/lib/pusher/client.rb +98 -68
- data/lib/pusher/version.rb +1 -1
- data/pull_request_template.md +7 -0
- data/pusher.gemspec +12 -9
- data/spec/channel_spec.rb +22 -5
- data/spec/client_spec.rb +169 -96
- metadata +52 -39
- data/.document +0 -5
- data/.gemtest +0 -0
- data/.travis.yml +0 -16
- data/lib/pusher/native_notification/client.rb +0 -69
data/.document
DELETED
data/.gemtest
DELETED
File without changes
|
data/.travis.yml
DELETED
@@ -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
|