cisco-spark-ruby 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/bin/ciscospark +418 -0
- data/lib/base.rb +31 -0
- data/lib/cisco-spark-ruby.rb +119 -0
- data/lib/collection.rb +22 -0
- data/lib/membership.rb +31 -0
- data/lib/memberships.rb +19 -0
- data/lib/message.rb +30 -0
- data/lib/messages.rb +19 -0
- data/lib/people.rb +19 -0
- data/lib/person.rb +29 -0
- data/lib/room.rb +32 -0
- data/lib/rooms.rb +23 -0
- data/lib/team.rb +20 -0
- data/lib/teammembership.rb +31 -0
- data/lib/teammemberships.rb +19 -0
- data/lib/teams.rb +19 -0
- data/lib/webhook.rb +29 -0
- data/lib/webhooks.rb +18 -0
- metadata +22 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66ba5bbbea189d32ad44cc227c649b767d950897
|
4
|
+
data.tar.gz: 29d7e6f4cf70b10595809a3b21596817c4228075
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c1311ae16a9383819247355444c4b5199741be9f9f2ba0c3803a344c8a8a55e4b779147ab174b451b7954e04a3c3050bb02524044fa26b0dda42dde53564660
|
7
|
+
data.tar.gz: 3da75d71b74c7a2468409b9662d25b4c36640528adcdd3d265f67f1b117f57435edb4e2251f1530c7ac0aa9a17b96e1df6379aef99b0bda885b860b392f52bab
|
data/bin/ciscospark
ADDED
@@ -0,0 +1,418 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse/subcommand'
|
4
|
+
# $LOAD_PATH.push("/Users/robertlabrie/Documents/code/cisco-spark-ruby/lib")
|
5
|
+
|
6
|
+
require 'cisco-spark-ruby'
|
7
|
+
options = {}
|
8
|
+
parser = OptionParser.new do |opts|
|
9
|
+
opts.on('-h','--help', 'Show Help') do
|
10
|
+
options[:help] = 'root'
|
11
|
+
end
|
12
|
+
opts.subcommand 'webhook' do |subcommand|
|
13
|
+
options[:entity] = 'webhook'
|
14
|
+
subcommand.on('-h','--help','Show help') { |o| options[:help] = 'webhook'}
|
15
|
+
subcommand.subcommand 'list' do |action|
|
16
|
+
options[:action] = 'list'
|
17
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'webhook-list'}
|
18
|
+
end
|
19
|
+
subcommand.subcommand 'get' do |action|
|
20
|
+
options[:action] = 'get'
|
21
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'webhook-get'}
|
22
|
+
action.on('-i','--id id','ID') { |o| options[:id] = o}
|
23
|
+
end
|
24
|
+
subcommand.subcommand 'delete' do |action|
|
25
|
+
options[:action] = 'delete'
|
26
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'webhook-delete'}
|
27
|
+
action.on('-i','--id id','ID') { |o| options[:id] = o}
|
28
|
+
end
|
29
|
+
subcommand.subcommand 'create' do |action|
|
30
|
+
options[:action] = 'create'
|
31
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'webhook-create'}
|
32
|
+
action.on('-n','--name name','A user-friendly name for the webhook.') { |o| options[:name] = o}
|
33
|
+
action.on('-u','--targetUrl targetUrl','The URL that receives POST requests for each event.') { |o| options[:targetUrl] = o}
|
34
|
+
action.on('-r','--resource resource','The resource type for the webhook. Creating a webhook requires read scope on the resource the webhook is for.') { |o| options[:resource] = o}
|
35
|
+
action.on('-e','--event event','The event type for the webhook.') { |o| options[:event] = o}
|
36
|
+
action.on('-f','--filter filter','The filter that defines the webhook scope.') { |o| options[:filter] = o}
|
37
|
+
action.on('-s','--secret secret','The secret used to generate payload signature.') { |o| options[:secret] = o}
|
38
|
+
end
|
39
|
+
subcommand.subcommand 'update' do |action|
|
40
|
+
options[:action] = 'update'
|
41
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'webhook-update'}
|
42
|
+
action.on('-n','--name name','A user-friendly name for the webhook.') { |o| options[:name] = o}
|
43
|
+
action.on('-u','--targetUrl targetUrl','The URL that receives POST requests for each event.') { |o| options[:targetUrl] = o}
|
44
|
+
action.on('-s','--secret secret','The secret used to generate payload signature.') { |o| options[:secret] = o}
|
45
|
+
action.on('-t','--status status','The status of the webhook. Use active to reactivate a disabled webhook.') { |o| options[:status] = o}
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
opts.subcommand 'message' do |subcommand|
|
50
|
+
options[:entity] = 'message'
|
51
|
+
subcommand.on('-h','--help','Show help') { |o| options[:help] = 'message'}
|
52
|
+
subcommand.subcommand 'list' do |action|
|
53
|
+
options[:action] = 'list'
|
54
|
+
action.on('-r','--roomId roomId ','List messages for a room, by ID') { |o| options[:roomId] = o}
|
55
|
+
action.on('-p','--mentionedPeople mentionedPeople','List messages where the caller is mentioned by specifying "me" or the caller personId') { |o| options[:mentionedPeople] = o}
|
56
|
+
action.on('-b','--before before ','List messages before a sent time in ISO8601 format') { |o| options[:before] = o}
|
57
|
+
action.on('-b','--beforeMessage beforeMessage ','List messages before a message, by ID') { |o| options[:beforeMessage] = o}
|
58
|
+
end
|
59
|
+
subcommand.subcommand 'get' do |action|
|
60
|
+
options[:action] = 'get'
|
61
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'message-get'}
|
62
|
+
action.on('-i','--id id','ID') { |o| options[:id] = o}
|
63
|
+
end
|
64
|
+
subcommand.subcommand 'delete' do |action|
|
65
|
+
options[:action] = 'delete'
|
66
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'message-delete'}
|
67
|
+
action.on('-i','--id id','ID') { |o| options[:id] = o}
|
68
|
+
end
|
69
|
+
subcommand.subcommand 'create' do |action|
|
70
|
+
options[:action] = 'create'
|
71
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'message-create'}
|
72
|
+
action.on('-r','--roomId roomId','The room ID') { |o| options[:roomId] = o}
|
73
|
+
action.on('-p','--toPersonId toPersonId','The ID of the recipient when sending a private 1:1 message') { |o| options[:toPersonId] = o}
|
74
|
+
action.on('-e','--toPersonEmail toPersonEmail','The ID of the recipient when sending a private 1:1 message') { |o| options[:toPersonEmail] = o}
|
75
|
+
action.on('-m','--markdown markdown','The message, in markdown format') { |o| options[:markdown] = o}
|
76
|
+
action.on('-t','--text text','The message, in text format') { |o| options[:text] = o}
|
77
|
+
action.on('-f','--files files','The public URL to a file to be posted in the room') { |o| options[:files] = o}
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
opts.subcommand 'teammembership' do |subcommand|
|
82
|
+
options[:entity] = 'teammembership'
|
83
|
+
subcommand.on('-h','--help','Show help') { |o| options[:help] = 'teammembership'}
|
84
|
+
subcommand.subcommand 'list' do |action|
|
85
|
+
options[:action] = 'list'
|
86
|
+
action.on('-t','--teamId teamId ','List team memberships for a team, by ID') { |o| options[:teamId] = o}
|
87
|
+
end
|
88
|
+
subcommand.subcommand 'get' do |action|
|
89
|
+
options[:action] = 'get'
|
90
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'teammembership-get'}
|
91
|
+
action.on('-i','--id id','ID') { |o| options[:id] = o}
|
92
|
+
end
|
93
|
+
subcommand.subcommand 'update' do |action|
|
94
|
+
options[:action] = 'update'
|
95
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'teammembership-update'}
|
96
|
+
action.on('-i','--id id','ID') { |o| options[:id] = o}
|
97
|
+
action.on('-m','--isModerator isModerator','Set true to make the person a moderator') { |o| options[:isModerator] = o}
|
98
|
+
end
|
99
|
+
|
100
|
+
subcommand.subcommand 'delete' do |action|
|
101
|
+
options[:action] = 'delete'
|
102
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'teammembership-delete'}
|
103
|
+
action.on('-i','--id id','ID') { |o| options[:id] = o}
|
104
|
+
end
|
105
|
+
subcommand.subcommand 'create' do |action|
|
106
|
+
options[:action] = 'create'
|
107
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'teammembership-create'}
|
108
|
+
action.on('-t','--teamId teamId ','List team memberships for a team, by ID') { |o| options[:teamId] = o}
|
109
|
+
action.on('-p','--personId personId','The person ID') { |o| options[:personId] = o}
|
110
|
+
action.on('-e','--personEmail personEmail','The person email') { |o| options[:personEmail] = o}
|
111
|
+
action.on('-m','--isModerator isModerator','Set to true to make the person a moderator') { |o| options[:isModerator] = o}
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
opts.subcommand 'membership' do |subcommand|
|
117
|
+
options[:entity] = 'membership'
|
118
|
+
subcommand.on('-h','--help','Show help') { |o| options[:help] = 'membership'}
|
119
|
+
subcommand.subcommand 'list' do |action|
|
120
|
+
options[:action] = 'list'
|
121
|
+
action.on('-e','--personEmail personEmail','Email address') { |o| options[:personEmail] = o}
|
122
|
+
action.on('-r','--roomId roomId ','Display name') { |o| options[:roomId] = o}
|
123
|
+
action.on('-p','--personId personId','Person ID') { |o| options[:personId] = o}
|
124
|
+
end
|
125
|
+
subcommand.subcommand 'get' do |action|
|
126
|
+
options[:action] = 'get'
|
127
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'membership-get'}
|
128
|
+
action.on('-i','--id id','ID') { |o| options[:id] = o}
|
129
|
+
end
|
130
|
+
subcommand.subcommand 'delete' do |action|
|
131
|
+
options[:action] = 'delete'
|
132
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'membership-delete'}
|
133
|
+
action.on('-i','--id id','ID') { |o| options[:id] = o}
|
134
|
+
end
|
135
|
+
subcommand.subcommand 'update' do |action|
|
136
|
+
options[:action] = 'update'
|
137
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'membership-update'}
|
138
|
+
action.on('-i','--id id','ID') { |o| options[:id] = o}
|
139
|
+
action.on('-m','--isModerator isModerator','Set true to make the person a moderator') { |o| options[:isModerator] = o}
|
140
|
+
end
|
141
|
+
subcommand.subcommand 'create' do |action|
|
142
|
+
options[:action] = 'create'
|
143
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'membership-create'}
|
144
|
+
action.on('-r','--roomId roomId','The room ID') { |o| options[:roomId] = o}
|
145
|
+
action.on('-p','--personId personId','The person ID') { |o| options[:personId] = o}
|
146
|
+
action.on('-e','--personEmail personEmail','The email address of the person') { |o| options[:personEmail] = o}
|
147
|
+
action.on('-m','--isModerator isModerator','Set true to make the person a moderator') { |o| options[:isModerator] = o}
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
opts.subcommand 'people' do |subcommand|
|
152
|
+
options[:entity] = 'people'
|
153
|
+
subcommand.on('-h','--help','Show help') { |o| options[:help] = 'people'}
|
154
|
+
subcommand.subcommand 'list' do |action|
|
155
|
+
options[:action] = 'list'
|
156
|
+
action.on('-e','--email email','Email address') { |o| options[:email] = o}
|
157
|
+
action.on('-d','--displayName displayName ','Display name') { |o| options[:displayName] = o}
|
158
|
+
action.on('-i','--id id','ID') { |o| options[:id] = o}
|
159
|
+
action.on('-o','--orgId orgId','orgid') { |o| options[:orgId] = o}
|
160
|
+
|
161
|
+
end
|
162
|
+
subcommand.subcommand 'get' do |action|
|
163
|
+
options[:action] = 'get'
|
164
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'people-get'}
|
165
|
+
action.on('-i','--id id','ID') { |o| options[:id] = o}
|
166
|
+
end
|
167
|
+
subcommand.subcommand 'delete' do |action|
|
168
|
+
options[:action] = 'get'
|
169
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'people-delete'}
|
170
|
+
action.on('-i','--id id','ID') { |o| options[:id] = o}
|
171
|
+
end
|
172
|
+
subcommand.subcommand 'create' do |action|
|
173
|
+
options[:action] = 'get'
|
174
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'people-create'}
|
175
|
+
action.on('-e','--email email','ID') { |o| options[:email] = o}
|
176
|
+
end
|
177
|
+
subcommand.subcommand 'update' do |action|
|
178
|
+
options[:action] = 'update'
|
179
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'people-update'}
|
180
|
+
action.on('-i','--id id','ID') { |o| options[:id] = o}
|
181
|
+
action.on('-e','--email email','email') { |o| options[:email] = o}
|
182
|
+
action.on('-d','--displayName displayName','Full name of the person') { |o| options[:displayName] = o}
|
183
|
+
action.on('-f','--firstName firstName','First name of the person') { |o| options[:firstName] = o}
|
184
|
+
action.on('-l','--lastName lastName','Last name of the person') { |o| options[:lastName] = o}
|
185
|
+
action.on('-a','--avatar avatar','URL to persons avatar in PNG format') { |o| options[:avatar] = o}
|
186
|
+
action.on('-o','--orgId orgId','ID of the organization to which the person belongs') { |o| options[:orgId] = o}
|
187
|
+
action.on('-r','--roles roles','Roles of the person') { |o| options[:roles] = o}
|
188
|
+
action.on('-c','--licenses licenses','Licenses allocated to the person') { |o| options[:licenses] = o}
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
192
|
+
opts.subcommand 'team' do |subcommand|
|
193
|
+
options[:entity] = 'team'
|
194
|
+
subcommand.on('-h','--help','Show help') { |o| options[:help] = 'team'}
|
195
|
+
subcommand.subcommand 'list' do |action|
|
196
|
+
options[:action] = 'list'
|
197
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'team-list'}
|
198
|
+
end
|
199
|
+
subcommand.subcommand 'get' do |action|
|
200
|
+
options[:action] = 'get'
|
201
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'team-get'}
|
202
|
+
action.on('-i','--id id','ID') { |o| options[:id] = o}
|
203
|
+
end
|
204
|
+
end
|
205
|
+
opts.subcommand 'room' do |subcommand|
|
206
|
+
options[:entity] = 'room'
|
207
|
+
subcommand.on('-h','--help','Show help') { |o| options[:help] = 'room'}
|
208
|
+
subcommand.subcommand 'list' do |action|
|
209
|
+
options[:action] = 'list'
|
210
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'room-list'}
|
211
|
+
action.on('-t','--type type','type direct or group') { |o| options[:type] = o}
|
212
|
+
action.on('-m','--teamId teamId','team ID') { |o| options[:teamId] = o}
|
213
|
+
|
214
|
+
end
|
215
|
+
subcommand.subcommand 'create' do |action|
|
216
|
+
options[:action] = 'create'
|
217
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'room-create'}
|
218
|
+
action.on('-i','--id id','ID') { |o| options[:id] = o}
|
219
|
+
action.on('-t', '--title title','Title') { |o| options[:title] = o}
|
220
|
+
end
|
221
|
+
subcommand.subcommand 'update' do |action|
|
222
|
+
options[:action] = 'update'
|
223
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'room-update'}
|
224
|
+
action.on('-i','--id id','ID') { |o| options[:id] = o}
|
225
|
+
action.on('-t', '--title title','Title') { |o| options[:title] = o}
|
226
|
+
end
|
227
|
+
subcommand.subcommand 'get' do |action|
|
228
|
+
options[:action] = 'get'
|
229
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'room-get'}
|
230
|
+
action.on('-i','--id id','ID') { |o| options[:id] = o}
|
231
|
+
end
|
232
|
+
subcommand.subcommand 'delete' do |action|
|
233
|
+
options[:action] = 'delete'
|
234
|
+
action.on('-h','--help','Show help') { |o| options[:help] = 'room-delete'}
|
235
|
+
action.on('-i','--id id','ID') { |o| options[:id] = o}
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
parser.parse!
|
240
|
+
|
241
|
+
puts "#{help[options[:help]]}" if options[:help]
|
242
|
+
# puts "options=#{options}"
|
243
|
+
Spark::Configure()
|
244
|
+
case options[:entity]
|
245
|
+
when 'room'
|
246
|
+
case options[:action]
|
247
|
+
when 'list'
|
248
|
+
params = {}
|
249
|
+
[:teamId, :type].each { |k| params[k] = options[k] if options[k] }
|
250
|
+
rooms = Spark::Rooms::List(params)
|
251
|
+
rooms.each { |r| printf "%-80s %s\n", r.id, r.title }
|
252
|
+
when 'get'
|
253
|
+
raise "Specify room ID with --id" unless options[:id]
|
254
|
+
room = Spark::Room::Get(options[:id])
|
255
|
+
room.instance_variables.each { |k| printf "%-25s %s\n", k,room[k.to_s.sub('@','')] }
|
256
|
+
when 'delete'
|
257
|
+
raise "Specify room ID with --id" unless options[:id]
|
258
|
+
room = Spark::Room::Get(options[:id])
|
259
|
+
room.delete()
|
260
|
+
when 'create'
|
261
|
+
teamid = options[:teamid] || nil
|
262
|
+
raise "Creating a room must specify a title" unless options[:title]
|
263
|
+
room = Spark::Room::Create(options[:title], teamid)
|
264
|
+
when 'update'
|
265
|
+
raise "Specify room ID with --id" unless options[:id]
|
266
|
+
raise "Creating a room must specify a title" unless options[:title]
|
267
|
+
room = Spark::Room::Get(options[:id])
|
268
|
+
room.title = options[:title]
|
269
|
+
room.update()
|
270
|
+
end
|
271
|
+
when 'team'
|
272
|
+
case options[:action]
|
273
|
+
when 'list'
|
274
|
+
teams = Spark::Teams::List()
|
275
|
+
teams.each { |t| printf "%-80s %s\n", t.id, t.name }
|
276
|
+
when 'get'
|
277
|
+
raise "Specify team ID with --id" unless options[:id]
|
278
|
+
team = Spark::Team::Get(options[:id])
|
279
|
+
team.instance_variables.each { |k| printf "%-25s %s\n", k,team[k.to_s.sub('@','')] }
|
280
|
+
end
|
281
|
+
#TODO: create, update, delete
|
282
|
+
when 'people'
|
283
|
+
case options[:action]
|
284
|
+
when 'list'
|
285
|
+
params = {}
|
286
|
+
[:email, :displayName, :id, :orgId].each { |k| params[k] = options[k] if options[k] }
|
287
|
+
raise "Must specify -id, -disaplyname or -email must be specified" if params.empty?
|
288
|
+
people = Spark::People::List(params)
|
289
|
+
people.each { |p| printf "%-80s %-25s %s\n", p.id, p.displayName, p.emails}
|
290
|
+
when 'get'
|
291
|
+
raise "Specify person ID with --id" unless options[:id]
|
292
|
+
person = Spark::Person::Get(options[:id])
|
293
|
+
person.instance_variables.each { |k| printf "%-25s %s\n", k,person[k.to_s.sub('@','')] }
|
294
|
+
when 'update'
|
295
|
+
raise "Specify person ID with --id" unless options[:id]
|
296
|
+
payload = {}
|
297
|
+
[:emails, :displayName, :firstName, :lastName, :avatar, :orgId, :roles, :licenses].each { |k| payload[k] = options[k] if options[k] }
|
298
|
+
person = Spark::Person::Get(options[:id])
|
299
|
+
person.update(payload)
|
300
|
+
when 'create'
|
301
|
+
raise "Specify one or more email addresses with --email" unless options[:email]
|
302
|
+
person = Spark::Person::Create(options[:email])
|
303
|
+
when 'delete'
|
304
|
+
raise "Specify person ID with --id" unless options[:id]
|
305
|
+
person = Spark::Person::Get(options[:id])
|
306
|
+
person.delete()
|
307
|
+
end
|
308
|
+
when 'membership'
|
309
|
+
case options[:action]
|
310
|
+
when 'list'
|
311
|
+
params = {}
|
312
|
+
[:personEmail, :roomId, :personId].each { |k| params[k] = options[k] if options[k] }
|
313
|
+
raise "-personEmail, -roomId or -personId must be specified" if params.empty?
|
314
|
+
memberships = Spark::Memberships::List(params)
|
315
|
+
memberships.each { |m| printf "%-80s %-80s %-80s %s\n", m.id, m.roomId, m.personId, m.personEmail}
|
316
|
+
when 'get'
|
317
|
+
raise "Specify membership ID with --id" unless options[:id]
|
318
|
+
membership = Spark::Membership::Get(options[:id])
|
319
|
+
membership.instance_variables.each { |k| printf "%-25s %s\n", k,membership[k.to_s.sub('@','')] }
|
320
|
+
when 'create'
|
321
|
+
raise "Specify room ID with --roomid" unless options[:roomId]
|
322
|
+
params = {}
|
323
|
+
[:personId, :personEmail, :isModerator].each { |k| params[k] = options[k] if options[k] }
|
324
|
+
membership = Spark::Membership::Create(options[:roomId],params)
|
325
|
+
membership.instance_variables.each { |k| printf "%-25s %s\n", k,membership[k.to_s.sub('@','')] }
|
326
|
+
when 'update'
|
327
|
+
raise "Specify membership ID with --id" unless options[:id]
|
328
|
+
payload = {}
|
329
|
+
[:isModerator].each { |k| payload[k] = options[k] if options[k] }
|
330
|
+
membership = Spark::Membership::Get(options[:id])
|
331
|
+
membership.update(payload)
|
332
|
+
when 'delete'
|
333
|
+
raise "Specify membership ID with --id" unless options[:id]
|
334
|
+
membership = Spark::Membership::Get(options[:id])
|
335
|
+
membership.delete()
|
336
|
+
end
|
337
|
+
when 'message'
|
338
|
+
case options[:action]
|
339
|
+
when 'list'
|
340
|
+
params = {}
|
341
|
+
[:before, :roomId, :mentionedPeople, :beforeMessage].each { |k| params[k] = options[k] if options[k] }
|
342
|
+
raise "--roomId must be specified" unless options[:roomId]
|
343
|
+
messages = Spark::Messages::List(params)
|
344
|
+
messages.each { |m| printf "%-80s %-28s %-30s %s\n", m.id, m.created, m.personEmail, m.text}
|
345
|
+
when 'get'
|
346
|
+
raise "Specify message ID with --id" unless options[:id]
|
347
|
+
message = Spark::Message::Get(options[:id])
|
348
|
+
message.instance_variables.each { |k| printf "%-25s %s\n", k,message[k.to_s.sub('@','')] }
|
349
|
+
when 'create'
|
350
|
+
raise "Specify room ID with --roomid" unless options[:roomId]
|
351
|
+
params = {}
|
352
|
+
[:toPersonId, :toPersonEmail, :text, :markdown, :files].each { |k| params[k] = options[k] if options[k] }
|
353
|
+
message = Spark::Message::Create(options[:roomId], params)
|
354
|
+
message.instance_variables.each { |k| printf "%-25s %s\n", k,message[k.to_s.sub('@','')] }
|
355
|
+
when 'delete'
|
356
|
+
raise "Specify message ID with --id" unless options[:id]
|
357
|
+
message = Spark::Message::Get(options[:id])
|
358
|
+
message.delete()
|
359
|
+
end
|
360
|
+
when 'teammembership'
|
361
|
+
case options[:action]
|
362
|
+
when 'list'
|
363
|
+
params = {}
|
364
|
+
[:personEmail, :roomId, :personId].each { |k| params[k] = options[k] if options[k] }
|
365
|
+
raise "-personEmail, -roomId or -personId must be specified" if params.empty?
|
366
|
+
teammemberships = Spark::TeamMemberships::List(params)
|
367
|
+
teammemberships.each { |m| printf "%-80s %-80s %-80s %s\n", m.id, m.roomId, m.personId, m.personEmail}
|
368
|
+
when 'get'
|
369
|
+
raise "Specify teammembership ID with --id" unless options[:id]
|
370
|
+
teammembership = Spark::TeamMembership::Get(options[:id])
|
371
|
+
teammembership.instance_variables.each { |k| printf "%-25s %s\n", k,teammembership[k.to_s.sub('@','')] }
|
372
|
+
when 'create'
|
373
|
+
raise "Specify team ID with --teamId" unless options[:roomId]
|
374
|
+
params = {}
|
375
|
+
[:personId, :personEmail, :isModerator].each { |k| params[k] = options[k] if options[k] }
|
376
|
+
teammembership = Spark::TeamMembership::Create(options[:roomId],params)
|
377
|
+
membeteammembershiprship.instance_variables.each { |k| printf "%-25s %s\n", k,teammembership[k.to_s.sub('@','')] }
|
378
|
+
when 'update'
|
379
|
+
raise "Specify teammembership ID with --id" unless options[:id]
|
380
|
+
payload = {}
|
381
|
+
[:isModerator].each { |k| payload[k] = options[k] if options[k] }
|
382
|
+
teammembership = Spark::TeamMembership::Get(options[:id])
|
383
|
+
teammembership.update(payload)
|
384
|
+
when 'delete'
|
385
|
+
raise "Specify teammembership ID with --id" unless options[:id]
|
386
|
+
teammembership = Spark::TeamMembership::Get(options[:id])
|
387
|
+
teammembership.delete()
|
388
|
+
end
|
389
|
+
|
390
|
+
when 'webhook'
|
391
|
+
case options[:action]
|
392
|
+
when 'list'
|
393
|
+
params = {}
|
394
|
+
webhooks = Spark::Webhooks::List(params)
|
395
|
+
webhooks.each { |h| printf "%-80s %-20s %s\n", h.id, h.name, h.targetUrl}
|
396
|
+
when 'get'
|
397
|
+
raise "Specify webhook ID with --id" unless options[:id]
|
398
|
+
webhook = Spark::Webhook::Get(options[:id])
|
399
|
+
webhook.instance_variables.each { |k| printf "%-25s %s\n", k,webhook[k.to_s.sub('@','')] }
|
400
|
+
when 'create'
|
401
|
+
params = {}
|
402
|
+
[:name, :targetUrl, :resource, :event].each { |k| params[k] = options[k] if options[k] }
|
403
|
+
raise "Must specify --name, --targetUrl, --resource, --event" if params.empty?
|
404
|
+
[:filter, :secret].each { |k| params[k] = options[k] if options[k] }
|
405
|
+
webhook = Spark::Webhook::Create(options[:roomId],params)
|
406
|
+
webhook.instance_variables.each { |k| printf "%-25s %s\n", k,webhook[k.to_s.sub('@','')] }
|
407
|
+
when 'update'
|
408
|
+
raise "Specify webhook ID with --id" unless options[:id]
|
409
|
+
payload = {}
|
410
|
+
[:name, :targetUrl, :secret, :status].each { |k| payload[k] = options[k] if options[k] }
|
411
|
+
webhook = Spark::Webhook::Get(options[:id])
|
412
|
+
webhook.update(payload)
|
413
|
+
when 'delete'
|
414
|
+
raise "Specify webhook ID with --id" unless options[:id]
|
415
|
+
webhook = Spark::Webhook::Get(options[:id])
|
416
|
+
webhook.delete()
|
417
|
+
end
|
418
|
+
end
|
data/lib/base.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Spark
|
2
|
+
class Base
|
3
|
+
@api_endpoint = nil
|
4
|
+
@update_fileds = []
|
5
|
+
def initialize(data)
|
6
|
+
self.refresh(data)
|
7
|
+
end
|
8
|
+
def update(data={})
|
9
|
+
data.each {|k,v| public_send("#{k}=",v)}
|
10
|
+
payload = {}
|
11
|
+
@update_fields.each { |k| payload[k] = self[k] }
|
12
|
+
res = Spark::rest('PUT',"/#{@api_endpoint}/#{@id}", {:payload => payload})
|
13
|
+
if res.ok
|
14
|
+
self.refresh(JSON.parse(res.body))
|
15
|
+
return true
|
16
|
+
end
|
17
|
+
return false
|
18
|
+
end
|
19
|
+
def refresh(data)
|
20
|
+
data.each {|k,v| public_send("#{k}=",v)}
|
21
|
+
end
|
22
|
+
def delete()
|
23
|
+
res = Spark::rest('DELETE',"/#{@api_endpoint}/#{@id}")
|
24
|
+
end
|
25
|
+
def [](key)
|
26
|
+
return nil unless respond_to?(key)
|
27
|
+
public_send(key)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
data/lib/cisco-spark-ruby.rb
CHANGED
@@ -0,0 +1,119 @@
|
|
1
|
+
gem 'rest-client', '>2.0.0'
|
2
|
+
require 'rest-client'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
module Spark
|
6
|
+
autoload :Base, "base"
|
7
|
+
autoload :Collection, "collection"
|
8
|
+
|
9
|
+
autoload :Room, "room"
|
10
|
+
autoload :Rooms, "rooms"
|
11
|
+
autoload :Team, "team"
|
12
|
+
autoload :Teams, "teams"
|
13
|
+
autoload :Person, "person"
|
14
|
+
autoload :People, "people"
|
15
|
+
autoload :Memberships, 'memberships'
|
16
|
+
autoload :Membership, 'membership'
|
17
|
+
autoload :Messages, 'messages'
|
18
|
+
autoload :Message, 'message'
|
19
|
+
autoload :TeamMemberships, 'teammemberships'
|
20
|
+
autoload :TeamMembership, 'teammembership'
|
21
|
+
autoload :Webhooks, 'webhooks'
|
22
|
+
autoload :Webhook, 'webhook'
|
23
|
+
@@token = nil
|
24
|
+
@@logger = nil
|
25
|
+
class << self
|
26
|
+
def Configure(_opts = {})
|
27
|
+
@@token = _opts[:token] || ENV['SPARK_TOKEN']
|
28
|
+
@@logger = Logger.new(STDOUT)
|
29
|
+
@@logger.level = Logger::FATAL
|
30
|
+
case _opts[:loglevel]
|
31
|
+
when :debug
|
32
|
+
@@logger.level = Logger::DEBUG
|
33
|
+
when :error
|
34
|
+
@@logger.level = Logger::ERROR
|
35
|
+
when :info
|
36
|
+
@@logger.level = Logger::INFO
|
37
|
+
when :fatal
|
38
|
+
@@logger.level = Logger::FATAL
|
39
|
+
when :warn
|
40
|
+
@@logger.level = Logger::WARN
|
41
|
+
when :unknown
|
42
|
+
@@logger.level = Logger::UKNOWN
|
43
|
+
end
|
44
|
+
end
|
45
|
+
def token
|
46
|
+
return @@token
|
47
|
+
end
|
48
|
+
def headers
|
49
|
+
return {'Content-type'=>'application/json; charset=utf-8', 'Authorization' => "Bearer #{@@token}"}
|
50
|
+
end
|
51
|
+
def Log(message, level = :debug)
|
52
|
+
case level
|
53
|
+
when :debug
|
54
|
+
@@logger.debug(message)
|
55
|
+
when :error
|
56
|
+
@@logger.error(message)
|
57
|
+
when :info
|
58
|
+
@@logger.info(message)
|
59
|
+
when :fatal
|
60
|
+
@@logger.fatal(message)
|
61
|
+
when :warn
|
62
|
+
@@logger.warn(message)
|
63
|
+
when :unknown
|
64
|
+
@@logger.unknown(message)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
def rest(method, uri_stub, _opts = {})
|
68
|
+
url = "https://api.ciscospark.com/v1#{uri_stub}"
|
69
|
+
|
70
|
+
# bolt on query string params if passed
|
71
|
+
if _opts[:params]
|
72
|
+
url = "#{url}?#{URI.encode_www_form(_opts[:params])}" unless _opts[:params].empty?
|
73
|
+
end
|
74
|
+
Spark::Log("REST method=#{method} url=#{url} _opts=#{_opts}", :info)
|
75
|
+
# assmeble the headers
|
76
|
+
headers = Spark::headers
|
77
|
+
headers = headers.merge(_opts[:headers]) if _opts[:headers]
|
78
|
+
|
79
|
+
payload = _opts[:payload] || {}
|
80
|
+
|
81
|
+
out = {}
|
82
|
+
begin
|
83
|
+
rsp = RestClient::Request.execute(
|
84
|
+
method: method,
|
85
|
+
url: url,
|
86
|
+
payload: payload,
|
87
|
+
headers: headers
|
88
|
+
)
|
89
|
+
out[:code] = rsp.code
|
90
|
+
out[:body] = rsp.body
|
91
|
+
out[:object] = rsp
|
92
|
+
rescue RestClient::Exception => e
|
93
|
+
out[:code] = e.http_code
|
94
|
+
out[:body] = e.http_body
|
95
|
+
out[:object] = e
|
96
|
+
end
|
97
|
+
Spark::Log("REST method=#{method} url=#{url} response=#{out[:code]}", :info)
|
98
|
+
Spark::Log("REST body=#{out[:body]}", :debug)
|
99
|
+
Spark::Response.new(out)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
class Response
|
103
|
+
attr_accessor 'code'
|
104
|
+
attr_accessor 'body'
|
105
|
+
attr_accessor 'object'
|
106
|
+
def initialize(_data = {})
|
107
|
+
@code = _data[:code]
|
108
|
+
@body = _data[:body]
|
109
|
+
@object = _data[:object]
|
110
|
+
end
|
111
|
+
def to_s
|
112
|
+
return body
|
113
|
+
end
|
114
|
+
def ok
|
115
|
+
return true if code < 400
|
116
|
+
false
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
data/lib/collection.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Spark
|
2
|
+
class Collection
|
3
|
+
attr_accessor 'items'
|
4
|
+
def initialize(items = [])
|
5
|
+
# we can broke no delay
|
6
|
+
@items = items
|
7
|
+
end
|
8
|
+
def push(item)
|
9
|
+
@items.push(item)
|
10
|
+
end
|
11
|
+
def [](key)
|
12
|
+
@items[key]
|
13
|
+
end
|
14
|
+
def to_s
|
15
|
+
"#{@items}"
|
16
|
+
end
|
17
|
+
def each
|
18
|
+
@items.each { |r| yield r }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
data/lib/membership.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Spark
|
2
|
+
class Membership < Base
|
3
|
+
attr_accessor :id, :roomId, :personId, :personEmail, :personDisplayName, :personOrgId, :isModerator, :isMonitor, :created
|
4
|
+
def initialize(data)
|
5
|
+
# we carry the membership, we can broke no delay
|
6
|
+
@api_endpoint = 'memberships'
|
7
|
+
@update_fields = [:isModerator]
|
8
|
+
super
|
9
|
+
end
|
10
|
+
class << self
|
11
|
+
def Get(id)
|
12
|
+
res = Spark::rest('GET',"/memberships/#{id}")
|
13
|
+
if res.ok
|
14
|
+
membership = Spark::Membership.new(JSON.parse(res.body))
|
15
|
+
return membership
|
16
|
+
end
|
17
|
+
return nil
|
18
|
+
end
|
19
|
+
def Create(roomId, payload={})
|
20
|
+
payload[:roomId] = roomId
|
21
|
+
res = Spark::rest('POST',"/memberships", {:payload => payload})
|
22
|
+
if res.ok
|
23
|
+
membership = Spark::Membership.new(JSON.parse(res.body))
|
24
|
+
return membership
|
25
|
+
end
|
26
|
+
return nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
data/lib/memberships.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spark
|
2
|
+
class Memberships < Collection
|
3
|
+
class << self
|
4
|
+
def List(params = {})
|
5
|
+
out = Spark::Memberships.new()
|
6
|
+
res = Spark::rest('GET','/memberships',{:params => params})
|
7
|
+
if res.ok
|
8
|
+
data = JSON.parse(res.body)
|
9
|
+
data['items'].each do |r|
|
10
|
+
membership = Spark::Membership.new(r)
|
11
|
+
out.push(membership)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
out
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
data/lib/message.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Spark
|
2
|
+
class Message < Base
|
3
|
+
attr_accessor :id, :roomId, :roomType, :text, :personId, :personEmail, :created, :markdown, :html, :mentionedPeople, :files
|
4
|
+
def initialize(data)
|
5
|
+
@api_endpoint = 'messages'
|
6
|
+
@update_fields = []
|
7
|
+
super
|
8
|
+
end
|
9
|
+
class << self
|
10
|
+
def Get(id)
|
11
|
+
res = Spark::rest('GET',"/messages/#{id}")
|
12
|
+
if res.ok
|
13
|
+
message = Spark::Message.new(JSON.parse(res.body))
|
14
|
+
return message
|
15
|
+
end
|
16
|
+
return nil
|
17
|
+
end
|
18
|
+
def Create(roomId, payload={})
|
19
|
+
payload[:roomId] = roomId
|
20
|
+
res = Spark::rest('POST',"/messages", {:payload => payload})
|
21
|
+
if res.ok
|
22
|
+
message = Spark::Message.new(JSON.parse(res.body))
|
23
|
+
return message
|
24
|
+
end
|
25
|
+
return nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
data/lib/messages.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spark
|
2
|
+
class Messages < Collection
|
3
|
+
class << self
|
4
|
+
def List(params = {})
|
5
|
+
out = Spark::Messages.new()
|
6
|
+
res = Spark::rest('GET','/messages',{:params => params})
|
7
|
+
if res.ok
|
8
|
+
data = JSON.parse(res.body)
|
9
|
+
data['items'].each do |r|
|
10
|
+
message = Spark::Message.new(r)
|
11
|
+
out.push(message)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
out
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
data/lib/people.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spark
|
2
|
+
class People < Collection
|
3
|
+
class << self
|
4
|
+
def List(params = {})
|
5
|
+
out = Spark::People.new()
|
6
|
+
res = Spark::rest('GET','/people',{:params => params})
|
7
|
+
if res.ok
|
8
|
+
data = JSON.parse(res.body)
|
9
|
+
data['items'].each do |r|
|
10
|
+
person = Spark::Person.new(r)
|
11
|
+
out.push(person)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
out
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
data/lib/person.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Spark
|
2
|
+
class Person < Base
|
3
|
+
attr_accessor :id, :emails, :displayName, :nickName, :firstName, :lastName, :avatar, :orgId, :created, :lastActivity, :status, :type
|
4
|
+
def initialize(data)
|
5
|
+
@api_endpoint = 'people'
|
6
|
+
@update_fields = [:emails, :displayName, :firstName, :lastName, :avatar, :orgId, :roles, :licenses]
|
7
|
+
super
|
8
|
+
end
|
9
|
+
class << self
|
10
|
+
def Get(id)
|
11
|
+
res = Spark::rest('GET',"/people/#{id}")
|
12
|
+
if res.ok
|
13
|
+
person = Spark::Person.new(JSON.parse(res.body))
|
14
|
+
return person
|
15
|
+
end
|
16
|
+
return nil
|
17
|
+
end
|
18
|
+
def Create(email, payload={})
|
19
|
+
payload[:email] = email
|
20
|
+
res = Spark::rest('POST',"/people", {:payload => payload})
|
21
|
+
if res.ok
|
22
|
+
person = Spark::Person.new(JSON.parse(res.body))
|
23
|
+
return person
|
24
|
+
end
|
25
|
+
return nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/room.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module Spark
|
2
|
+
class Room < Base
|
3
|
+
attr_accessor :id, :title, :type, :isLocked, :lastActivity, :creatorId, :created, :teamId, :sipAddress, :errors
|
4
|
+
def initialize(data)
|
5
|
+
@api_endpoint = 'rooms'
|
6
|
+
@update_fields = [:title]
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def Get(id)
|
12
|
+
res = Spark::rest('GET',"/rooms/#{id}")
|
13
|
+
if res.ok
|
14
|
+
room = Spark::Room.new(JSON.parse(res.body))
|
15
|
+
return room
|
16
|
+
end
|
17
|
+
return nil
|
18
|
+
end
|
19
|
+
def Create(title, teamId = nil)
|
20
|
+
payload = {}
|
21
|
+
payload[:title] = title
|
22
|
+
payload[:teamId] = teamId if teamId
|
23
|
+
res = Spark::rest('POST',"/rooms", {:payload => payload})
|
24
|
+
if res.ok
|
25
|
+
room = Spark::Room.new(JSON.parse(res.body))
|
26
|
+
return room
|
27
|
+
end
|
28
|
+
return nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/rooms.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Spark
|
2
|
+
class Rooms < Spark::Collection
|
3
|
+
class << self
|
4
|
+
def List(params = {})
|
5
|
+
out = Spark::Rooms.new()
|
6
|
+
if params[:sortBy]
|
7
|
+
valid = ['id','lastactivity','created']
|
8
|
+
raise "Valid sortBy values for List are #{valid} given #{params[:sortBy]}" unless valid.include? params[:sortBy]
|
9
|
+
end
|
10
|
+
rsp = Spark::rest('GET','/rooms',{:params => params})
|
11
|
+
if rsp.ok
|
12
|
+
data = JSON.parse(rsp.body)
|
13
|
+
data['items'].each do |r|
|
14
|
+
room = Spark::Room.new(r)
|
15
|
+
out.push(room)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
out
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
data/lib/team.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Spark
|
2
|
+
class Team < Base
|
3
|
+
attr_accessor :id, :name, :creatorId, :created
|
4
|
+
def initialize(data)
|
5
|
+
@api_endpoint = 'teams'
|
6
|
+
@update_fields = [:name]
|
7
|
+
super
|
8
|
+
end
|
9
|
+
class << self
|
10
|
+
def Get(id)
|
11
|
+
res = Spark::rest('GET',"/teams/#{id}")
|
12
|
+
if res.ok
|
13
|
+
team = Spark::Team.new(JSON.parse(res.body))
|
14
|
+
return team
|
15
|
+
end
|
16
|
+
return nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Spark
|
2
|
+
class TeamMembership < Base
|
3
|
+
attr_accessor :id, :teamId, :personId, :personEmail, :personDisplayName, :personOrgId, :isModerator, :created
|
4
|
+
def initialize(data)
|
5
|
+
# we carry the membership, we can broke no delay
|
6
|
+
@api_endpoint = 'team/memberships'
|
7
|
+
@update_fields = [:isModerator]
|
8
|
+
super
|
9
|
+
end
|
10
|
+
class << self
|
11
|
+
def Get(id)
|
12
|
+
res = Spark::rest('GET',"/team/memberships/#{id}")
|
13
|
+
if res.ok
|
14
|
+
teammembership = Spark::TeamMembership.new(JSON.parse(res.body))
|
15
|
+
return teammembership
|
16
|
+
end
|
17
|
+
return nil
|
18
|
+
end
|
19
|
+
def Create(roomId, payload={})
|
20
|
+
payload[:roomId] = roomId
|
21
|
+
res = Spark::rest('POST',"/team/memberships", {:payload => payload})
|
22
|
+
if res.ok
|
23
|
+
teammembership = Spark::TeamMembership.new(JSON.parse(res.body))
|
24
|
+
return teammembership
|
25
|
+
end
|
26
|
+
return nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spark
|
2
|
+
class TeamMemberships < Collection
|
3
|
+
class << self
|
4
|
+
def List(params = {})
|
5
|
+
out = Spark::TeamMemberships.new()
|
6
|
+
res = Spark::rest('GET','/team/memberships',{:params => params})
|
7
|
+
if res.ok
|
8
|
+
data = JSON.parse(res.body)
|
9
|
+
data['items'].each do |r|
|
10
|
+
teammembership = Spark::TeamMembership.new(r)
|
11
|
+
out.push(teammembership)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
out
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
data/lib/teams.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spark
|
2
|
+
class Teams < Collection
|
3
|
+
class << self
|
4
|
+
def List(params = {})
|
5
|
+
out = Spark::Teams.new()
|
6
|
+
res = Spark::rest('GET','/teams',{:params => params})
|
7
|
+
if res.ok
|
8
|
+
data = JSON.parse(res.body)
|
9
|
+
data['items'].each do |r|
|
10
|
+
team = Spark::Team.new(r)
|
11
|
+
out.push(team)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
out
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
data/lib/webhook.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Spark
|
2
|
+
class Webhook < Base
|
3
|
+
attr_accessor :id, :name, :targetUrl, :resource, :event, :filter, :secret, :status, :created, :orgId, :createdBy, :appId, :ownedBy
|
4
|
+
def initialize(data)
|
5
|
+
@api_endpoint = 'webhooks'
|
6
|
+
@update_fields = [:name]
|
7
|
+
super
|
8
|
+
end
|
9
|
+
class << self
|
10
|
+
def Get(id)
|
11
|
+
res = Spark::rest('GET',"/webhooks/#{id}")
|
12
|
+
if res.ok
|
13
|
+
webhook = Spark::Webhook.new(JSON.parse(res.body))
|
14
|
+
return webhook
|
15
|
+
end
|
16
|
+
return nil
|
17
|
+
end
|
18
|
+
def Create(payload={})
|
19
|
+
res = Spark::rest('POST',"/webhooks", {:payload => payload})
|
20
|
+
if res.ok
|
21
|
+
webhook = Spark::Webhook.new(JSON.parse(res.body))
|
22
|
+
return webhook
|
23
|
+
end
|
24
|
+
return nil
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/webhooks.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Spark
|
2
|
+
class Webhooks < Collection
|
3
|
+
class << self
|
4
|
+
def List(params = {})
|
5
|
+
out = Spark::Webhooks.new()
|
6
|
+
res = Spark::rest('GET','/webhooks',{:params => params})
|
7
|
+
if res.ok
|
8
|
+
data = JSON.parse(res.body)
|
9
|
+
data['items'].each do |r|
|
10
|
+
webhook = Spark::Webhook.new(r)
|
11
|
+
out.push(webhook)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
out
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cisco-spark-ruby
|
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
|
- Robert Labrie
|
@@ -12,11 +12,29 @@ date: 2017-10-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
13
13
|
description: Cisco spark ruby
|
14
14
|
email: rolabrie@cisco.com
|
15
|
-
executables:
|
15
|
+
executables:
|
16
|
+
- ciscospark
|
16
17
|
extensions: []
|
17
18
|
extra_rdoc_files: []
|
18
19
|
files:
|
20
|
+
- bin/ciscospark
|
21
|
+
- lib/base.rb
|
19
22
|
- lib/cisco-spark-ruby.rb
|
23
|
+
- lib/collection.rb
|
24
|
+
- lib/membership.rb
|
25
|
+
- lib/memberships.rb
|
26
|
+
- lib/message.rb
|
27
|
+
- lib/messages.rb
|
28
|
+
- lib/people.rb
|
29
|
+
- lib/person.rb
|
30
|
+
- lib/room.rb
|
31
|
+
- lib/rooms.rb
|
32
|
+
- lib/team.rb
|
33
|
+
- lib/teammembership.rb
|
34
|
+
- lib/teammemberships.rb
|
35
|
+
- lib/teams.rb
|
36
|
+
- lib/webhook.rb
|
37
|
+
- lib/webhooks.rb
|
20
38
|
homepage:
|
21
39
|
licenses: []
|
22
40
|
metadata: {}
|
@@ -24,6 +42,7 @@ post_install_message:
|
|
24
42
|
rdoc_options: []
|
25
43
|
require_paths:
|
26
44
|
- lib
|
45
|
+
- bin
|
27
46
|
required_ruby_version: !ruby/object:Gem::Requirement
|
28
47
|
requirements:
|
29
48
|
- - ">="
|
@@ -39,5 +58,5 @@ rubyforge_project:
|
|
39
58
|
rubygems_version: 2.5.1
|
40
59
|
signing_key:
|
41
60
|
specification_version: 3
|
42
|
-
summary: Cisco spark ruby
|
61
|
+
summary: Cisco spark ruby - broken, under active development
|
43
62
|
test_files: []
|