outbound 0.2.1 → 0.3

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 (2) hide show
  1. data/lib/outbound.rb +77 -3
  2. metadata +1 -1
data/lib/outbound.rb CHANGED
@@ -4,13 +4,18 @@ require 'net/http'
4
4
  require 'uri'
5
5
 
6
6
  module Outbound
7
- VERSION = '0.2.1'
7
+ VERSION = '0.3'
8
8
  BASE_URL = 'https://api.outbound.io/v2'
9
9
 
10
+ APNS = "apns"
11
+ GCM = "gcm"
12
+
10
13
  ERROR_USER_ID = "User ID must be a string or number."
11
14
  ERROR_EVENT_NAME = "Event name must be a string."
12
15
  ERROR_CONNECTION = "Outbound connection error"
13
16
  ERROR_INIT = "Must call init() before identify() or track()."
17
+ ERROR_TOKEN = "Token must be a string."
18
+ ERROR_PLATFORM = "Unsupported platform specified."
14
19
 
15
20
  @ob = nil
16
21
  @logger = Logger.new $stdout
@@ -20,8 +25,7 @@ module Outbound
20
25
  module Defaults
21
26
  HEADERS = {
22
27
  'Content-type' => 'application/json',
23
- 'X-Outbound-Client' => 'ruby',
24
- 'X-Outbound-Client-Version' => Outbound::VERSION,
28
+ 'X-Outbound-Client' => 'Ruby/' + Outbound::VERSION,
25
29
  }
26
30
  end
27
31
 
@@ -49,6 +53,24 @@ module Outbound
49
53
  return @ob.track user_id, event, properties, user_info, user_attributes
50
54
  end
51
55
 
56
+ def Outbound.disable platform, user_id, token
57
+ if @ob == nil
58
+ res = Result.new Outbound::ERROR_INIT, false
59
+ @logger.error res.error
60
+ return res
61
+ end
62
+ return @ob.disable platform, user_id, token
63
+ end
64
+
65
+ def Outbound.register platform, user_id, token
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.register platform, user_id, token
72
+ end
73
+
52
74
  class Result
53
75
  include Defaults
54
76
 
@@ -79,6 +101,14 @@ module Outbound
79
101
  def init_error?
80
102
  return @error == Outbound::ERROR_INIT
81
103
  end
104
+
105
+ def token_error?
106
+ return @error == Outbound::ERROR_TOKEN
107
+ end
108
+
109
+ def platform_error?
110
+ return @error == Outbound::ERROR_PLATFORM
111
+ end
82
112
  end
83
113
 
84
114
  class Client
@@ -142,6 +172,50 @@ module Outbound
142
172
  return post(@api_key, '/track', data)
143
173
  end
144
174
 
175
+ def disable platform, user_id, token
176
+ unless user_id.is_a? String or user_id.is_a? Numeric
177
+ res = Result.new Outbound::ERROR_USER_ID, false
178
+ @logger.error res.error
179
+ return res
180
+ end
181
+
182
+ unless token.is_a? String
183
+ res = Result.new Outbound::ERROR_TOKEN, false
184
+ @logger.error res.error
185
+ return res
186
+ end
187
+
188
+ unless [Outbound::APNS, Outbound::GCM].include? platform
189
+ res = Result.new Outbound::ERROR_PLATFORM, false
190
+ @logger.error res.error
191
+ return res
192
+ end
193
+
194
+ return post(@api_key, "/#{platform}/disable", {:token => token, :user_id => user_id})
195
+ end
196
+
197
+ def register platform, user_id, token
198
+ unless user_id.is_a? String or user_id.is_a? Numeric
199
+ res = Result.new Outbound::ERROR_USER_ID, false
200
+ @logger.error res.error
201
+ return res
202
+ end
203
+
204
+ unless token.is_a? String
205
+ res = Result.new Outbound::ERROR_TOKEN, false
206
+ @logger.error res.error
207
+ return res
208
+ end
209
+
210
+ unless [Outbound::APNS, Outbound::GCM].include? platform
211
+ res = Result.new Outbound::ERROR_PLATFORM, false
212
+ @logger.error res.error
213
+ return res
214
+ end
215
+
216
+ return post(@api_key, "/#{platform}/register", {:token => token, :user_id => user_id})
217
+ end
218
+
145
219
  private
146
220
 
147
221
  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: 0.2.1
4
+ version: '0.3'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: