stackmob 0.1.1 → 0.1.2

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.
@@ -56,13 +56,17 @@ module StackMob
56
56
  headers = {}
57
57
  for headerArr in env.select { |k, v| k.start_with? 'HTTP_' }
58
58
  if !EXCLUDED_HEADERS.include?(headerArr[0])
59
- headers[headerArr[0].sub('HTTP_', '')] = headerArr[1]
59
+ headers[normalize(headerArr[0])] = headerArr[1]
60
60
  end
61
61
  end
62
62
  headers["Accept"] = "application/json"
63
63
  headers
64
64
  end
65
65
 
66
+ def normalize(key)
67
+ key.sub('HTTP_', '').split('_').map! { |p| p.downcase }.join("-")
68
+ end
69
+
66
70
  end
67
71
  end
68
72
  end
data/lib/stackmob/push.rb CHANGED
@@ -18,9 +18,11 @@ module StackMob
18
18
  attr_accessor :client
19
19
 
20
20
  PUSH_SVC = :push
21
- DEVICE_TOKEN_PATH = "/device_tokens"
22
- BROADCAST_PATH = "/push_broadcast"
23
- PUSH_PATH = "/push"
21
+ DEVICE_TOKEN_PATH = "/register_device_token_universal"
22
+ REMOVE_DEVICE_TOKEN = "/remove_token_universal"
23
+ BROADCAST_PATH = "/push_broadcast_universal"
24
+ PUSH_TOKENS_PATH = "/push_tokens_universal"
25
+ PUSH_USERS_PATH = "/push_users_universal"
24
26
 
25
27
  DEFAULT_BADGE = 0
26
28
  DEFAULT_SOUND = ""
@@ -33,31 +35,42 @@ module StackMob
33
35
  self.client.request(:post, PUSH_SVC, DEVICE_TOKEN_PATH, :userId => user_id, :token => device_token) # using non-convential symbols to conform to StackMob Push API
34
36
  end
35
37
 
36
- def broadcast(opts)
37
- aps_data = generate_aps_data(opts)
38
- payload = {:recipients => [], :aps => aps_data, :areRecipientsDeviceTokens => true, :exclude_tokens => []}
39
-
40
- self.client.request(:post, PUSH_SVC, BROADCAST_PATH, payload)
38
+ def remove(device_token)
39
+ self.client.request(:post, PUSH_SVC, REMOVE_DEVICE_TOKEN, device_token)
41
40
  end
42
41
 
43
- def send_message(to, opts)
44
- aps_data = generate_aps_data(opts)
45
- recipients_are_device_tokens = (opts[:recipients_are_users]) ? false : true
46
- payload = {:recipients => Array(to), :aps => aps_data, :areRecipientsDeviceTokens => recipients_are_device_tokens, :exclude_tokens => []}
47
-
48
- self.client.request(:post, PUSH_SVC, PUSH_PATH, payload)
42
+ def broadcast(opts)
43
+ payload = { :kvPairs => opts }
44
+ self.client.request(:post, PUSH_SVC, BROADCAST_PATH, payload)
49
45
  end
50
46
 
51
- def generate_aps_data(opts)
47
+ def aps_data(opts)
52
48
  alert = opts[:alert] || (raise ArgumentError.new("Push requires alert message"))
53
49
  badge = opts[:badge] || DEFAULT_BADGE
54
50
  sound = opts[:sound] || DEFAULT_SOUND
55
51
 
56
52
  {:badge => badge, :sound => sound, :alert => alert}
57
53
  end
58
- private :generate_aps_data
59
54
 
60
-
55
+ # Deprecated
56
+ def send_message(to, opts)
57
+ warn "[DEPRECATION] `send_message` is deprecated and does not support android, please use `send_message_to_tokens` or `send_message_to_users`"
58
+ recipients_are_device_tokens = (opts[:recipients_are_users]) ? false : true
59
+ payload = {:recipients => Array(to), :aps => aps_data(opts), :areRecipientsDeviceTokens => recipients_are_device_tokens, :exclude_tokens => []}
60
+
61
+ self.client.request(:post, PUSH_SVC, "/push", payload)
62
+ end
61
63
 
64
+ def send_message_to_tokens(to, opts)
65
+ to = [to] if to.is_a? Hash
66
+ payload = {:tokens => Array(to), :payload => { :kvPairs => opts }}
67
+ self.client.request(:post, PUSH_SVC, PUSH_TOKENS_PATH, payload)
68
+ end
69
+
70
+ def send_message_to_users(to, opts)
71
+ payload = {:userIds => Array(to), :kvPairs => opts}
72
+ self.client.request(:post, PUSH_SVC, PUSH_USERS_PATH, payload)
73
+ end
62
74
  end
75
+
63
76
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stackmob
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - StackMob
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-17 00:00:00 Z
18
+ date: 2012-04-09 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -87,12 +87,11 @@ dependencies:
87
87
  requirements:
88
88
  - - ~>
89
89
  - !ruby/object:Gem::Version
90
- hash: 27
90
+ hash: 9
91
91
  segments:
92
92
  - 1
93
93
  - 3
94
- - 0
95
- version: 1.3.0
94
+ version: "1.3"
96
95
  prerelease: false
97
96
  requirement: *id005
98
97
  type: :runtime