Class: App42::Social::SocialService

Inherits:
Object
  • Object
show all
Defined in:
lib/social/SocialService.rb

Overview

Connect to the User’s multiple social accounts. Also used to update the status individually or all at once for the linked social accounts.

Instance Method Summary collapse

Constructor Details

#initialize(api_key, secret_key, base_url) ⇒ SocialService

this is a constructor that takes

Parameters:

  • apiKey
  • secretKey
  • baseURL


27
28
29
30
31
32
33
34
# File 'lib/social/SocialService.rb', line 27

def initialize(api_key, secret_key, base_url)
  puts "Social Service->initialize"
  @api_key = api_key
  @secret_key = secret_key
  @base_url = base_url
  @resource = "social"
  @version = "1.0"
end

Instance Method Details

Returns The Social object.

Parameters:

  • userName
    • Name of the user whose Facebook account to be linked

  • appId
    • Facebook App Id

  • appSecret
    • Facebook App Secret

  • accessToken
    • Facebook Access Token that has been received after authorization

Returns:

  • The Social object

Raises:

  • App42Exception



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/social/SocialService.rb', line 53

def (userName, accessToken, appId, appSecret)
  response = nil
  socialObj = Social.new
  socialObj = nil
  util = Util.new
  util.throwExceptionIfNullOrBlank(userName, "userName")
  util.throwExceptionIfNullOrBlank(accessToken, "accessToken")
  util.throwExceptionIfNullOrBlank(appId, "appId")
  util.throwExceptionIfNullOrBlank(appSecret, "appSecret")
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    body = {'app42' => {"social"=> {
      "userName" => userName,
      "accessToken" => accessToken,
      "appId" => appId,
      "appSecret" => appSecret
      }}}.to_json
    puts "Body #{body}"
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("body", body)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/facebook/linkuser"
    response = connection.post(signature, resource_url, query_params, body)
    social = SocialResponseBuilder.new()
    socialObj = social.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return socialObj
end

Links the User Facebook access credentials to the App User account.

Parameters:

  • userName
    • Name of the user whose Facebook account to be linked

  • accessToken
    • Facebook Access Token that has been received after authorization

Returns:

  • The Social object

Raises:

  • App42Exception



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/social/SocialService.rb', line 106

def (userName, accessToken)
  response = nil
  socialObj = Social.new
  socialObj = nil
  util = Util.new
  util.throwExceptionIfNullOrBlank(userName, "userName")
  util.throwExceptionIfNullOrBlank(accessToken, "accessToken")
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    body = {'app42' => {"social"=> {
      "userName" => userName,
      "accessToken" => accessToken
      }}}.to_json
    puts "Body #{body}"
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("body", body)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/facebook/linkuser/accesscredentials"
    response = connection.post(signature, resource_url, query_params, body)
    social = SocialResponseBuilder.new()
    socialObj = social.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return socialObj
end

Links the User LinkedIn access credentials to the App User account.

@param userName
   - Name of the user whose LinkedIn account to be linked
@param apiKey
   - LinkedIn App API Key
@param secretKey
   - LinkedIn App Secret Key
@param accessToken
   - LinkedIn Access Token that has been received after authorization
@param accessTokenSecret
   - LinkedIn Access Token Secret that has been received after authorization

@return The Social object

@raise App42Exception


381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/social/SocialService.rb', line 381

def (userName, accessToken, accessTokenSecret, apiKey, secretKey)
  puts "linkUserLinkedInAccount Called "
  puts "Base url #{@base_url}"
  response = nil
  social = Social.new
  social = nil
  util = Util.new
  util.throwExceptionIfNullOrBlank(userName, "userName")
  util.throwExceptionIfNullOrBlank(accessToken, "accessToken")
  util.throwExceptionIfNullOrBlank(accessTokenSecret, "accessTokenSecret")
  util.throwExceptionIfNullOrBlank(apiKey, "apiKey")
  util.throwExceptionIfNullOrBlank(secretKey, "secretKey")
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    body = {'app42' => {"social"=> {
      "userName" => userName,
      "accessToken" => accessToken,
      "accessTokenSecret" => accessTokenSecret,
      "apiKey" => apiKey,
      "secretKey" => secretKey
      }}}.to_json
    puts "Body #{body}"
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("body", body)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/linkedin/linkuser"
    response = connection.post(signature, resource_url, query_params, body)
    social = SocialResponseBuilder.new()
    socialObj = social.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return socialObj
end

Links the User LinkedIn access credentials to the App User account.

Parameters:

  • userName
    • Name of the user whose LinkedIn account to be linked

  • accessToken
    • LinkedIn Access Token that has been received after authorization

  • accessTokenSecret
    • LinkedIn Access Token Secret that has been received after authorization

Returns:

  • The Social object

Raises:

  • App42Exception



440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
# File 'lib/social/SocialService.rb', line 440

def (userName, accessToken, accessTokenSecret)
  puts "linkUserLinkedInAccount Called "
  puts "Base url #{@base_url}"
  response = nil
  social = Social.new
  social = nil
  util = Util.new
  util.throwExceptionIfNullOrBlank(userName, "userName")
  util.throwExceptionIfNullOrBlank(accessToken, "accessToken")
  util.throwExceptionIfNullOrBlank(accessTokenSecret, "accessTokenSecret")
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    body = {'app42' => {"social"=> {
      "userName" => userName,
      "accessToken" => accessToken,
      "accessTokenSecret" => accessTokenSecret
      }}}.to_json
    puts "Body #{body}"
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("body", body)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/linkedin/linkuser/accesscredentials"
    response = connection.post(signature, resource_url, query_params, body)
    social = SocialResponseBuilder.new()
    socialObj = social.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return socialObj
end

Links the User Twitter access credentials to the App User account.

Parameters:

  • userName
    • Name of the user whose Twitter account to be linked

  • consumerKey
    • Twitter App Consumer Key

  • consumerSecret
    • Twitter App Consumer Secret

  • accessToken
    • Request Token retrieved from Twitter after authorizing the App

  • accessTokenSecret
    • Request Token Secret retrieved from Twitter after authorizing the App

Returns:

  • the Social object

Raises:

  • App42Exception



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/social/SocialService.rb', line 212

def (userName, accessToken, accessTokenSecret, consumerKey, consumerSecret)
  puts "linkUserTwitterAccount Called "
  puts "Base url #{@base_url}"
  response = nil
  social = Social.new
  social = nil
  util = Util.new
  util.throwExceptionIfNullOrBlank(userName, "userName")
  util.throwExceptionIfNullOrBlank(accessToken, "accessToken")
  util.throwExceptionIfNullOrBlank(accessTokenSecret, "accessTokenSecret")
  util.throwExceptionIfNullOrBlank(consumerKey, "consumerKey")
  util.throwExceptionIfNullOrBlank(consumerSecret, "consumerSecret")
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    body = {'app42' => {"social"=> {
      "userName" => userName,
      "accessToken" => accessToken,
      "accessTokenSecret" => accessTokenSecret,
      "consumerKey" => consumerKey,
      "consumerSecret" => consumerSecret
      }}}.to_json
    puts "Body #{body}"
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("body", body)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/twitter/linkuser"
    response = connection.post(signature, resource_url, query_params, body)
    social = SocialResponseBuilder.new()
    socialObj = social.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return socialObj
end

Links the User Twitter access credentials to the App User account.

Parameters:

  • userName
    • Name of the user whose Twitter account to be linked

  • accessToken
    • Request Token retrieved from Twitter after authorizing the App

  • accessTokenSecret
    • Request Token Secret retrieved from Twitter after authorizing the App

Returns:

  • the Social object

Raises:

  • App42Exception



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/social/SocialService.rb', line 271

def (userName, accessToken, accessTokenSecret)
  puts "linkUserTwitterAccount Called "
  puts "Base url #{@base_url}"
  response = nil
  social = Social.new
  social = nil
  util = Util.new
  util.throwExceptionIfNullOrBlank(userName, "userName")
  util.throwExceptionIfNullOrBlank(accessToken, "accessToken")
  util.throwExceptionIfNullOrBlank(accessTokenSecret, "accessTokenSecret")
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    body = {'app42' => {"social"=> {
      "userName" => userName,
      "accessToken" => accessToken,
      "accessTokenSecret" => accessTokenSecret
      }}}.to_json
    puts "Body #{body}"
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("body", body)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/twitter/linkuser/accesscredentials"
    response = connection.post(signature, resource_url, query_params, body)
    social = SocialResponseBuilder.new()
    socialObj = social.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return socialObj
end

#update_facebook_status(userName, status) ⇒ Object

Updates the Facebook status of the specified user.

Parameters:

  • userName
    • Name of the user for whom the status needs to be updated

  • status
    • status that has to be updated

Returns:

  • The Social object

Raises:

  • App42Exception



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/social/SocialService.rb', line 155

def update_facebook_status(userName,status)
  puts "update Status Called "
  puts "Base url #{@base_url}"
  response = nil;
  socialObj = nil;
  socialObj = Social.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(userName, "userName");
  util.throwExceptionIfNullOrBlank(status, "status");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    body = {'app42' => {"social"=> {
      "userName" => userName,
      "status" => status
      }}}.to_json
    puts "Body #{body}"
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("body", body)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/facebook/updatestatus"
    response = connection.post(signature, resource_url, query_params, body)
    social = SocialResponseBuilder.new()
    socialObj = social.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return socialObj
end

#update_linkedIn_status(userName, status) ⇒ Object

Updates the LinkedIn status of the specified user.

Parameters:

  • userName
    • Name of the user for whom the status needs to be updated

  • status
    • status that has to be updated

Returns:

  • The Social object

Raises:

  • App42Exception



493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
# File 'lib/social/SocialService.rb', line 493

def update_linkedIn_status(userName, status)
  puts "updateStatus Called "
  puts "Base url #{@base_url}"
  response = nil;
  socialObj = nil;
  socialObj = Social.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(userName, "userName")
  util.throwExceptionIfNullOrBlank(status, "status")
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    body = {'app42' => {"social"=> {
      "userName" => userName,
      "status" => status
      }}}.to_json
    puts "Body #{body}"
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("body", body)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/linkedin/updatestatus"
    response = connection.post(signature, resource_url, query_params, body)
    social = SocialResponseBuilder.new()
    socialObj = social.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return socialObj
end

#update_social_status_for_all(userName, status) ⇒ Object

Updates the status for all linked social accounts of the specified user.

Parameters:

  • userName
    • Name of the user for whom the status needs to be updated

  • status
    • status that has to be updated

Returns:

  • The Social object

Raises:

  • App42Exception



544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
# File 'lib/social/SocialService.rb', line 544

def update_social_status_for_all(userName, status)
  puts "updateStatus Called "
  puts "Base url #{@base_url}"
  response = nil;
  socialObj = Social.new
  socialObj = nil;
  util = Util.new
  util.throwExceptionIfNullOrBlank(userName, "userName")
  util.throwExceptionIfNullOrBlank(status, "status")
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    body = {'app42' => {"social"=> {
      "userName" => userName,
      "status" => status
      }}}.to_json
    puts "Body #{body}"
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("body", body)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/social/updatestatus/all"
    response = connection.post(signature, resource_url, query_params, body)
    social = SocialResponseBuilder.new()
    socialObj = social.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  puts socialObj.userName()
  return socialObj
end

#update_twitter_status(userName, status) ⇒ Object

Updates the Twitter status of the specified user.

Parameters:

  • userName
    • Name of the user for whom the status needs to be updated

  • status
    • status that has to be updated

Returns:

  • The Social object

Raises:

  • App42Exception



324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/social/SocialService.rb', line 324

def update_twitter_status(userName,status)
  puts "updateStatus Called "
  puts "Base url #{@base_url}"
  response = nil;
  socialObj = Social.new
  socialObj = nil;
  util = Util.new
  util.throwExceptionIfNullOrBlank(userName, "userName");
  util.throwExceptionIfNullOrBlank(status, "status");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    body = {'app42' => {"social"=> {
      "userName" => userName,
      "status" => status
      }}}.to_json
    puts "Body #{body}"
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("body", body)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/twitter/updatestatus"
    response = connection.post(signature, resource_url, query_params, body)
    social = SocialResponseBuilder.new()
    socialObj = social.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return socialObj
end