fomo 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fomo.rb +50 -190
- data/lib/fomo_delete_message_response.rb +28 -0
- data/lib/fomo_event.rb +94 -0
- data/lib/fomo_event_basic.rb +75 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcc514f4a284cc788137ac76d83d20f974ad28d6
|
4
|
+
data.tar.gz: 147477b80dc9f899dfd97fff0ff0f3d5e9d83190
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dffb6233fb5dc77332d5057fabbf37d3dc99005b8f56d8d3a05f81d6a2ca0495b708c46a218bdfd254210a30a6505cc377cc97b9f76ef5f97c8e4c7f17f35bca
|
7
|
+
data.tar.gz: 03d7f8c4a103c153815287b715935694b92466750dc642b477e66b8ab2909f599108d820ae26378c512a0675562c2d6ab28ec0d00e440efeb70e55659b845671
|
data/lib/fomo.rb
CHANGED
@@ -6,6 +6,9 @@
|
|
6
6
|
|
7
7
|
require 'net/http'
|
8
8
|
require 'json'
|
9
|
+
require 'fomo_event_basic'
|
10
|
+
require 'fomo_event'
|
11
|
+
require 'fomo_delete_message_response'
|
9
12
|
|
10
13
|
# Fomo Client is wrapper around official Fomo API (https://www.usefomo.com)
|
11
14
|
class Fomo
|
@@ -35,8 +38,12 @@ class Fomo
|
|
35
38
|
#
|
36
39
|
def get_event(id)
|
37
40
|
response = make_request('/api/v1/applications/me/events/' + id.to_s, 'GET')
|
38
|
-
|
39
|
-
|
41
|
+
begin
|
42
|
+
j = JSON.parse(response)
|
43
|
+
FomoEvent.new(j['id'], j['created_at'], j['updated_at'], j['message'], j['link'], j['event_type_id'], j['url'], j['first_name'], j['city'], j['province'], j['country'], j['title'], j['image_url'], j['custom_event_fields_attributes'])
|
44
|
+
rescue JSON::ParserError => _
|
45
|
+
# String was not valid
|
46
|
+
end
|
40
47
|
end
|
41
48
|
|
42
49
|
# Get events
|
@@ -45,25 +52,46 @@ class Fomo
|
|
45
52
|
#
|
46
53
|
def get_events
|
47
54
|
response = make_request('/api/v1/applications/me/events', 'GET')
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
55
|
+
begin
|
56
|
+
data = JSON.parse(response)
|
57
|
+
list = []
|
58
|
+
data.each do |j|
|
59
|
+
list.push(FomoEvent.new(j['id'], j['created_at'], j['updated_at'], j['message'], j['link'], j['event_type_id'], j['url'], j['first_name'], j['city'], j['province'], j['country'], j['title'], j['image_url'], j['custom_event_fields_attributes']))
|
60
|
+
end
|
61
|
+
list
|
62
|
+
rescue JSON::ParserError => _
|
63
|
+
# String was not valid
|
52
64
|
end
|
53
|
-
list
|
54
65
|
end
|
55
66
|
|
56
67
|
# Create event
|
57
68
|
#
|
58
69
|
# Arguments:
|
59
70
|
# event: (FomoEventBasic) Fomo event
|
71
|
+
# event_type_id: (String) Event type ID
|
72
|
+
# url: (String) Event URL
|
73
|
+
# first_name: (String) First name
|
74
|
+
# city: (String) City
|
75
|
+
# province: (String) Province
|
76
|
+
# country: (String) Country
|
77
|
+
# title: (String) Event title
|
78
|
+
# image_url: (String) Event Image URL
|
79
|
+
# custom_event_fields_attributes: (array) Custom event attributes
|
60
80
|
#
|
61
81
|
# Returns an FomoEvent object.
|
62
82
|
#
|
63
|
-
def create_event(event)
|
83
|
+
def create_event(event=nil, event_type_id='', url='', first_name='', city='', province='', country='', title='', image_url='', custom_event_fields_attributes=[])
|
84
|
+
if event == nil
|
85
|
+
event = FomoEventBasic.new(event_type_id, url, first_name, city, province, country, title, image_url, custom_event_fields_attributes)
|
86
|
+
end
|
87
|
+
|
64
88
|
response = make_request('/api/v1/applications/me/events', 'POST', event)
|
65
|
-
|
66
|
-
|
89
|
+
begin
|
90
|
+
j = JSON.parse(response)
|
91
|
+
FomoEvent.new(j['id'], j['created_at'], j['updated_at'], j['message'], j['link'], j['event_type_id'], j['url'], j['first_name'], j['city'], j['province'], j['country'], j['title'], j['image_url'], j['custom_event_fields_attributes'])
|
92
|
+
rescue JSON::ParserError => _
|
93
|
+
# String was not valid
|
94
|
+
end
|
67
95
|
end
|
68
96
|
|
69
97
|
# Delete event
|
@@ -75,8 +103,12 @@ class Fomo
|
|
75
103
|
#
|
76
104
|
def delete_event(id)
|
77
105
|
response = make_request('/api/v1/applications/me/events/' + id.to_s, 'DELETE')
|
78
|
-
|
79
|
-
|
106
|
+
begin
|
107
|
+
j = JSON.parse(response)
|
108
|
+
FomoDeleteMessageResponse.new(j['message'])
|
109
|
+
rescue JSON::ParserError => _
|
110
|
+
# String was not valid
|
111
|
+
end
|
80
112
|
end
|
81
113
|
|
82
114
|
# Update event
|
@@ -88,8 +120,12 @@ class Fomo
|
|
88
120
|
#
|
89
121
|
def update_event(event)
|
90
122
|
response = make_request('/api/v1/applications/me/events/' + event.id.to_s, 'PATCH', event)
|
91
|
-
|
92
|
-
|
123
|
+
begin
|
124
|
+
j = JSON.parse(response)
|
125
|
+
FomoEvent.new(j['id'], j['created_at'], j['updated_at'], j['message'], j['link'], j['event_type_id'], j['url'], j['first_name'], j['city'], j['province'], j['country'], j['title'], j['image_url'], j['custom_event_fields_attributes'])
|
126
|
+
rescue JSON::ParserError => _
|
127
|
+
# String was not valid
|
128
|
+
end
|
93
129
|
end
|
94
130
|
|
95
131
|
# Make authorized request to Fomo API
|
@@ -134,180 +170,4 @@ class Fomo
|
|
134
170
|
puts('Unknown method')
|
135
171
|
end
|
136
172
|
end
|
137
|
-
end
|
138
|
-
|
139
|
-
# This class holds attributes of basic event, object is needed when creating new event
|
140
|
-
class FomoEventBasic
|
141
|
-
|
142
|
-
# Event type unique ID (required)
|
143
|
-
attr_accessor :event_type_id
|
144
|
-
|
145
|
-
# Url to redirect on the event click. Size range: 0..255 (required)
|
146
|
-
attr_accessor :url
|
147
|
-
|
148
|
-
# First name of the person on the event. Size range: 0..255
|
149
|
-
attr_accessor :first_name
|
150
|
-
|
151
|
-
# City where the event happened. Size range: 0..255
|
152
|
-
attr_accessor :city
|
153
|
-
|
154
|
-
# Province where the event happened. Size range: 0..255
|
155
|
-
attr_accessor :province
|
156
|
-
|
157
|
-
# Country where the event happened ISO-2 standard. Size range: 0..255
|
158
|
-
attr_accessor :country
|
159
|
-
|
160
|
-
# Title of the event. Size range: 0..255
|
161
|
-
attr_accessor :title
|
162
|
-
|
163
|
-
# Url of the image to be displayed. Size range: 0..255
|
164
|
-
attr_accessor :image_url
|
165
|
-
|
166
|
-
# Array to create custom event fields
|
167
|
-
attr_accessor :custom_event_fields_attributes
|
168
|
-
|
169
|
-
# Initializes FomoEventBasic object
|
170
|
-
def initialize(event_type_id='', url='', first_name='', city='', province='', country='', title='', image_url='', custom_event_fields_attributes = [])
|
171
|
-
@event_type_id = event_type_id
|
172
|
-
@url = url
|
173
|
-
@first_name = first_name
|
174
|
-
@city = city
|
175
|
-
@province = province
|
176
|
-
@country = country
|
177
|
-
@title = title
|
178
|
-
@image_url = image_url
|
179
|
-
@custom_event_fields_attributes = custom_event_fields_attributes
|
180
|
-
end
|
181
|
-
|
182
|
-
# Add custom event field
|
183
|
-
#
|
184
|
-
# Arguments:
|
185
|
-
# key: Custom attribute key
|
186
|
-
# value: Custom attribute value
|
187
|
-
# id: Custom attribute ID
|
188
|
-
#
|
189
|
-
def add_custom_event_field(key, value, id='')
|
190
|
-
if id == ''
|
191
|
-
@custom_event_fields_attributes.push({'key' => key, 'value' => value})
|
192
|
-
else
|
193
|
-
@custom_event_fields_attributes.push({'key' => key, 'value' => value, 'id' => id})
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
# Return JSON serialized object
|
198
|
-
def to_json
|
199
|
-
hash = {}
|
200
|
-
self.instance_variables.each do |var|
|
201
|
-
hash[var.to_s.sub(/^@/, '')] = self.instance_variable_get var
|
202
|
-
end
|
203
|
-
'{"event":' + hash.to_json + '}'
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
# This class holds attributes of event, object returned by API
|
208
|
-
class FomoEvent
|
209
|
-
# Event ID
|
210
|
-
attr_accessor :id
|
211
|
-
|
212
|
-
# Created timestamp
|
213
|
-
attr_accessor :created_at
|
214
|
-
|
215
|
-
# Updated timestamp
|
216
|
-
attr_accessor :updated_at
|
217
|
-
|
218
|
-
# Message template
|
219
|
-
attr_accessor :message
|
220
|
-
|
221
|
-
# Full link
|
222
|
-
attr_accessor :link
|
223
|
-
|
224
|
-
# Event type unique ID (required)
|
225
|
-
attr_accessor :event_type_id
|
226
|
-
|
227
|
-
# Url to redirect on the event click. Size range: 0..255 (required)
|
228
|
-
attr_accessor :url
|
229
|
-
|
230
|
-
# First name of the person on the event. Size range: 0..255
|
231
|
-
attr_accessor :first_name
|
232
|
-
|
233
|
-
# City where the event happened. Size range: 0..255
|
234
|
-
attr_accessor :city
|
235
|
-
|
236
|
-
# Province where the event happened. Size range: 0..255
|
237
|
-
attr_accessor :province
|
238
|
-
|
239
|
-
# Country where the event happened ISO-2 standard. Size range: 0..255
|
240
|
-
attr_accessor :country
|
241
|
-
|
242
|
-
# Title of the event. Size range: 0..255
|
243
|
-
attr_accessor :title
|
244
|
-
|
245
|
-
# Url of the image to be displayed. Size range: 0..255
|
246
|
-
attr_accessor :image_url
|
247
|
-
|
248
|
-
# Array to create custom event fields
|
249
|
-
attr_accessor :custom_event_fields_attributes
|
250
|
-
|
251
|
-
# Initializes FomoEvent object
|
252
|
-
def initialize(id='', created_at='', updated_at='', message='', link='', event_type_id='', url='', first_name='', city='', province='', country='', title='', image_url='', custom_event_fields_attributes = [])
|
253
|
-
@id = id
|
254
|
-
@created_at = created_at
|
255
|
-
@updated_at = updated_at
|
256
|
-
@message = message
|
257
|
-
@link = link
|
258
|
-
@event_type_id = event_type_id
|
259
|
-
@url = url
|
260
|
-
@first_name = first_name
|
261
|
-
@city = city
|
262
|
-
@province = province
|
263
|
-
@country = country
|
264
|
-
@title = title
|
265
|
-
@image_url = image_url
|
266
|
-
@custom_event_fields_attributes = custom_event_fields_attributes
|
267
|
-
end
|
268
|
-
|
269
|
-
# Add custom event field
|
270
|
-
#
|
271
|
-
# Arguments:
|
272
|
-
# key: Custom attribute key
|
273
|
-
# value: Custom attribute value
|
274
|
-
# id: Custom attribute ID
|
275
|
-
#
|
276
|
-
def add_custom_event_field(key, value, id='')
|
277
|
-
if id == ''
|
278
|
-
@custom_event_fields_attributes.push({'key' => key, 'value' => value})
|
279
|
-
else
|
280
|
-
@custom_event_fields_attributes.push({'key' => key, 'value' => value, 'id' => id})
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
# Return JSON serialized object
|
285
|
-
def to_json
|
286
|
-
hash = {}
|
287
|
-
self.instance_variables.each do |var|
|
288
|
-
hash[var.to_s.sub(/^@/, '')] = self.instance_variable_get var
|
289
|
-
end
|
290
|
-
'{"event":' + hash.to_json + '}'
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
# This class holds attributes of Fomo delete response, object returned by API
|
295
|
-
class FomoDeleteMessageResponse
|
296
|
-
|
297
|
-
# Message
|
298
|
-
attr_accessor :message
|
299
|
-
|
300
|
-
# Initializes FomoDeleteMessageResponse object
|
301
|
-
def initialize(message='')
|
302
|
-
@message = message
|
303
|
-
end
|
304
|
-
|
305
|
-
# Return JSON serialized object
|
306
|
-
def to_json
|
307
|
-
hash = {}
|
308
|
-
self.instance_variables.each do |var|
|
309
|
-
hash[var.to_s.sub(/^@/, '')] = self.instance_variable_get var
|
310
|
-
end
|
311
|
-
hash.to_json
|
312
|
-
end
|
313
173
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright (c) 2016. Fomo. https://www.usefomo.com
|
2
|
+
#
|
3
|
+
# Author:: Fomo (mailto:hello@usefomo.com)
|
4
|
+
# Copyright:: Copyright (c) 2016. Fomo. https://www.usefomo.com
|
5
|
+
# License:: MIT
|
6
|
+
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
# This class holds attributes of Fomo delete response, object returned by API
|
10
|
+
class FomoDeleteMessageResponse
|
11
|
+
|
12
|
+
# Message
|
13
|
+
attr_accessor :message
|
14
|
+
|
15
|
+
# Initializes FomoDeleteMessageResponse object
|
16
|
+
def initialize(message='')
|
17
|
+
@message = message
|
18
|
+
end
|
19
|
+
|
20
|
+
# Return JSON serialized object
|
21
|
+
def to_json
|
22
|
+
hash = {}
|
23
|
+
self.instance_variables.each do |var|
|
24
|
+
hash[var.to_s.sub(/^@/, '')] = self.instance_variable_get var
|
25
|
+
end
|
26
|
+
hash.to_json
|
27
|
+
end
|
28
|
+
end
|
data/lib/fomo_event.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# Copyright (c) 2016. Fomo. https://www.usefomo.com
|
2
|
+
#
|
3
|
+
# Author:: Fomo (mailto:hello@usefomo.com)
|
4
|
+
# Copyright:: Copyright (c) 2016. Fomo. https://www.usefomo.com
|
5
|
+
# License:: MIT
|
6
|
+
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
# This class holds attributes of event, object returned by API
|
10
|
+
class FomoEvent
|
11
|
+
# Event ID
|
12
|
+
attr_accessor :id
|
13
|
+
|
14
|
+
# Created timestamp
|
15
|
+
attr_accessor :created_at
|
16
|
+
|
17
|
+
# Updated timestamp
|
18
|
+
attr_accessor :updated_at
|
19
|
+
|
20
|
+
# Message template
|
21
|
+
attr_accessor :message
|
22
|
+
|
23
|
+
# Full link
|
24
|
+
attr_accessor :link
|
25
|
+
|
26
|
+
# Event type unique ID (required)
|
27
|
+
attr_accessor :event_type_id
|
28
|
+
|
29
|
+
# Url to redirect on the event click. Size range: 0..255 (required)
|
30
|
+
attr_accessor :url
|
31
|
+
|
32
|
+
# First name of the person on the event. Size range: 0..255
|
33
|
+
attr_accessor :first_name
|
34
|
+
|
35
|
+
# City where the event happened. Size range: 0..255
|
36
|
+
attr_accessor :city
|
37
|
+
|
38
|
+
# Province where the event happened. Size range: 0..255
|
39
|
+
attr_accessor :province
|
40
|
+
|
41
|
+
# Country where the event happened ISO-2 standard. Size range: 0..255
|
42
|
+
attr_accessor :country
|
43
|
+
|
44
|
+
# Title of the event. Size range: 0..255
|
45
|
+
attr_accessor :title
|
46
|
+
|
47
|
+
# Url of the image to be displayed. Size range: 0..255
|
48
|
+
attr_accessor :image_url
|
49
|
+
|
50
|
+
# Array to create custom event fields
|
51
|
+
attr_accessor :custom_event_fields_attributes
|
52
|
+
|
53
|
+
# Initializes FomoEvent object
|
54
|
+
def initialize(id='', created_at='', updated_at='', message='', link='', event_type_id='', url='', first_name='', city='', province='', country='', title='', image_url='', custom_event_fields_attributes = [])
|
55
|
+
@id = id
|
56
|
+
@created_at = created_at
|
57
|
+
@updated_at = updated_at
|
58
|
+
@message = message
|
59
|
+
@link = link
|
60
|
+
@event_type_id = event_type_id
|
61
|
+
@url = url
|
62
|
+
@first_name = first_name
|
63
|
+
@city = city
|
64
|
+
@province = province
|
65
|
+
@country = country
|
66
|
+
@title = title
|
67
|
+
@image_url = image_url
|
68
|
+
@custom_event_fields_attributes = custom_event_fields_attributes
|
69
|
+
end
|
70
|
+
|
71
|
+
# Add custom event field
|
72
|
+
#
|
73
|
+
# Arguments:
|
74
|
+
# key: Custom attribute key
|
75
|
+
# value: Custom attribute value
|
76
|
+
# id: Custom attribute ID
|
77
|
+
#
|
78
|
+
def add_custom_event_field(key, value, id='')
|
79
|
+
if id == ''
|
80
|
+
@custom_event_fields_attributes.push({'key' => key, 'value' => value})
|
81
|
+
else
|
82
|
+
@custom_event_fields_attributes.push({'key' => key, 'value' => value, 'id' => id})
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Return JSON serialized object
|
87
|
+
def to_json
|
88
|
+
hash = {}
|
89
|
+
self.instance_variables.each do |var|
|
90
|
+
hash[var.to_s.sub(/^@/, '')] = self.instance_variable_get var
|
91
|
+
end
|
92
|
+
'{"event":' + hash.to_json + '}'
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# Copyright (c) 2016. Fomo. https://www.usefomo.com
|
2
|
+
#
|
3
|
+
# Author:: Fomo (mailto:hello@usefomo.com)
|
4
|
+
# Copyright:: Copyright (c) 2016. Fomo. https://www.usefomo.com
|
5
|
+
# License:: MIT
|
6
|
+
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
# This class holds attributes of basic event, object is needed when creating new event
|
10
|
+
class FomoEventBasic
|
11
|
+
|
12
|
+
# Event type unique ID (required)
|
13
|
+
attr_accessor :event_type_id
|
14
|
+
|
15
|
+
# Url to redirect on the event click. Size range: 0..255 (required)
|
16
|
+
attr_accessor :url
|
17
|
+
|
18
|
+
# First name of the person on the event. Size range: 0..255
|
19
|
+
attr_accessor :first_name
|
20
|
+
|
21
|
+
# City where the event happened. Size range: 0..255
|
22
|
+
attr_accessor :city
|
23
|
+
|
24
|
+
# Province where the event happened. Size range: 0..255
|
25
|
+
attr_accessor :province
|
26
|
+
|
27
|
+
# Country where the event happened ISO-2 standard. Size range: 0..255
|
28
|
+
attr_accessor :country
|
29
|
+
|
30
|
+
# Title of the event. Size range: 0..255
|
31
|
+
attr_accessor :title
|
32
|
+
|
33
|
+
# Url of the image to be displayed. Size range: 0..255
|
34
|
+
attr_accessor :image_url
|
35
|
+
|
36
|
+
# Array to create custom event fields
|
37
|
+
attr_accessor :custom_event_fields_attributes
|
38
|
+
|
39
|
+
# Initializes FomoEventBasic object
|
40
|
+
def initialize(event_type_id='', url='', first_name='', city='', province='', country='', title='', image_url='', custom_event_fields_attributes = [])
|
41
|
+
@event_type_id = event_type_id
|
42
|
+
@url = url
|
43
|
+
@first_name = first_name
|
44
|
+
@city = city
|
45
|
+
@province = province
|
46
|
+
@country = country
|
47
|
+
@title = title
|
48
|
+
@image_url = image_url
|
49
|
+
@custom_event_fields_attributes = custom_event_fields_attributes
|
50
|
+
end
|
51
|
+
|
52
|
+
# Add custom event field
|
53
|
+
#
|
54
|
+
# Arguments:
|
55
|
+
# key: Custom attribute key
|
56
|
+
# value: Custom attribute value
|
57
|
+
# id: Custom attribute ID
|
58
|
+
#
|
59
|
+
def add_custom_event_field(key, value, id='')
|
60
|
+
if id == ''
|
61
|
+
@custom_event_fields_attributes.push({'key' => key, 'value' => value})
|
62
|
+
else
|
63
|
+
@custom_event_fields_attributes.push({'key' => key, 'value' => value, 'id' => id})
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Return JSON serialized object
|
68
|
+
def to_json
|
69
|
+
hash = {}
|
70
|
+
self.instance_variables.each do |var|
|
71
|
+
hash[var.to_s.sub(/^@/, '')] = self.instance_variable_get var
|
72
|
+
end
|
73
|
+
'{"event":' + hash.to_json + '}'
|
74
|
+
end
|
75
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fomo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fomo
|
@@ -18,6 +18,9 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- lib/fomo.rb
|
21
|
+
- lib/fomo_delete_message_response.rb
|
22
|
+
- lib/fomo_event.rb
|
23
|
+
- lib/fomo_event_basic.rb
|
21
24
|
homepage: https://github.com/usefomo/fomo-ruby-sdk
|
22
25
|
licenses:
|
23
26
|
- MIT
|