class App42::Social::SocialService

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

Public Class Methods

new(api_key, secret_key, base_url) click to toggle source

this is a constructor that takes

@param apiKey @param secretKey @param baseURL

# 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

Public Instance Methods

update_facebook_status(userName,status) click to toggle source

Updates the Facebook status of the specified user.

@param userName

- Name of the user for whom the status needs to be updated

@param status

- status that has to be updated

@return The Social object

@raise App42Exception

# 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) click to toggle source

Updates the LinkedIn status of the specified user.

@param userName

- Name of the user for whom the status needs to be updated

@param status

- status that has to be updated

@return The Social object

@raise App42Exception

# 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) click to toggle source

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

@param userName

- Name of the user for whom the status needs to be updated

@param status

- status that has to be updated

@return The Social object

@raise App42Exception

# 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) click to toggle source

Updates the Twitter status of the specified user.

@param userName

- Name of the user for whom the status needs to be updated

@param status

- status that has to be updated

@return The Social object

@raise App42Exception

# 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