outbound 1.0.1 → 1.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/outbound.rb +72 -1
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0880d96cb2a3a97eab063a1bb7f5b2528e945a74
4
- data.tar.gz: 296c46923e1fa4061f56932b84e6b1ab2140c45b
3
+ metadata.gz: c71e5b2056a5a319a0dfc927aa93afdd35f9ea85
4
+ data.tar.gz: 59fe333eb515f8649661f479c829f0592ee3d4ca
5
5
  SHA512:
6
- metadata.gz: 4cf9dff2e7df82501cffe497ce61962baa9587cdb84d88d89122971fb2394954e85abe3eeede3e45b9723f254b8f25f0b56b5e53f7646fde2708706c9ee94066
7
- data.tar.gz: dc781b782d9406d93ba570a7c8c8ddc7ecb61900fe4c8575377ac5f2a0578b7498f930ce0d1d160abc2e69d97ad13eb2356ac4b64e435d3200a9092bec410910
6
+ metadata.gz: 7aa2993b6c0b23d5d1533b1a285e6fdad5affb5394e377b3a642f640c99d45df488b673c3327f747b3bfe74089813bc2c939b38539e94651bdc718b41526b07f
7
+ data.tar.gz: 1229904ebc79bd02eff8c48bef23696f62208e70a1abe301c76567064144b19d87be2a81f5ad578247ce6dc28570f08df3966545a906b64ddd1216246859cede
@@ -4,7 +4,7 @@ require 'net/http'
4
4
  require 'uri'
5
5
 
6
6
  module Outbound
7
- VERSION = '1.0.1'
7
+ VERSION = '1.1.0'
8
8
  BASE_URL = 'https://api.outbound.io/v2'
9
9
 
10
10
  APNS = "apns"
@@ -16,6 +16,7 @@ module Outbound
16
16
  ERROR_INIT = "Must call init() before identify() or track()."
17
17
  ERROR_TOKEN = "Token must be a string."
18
18
  ERROR_PLATFORM = "Unsupported platform specified."
19
+ ERROR_CAMPAIGN_IDS = "At least one campaign ID is required."
19
20
 
20
21
  @ob = nil
21
22
  @logger = Logger.new $stdout
@@ -61,6 +62,15 @@ module Outbound
61
62
  return @ob.disable(platform, user_id, token)
62
63
  end
63
64
 
65
+ def Outbound.disable_all(platform, user_id)
66
+ if @ob == nil
67
+ res = Result.new Outbound::ERROR_INIT, false
68
+ @logger.error res.error
69
+ return res
70
+ end
71
+ return @ob.disable_all(platform, user_id)
72
+ end
73
+
64
74
  def Outbound.register(platform, user_id, token)
65
75
  if @ob == nil
66
76
  res = Result.new Outbound::ERROR_INIT, false
@@ -70,6 +80,24 @@ module Outbound
70
80
  return @ob.register(platform, user_id, token)
71
81
  end
72
82
 
83
+ def Outbound.unsubscribe user_id, all=false, campaign_ids=nil
84
+ if @ob == nil
85
+ res = Result.new Outbound::ERROR_INIT, false
86
+ @logger.error res.error
87
+ return res
88
+ end
89
+ return @ob.subscription user_id, true, all, campaign_ids
90
+ end
91
+
92
+ def Outbound.subscribe user_id, all=false, campaign_ids=nil
93
+ if @ob == nil
94
+ res = Result.new Outbound::ERROR_INIT, false
95
+ @logger.error res.error
96
+ return res
97
+ end
98
+ return @ob.subscription user_id, false, all, campaign_ids
99
+ end
100
+
73
101
  class Result
74
102
  include Defaults
75
103
 
@@ -108,6 +136,10 @@ module Outbound
108
136
  def platform_error?
109
137
  return @error == Outbound::ERROR_PLATFORM
110
138
  end
139
+
140
+ def campaign_id_error?
141
+ return @error == Outbound::ERROR_CAMPAIGN_IDS
142
+ end
111
143
  end
112
144
 
113
145
  class Client
@@ -187,6 +219,22 @@ module Outbound
187
219
  return post(@api_key, "/#{platform}/disable", {:token => token, :user_id => user_id})
188
220
  end
189
221
 
222
+ def disable_all(platform, user_id)
223
+ unless user_id.is_a? String or user_id.is_a? Numeric
224
+ res = Result.new Outbound::ERROR_USER_ID, false
225
+ @logger.error res.error
226
+ return res
227
+ end
228
+
229
+ unless [Outbound::APNS, Outbound::GCM].include? platform
230
+ res = Result.new Outbound::ERROR_PLATFORM, false
231
+ @logger.error res.error
232
+ return res
233
+ end
234
+
235
+ return post(@api_key, "/#{platform}/disable", {:all => true, :user_id => user_id})
236
+ end
237
+
190
238
  def register(platform, user_id, token)
191
239
  unless user_id.is_a? String or user_id.is_a? Numeric
192
240
  res = Result.new Outbound::ERROR_USER_ID, false
@@ -209,6 +257,29 @@ module Outbound
209
257
  return post(@api_key, "/#{platform}/register", {:token => token, :user_id => user_id})
210
258
  end
211
259
 
260
+ def subscription user_id, unsubscribe=false, all=false, campaign_ids=nil
261
+ unless user_id.is_a? String or user_id.is_a? Numeric
262
+ res = Result.new Outbound::ERROR_USER_ID, false
263
+ @logger.error res.error
264
+ return res
265
+ end
266
+
267
+ if !all
268
+ unless !campaign_ids.nil? && campaign_ids.is_a?(Array) && campaign_ids.length > 0
269
+ res = Result.new Outbound::ERROR_CAMPAIGN_IDS, false
270
+ @logger.error res.error
271
+ return res
272
+ end
273
+ end
274
+
275
+ url = '/' + (unsubscribe ? 'unsubscribe' : 'subscribe') + '/' + (all ? 'all' : 'campaigns')
276
+ data = {:user_id => user_id}
277
+ if !all
278
+ data[:campaign_ids] = campaign_ids
279
+ end
280
+ return post(@api_key, url, data)
281
+ end
282
+
212
283
  private
213
284
 
214
285
  def post(api_key, path, data)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: outbound
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Beauvais