pushbots 0.4.0 → 0.5.0

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: 7b766d00b676a82fdcfea64e2c3baa7509f61900
4
- data.tar.gz: b36715e61c9708936e41c9cc37e68fbe66fd423c
3
+ metadata.gz: 9a70f662bdddb8da1d0eeae97de09d2db4632f4a
4
+ data.tar.gz: 0f0048266baac821779b8afa47f50adb88ccf4e5
5
5
  SHA512:
6
- metadata.gz: 1fcfa2c1a14c66a7c00462c500a3b4f4ed132f7c4b0078664ad54cad2a0e82e8dcf29d467d657a26b1d0f64c2c86f514c39eca5e8efa8a2859f4fe9b59a75f78
7
- data.tar.gz: 688203201284b99fa6dfadb36f66278b124eefd283aed4e1fffef23facbaee275584ce44df026eb592a8c7ff6246982b3c5da1aa604edd46c9431eaa53e6e4c6
6
+ metadata.gz: acd6f809ab13f15929229deb0d4ef8d0b2f1f4cdf030dc87e818fdc067addd5c8124e4cb81b0593e0a709ac439f29c3708da50b7065fa5cc5480c76bad442349
7
+ data.tar.gz: 1b22944ba80950c5e1d3c03a2aac5df6487b6f87fb3ad3d2b408bd27c3a390d493144fc274cc5d2cdd3ae3adb411dfd0d6e174583693063d2bc3c7876b91c7c3
data/README.md CHANGED
@@ -12,6 +12,7 @@ this gem on your favorite Ruby on Rails Projects.
12
12
  - [How to use](#how-to-use)
13
13
  - [Device management](#device-management)
14
14
  - [Register a device](#register-a-device)
15
+ - [Register multiple devices](#register-multiple-devices)
15
16
  - [Delete a device](#delete-a-device)
16
17
  - [Device information](#device-information)
17
18
 
@@ -59,8 +60,25 @@ device = Pushbots::Device.new(token, platform)
59
60
  device.register
60
61
  ```
61
62
 
63
+ #### Register multiple devices
64
+ ```ruby
65
+ tokens = ['8js62lsod8',
66
+ '71882jksu2']
67
+ platform = :ios
68
+ tags = ['vip', 'cool_people']
69
+ # tokens and platform are required to add multiple devices
70
+ # tags is an optional parameter
71
+ devices = Pushbots::Devices.new(tokens, platform, tags)
72
+ # register the devices to pushbots returns true/false
73
+ # an attempt to register a device
74
+ # that has been already registered returns false
75
+ devices.register
76
+ ```
77
+
62
78
  #### Delete a device
63
79
  ```ruby
80
+ token = 'k2iwp29271'
81
+ platform = :ios
64
82
  # token and platform are required to delete a device
65
83
  device = Pushbots::Device.new(token, platform)
66
84
  # remove the device from pushbots
@@ -71,9 +89,11 @@ device.delete
71
89
  #### Device information
72
90
  ```ruby
73
91
  # token is required to get device information
92
+ token = '182ksiwl29'
74
93
  # platform is an optional parameter
75
94
  device = Pushbots::Device.new(token)
76
95
  # Get device information
96
+ device.info
77
97
  # Device token
78
98
  device.token
79
99
  # Device status
@@ -86,7 +106,7 @@ device.tags
86
106
  #### Single device notification
87
107
  ```ruby
88
108
  # Device token
89
- token = '900f9e35cc09ab9f3d99f0b244e23f160e0264f1aaf785549efeb6835a586710'
109
+ token = '82ksh62j1a'
90
110
  # platform is :ios or :android
91
111
  # (Any other value will return a RuntimeError)
92
112
  platform = :ios
@@ -6,6 +6,7 @@ require 'pushbots/response'
6
6
  require 'pushbots/one'
7
7
  require 'pushbots/all'
8
8
  require 'pushbots/device'
9
+ require 'pushbots/devices'
9
10
 
10
11
  # Pushbots module
11
12
  module Pushbots
@@ -0,0 +1,20 @@
1
+ module Pushbots
2
+ # Devices class
3
+ class Devices
4
+ attr_accessor :tokens, :platform, :tags
5
+ PLATFORM_TYPE = { ios: 0, android: 1 }.freeze
6
+
7
+ def initialize(tokens, platform, tags = nil)
8
+ self.tokens = tokens
9
+ self.platform = platform
10
+ self.tags = tags if tags
11
+ end
12
+
13
+ def register
14
+ body = { tokens: tokens, platform: PLATFORM_TYPE[platform] }
15
+ body[:tags] = tags if tags
16
+ response = Request.register_batch(body)
17
+ response.code == 201
18
+ end
19
+ end
20
+ end
@@ -26,6 +26,12 @@ module Pushbots
26
26
  HTTP.headers(header_base).put(url, json: body)
27
27
  end
28
28
 
29
+ def self.register_batch(body)
30
+ url = 'https://api.pushbots.com/deviceToken/batch'
31
+ header = header_base.merge(header_push)
32
+ HTTP.headers(header).put(url, json: body)
33
+ end
34
+
29
35
  def self.header_base
30
36
  {
31
37
  :'X-PushBots-AppID' => Config.config.application_id,
@@ -1,4 +1,4 @@
1
1
  # Pushbots gem version
2
2
  module Pushbots
3
- VERSION = '0.4.0'.freeze
3
+ VERSION = '0.5.0'.freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pushbots
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Omana
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-03-19 00:00:00.000000000 Z
12
+ date: 2016-03-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -110,6 +110,7 @@ files:
110
110
  - lib/pushbots/all.rb
111
111
  - lib/pushbots/config.rb
112
112
  - lib/pushbots/device.rb
113
+ - lib/pushbots/devices.rb
113
114
  - lib/pushbots/one.rb
114
115
  - lib/pushbots/push.rb
115
116
  - lib/pushbots/request.rb