batch_push_notification 0.0.8 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90ca3b38075249a3482b6bb96008fab5e0ce332d
4
- data.tar.gz: 4e417f9e9f891865257a03f1987b1614940c8229
3
+ metadata.gz: 1ca2f7e4293f508c8a9c376d2cfa58d0a0ad10c2
4
+ data.tar.gz: 84153b63904d792a69a87913e61390b3b98418ed
5
5
  SHA512:
6
- metadata.gz: 3b32fbd0ccc21a9dea706c83be238e4d100508c27e8408205def0f8083dab5a899ce2f405e8308ee140d34b6f7cddfe61128e76c2595677027422ab193dae111
7
- data.tar.gz: 178c1532d08f519f012fca960b8c81b9b97893464b9d3eed28971f77843306121d10ce5005c75de76549559b4b123ac31ea719b51e74f9c31535fa774b9bda2a
6
+ metadata.gz: 7cdacb064d1a0710d35675f52f89b4d9d97d70b2d4b9f79d9cb2c7d67877410cb5db85e58fb98484e5a289dea042252e8b14a6b5889cf8e3f5185e8ea46313ef
7
+ data.tar.gz: f2b7a637d8fc50141952905661288e5abcf78182b15f6844411b5c1946f26fa91f7c83329c579a2555d3f4d15d65db2306134764003f4cecc54c7206831e9c0b
@@ -8,18 +8,27 @@ module BatchPushNotification
8
8
  raise(StandardError, 'Configuration is missing') unless BatchPushNotification.endpoint && BatchPushNotification.api_key && BatchPushNotification.rest_api_key && !BatchPushNotification.sandbox.nil?
9
9
  end
10
10
 
11
- def send_notification(notification)
12
- response = connection.post send_url, notification.payload
13
- return JSON.parse(response.body)
11
+ def send_notification(notification, &on_complete)
12
+ send_asynchronously(notification) do |response|
13
+ on_complete.call(response)
14
+ end
14
15
  end
15
16
 
17
+ def send_asynchronously(notification, &on_complete)
18
+ Thread.new do
19
+ response = connection.post send_url, notification.payload
20
+ on_complete.call(JSON.parse(response.body))
21
+ end
22
+ end
23
+
24
+
16
25
  def connection
17
26
  return Faraday.new(:url => BatchPushNotification.endpoint) do |faraday|
18
- faraday.response :logger # log requests to STDOUT
27
+ faraday.response :logger # log requests to STDOUT
19
28
  faraday.headers['Content-Type'] = 'application/json'
20
29
  faraday.headers['X-Authorization'] = BatchPushNotification.rest_api_key
21
30
 
22
- faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
31
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
23
32
  end
24
33
  end
25
34
 
@@ -17,7 +17,6 @@ RSpec.describe BatchPushNotification::Client do
17
17
  let(:custom_payload) { {:poll_id => 1} }
18
18
  let(:notification) { BatchPushNotification::Notification.new({group_id: group_id, tokens: tokens, title: title, body: body, custom_payload: custom_payload}) }
19
19
 
20
- #def initialize(group_id, tokens = [], custom_ids = [], title, body, custom_payload)
21
20
 
22
21
  before {
23
22
  BatchPushNotification.configure do |config|
@@ -31,8 +30,9 @@ RSpec.describe BatchPushNotification::Client do
31
30
 
32
31
  it "can send a notification" do
33
32
  client = BatchPushNotification::Client.new
34
- response = client.send_notification(notification)
35
33
 
36
- expect(response['token']).to_not be_nil
34
+ client.send_notification(notification) do |response|
35
+ expect(response['token']).to_not be_nil
36
+ end
37
37
  end
38
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: batch_push_notification
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicholas Wittstruck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-18 00:00:00.000000000 Z
11
+ date: 2016-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday