Class: Giggly::Rest::Socialize

Inherits:
Object
  • Object
show all
Defined in:
lib/giggly/rest/socialize.rb

Defined Under Namespace

Classes: InvalidProvider

Constant Summary collapse

GIGYA_URL =
"http://socialize.api.gigya.com/socialize."

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Socialize

Create a new socialize object by passing in a Giggly::Rest::Socialize object or by passing in a hash that will be used to initialize a new Giggly::Rest::Socialize. See the rdoc for Request to find details for a new connection hash. A Giggly::Rest::Socialize is used per user (because the Request object is). example:

@socialize = Giggly::Rest::Socialize.new(@connection)


15
16
17
18
# File 'lib/giggly/rest/socialize.rb', line 15

def initialize(request)
  @request = request and return if request.kind_of?(Giggly::Rest::Request)
  @request = Giggly::Rest::Request.new(request)
end

Instance Attribute Details

#requestObject

Returns the value of attribute request.



7
8
9
# File 'lib/giggly/rest/socialize.rb', line 7

def request
  @request
end

Instance Method Details

#disconnect(provider = nil) ⇒ Object

Disconnects the user from the provided network.

Params
  • network array of networks to disconnect from, if emtpy user will be disconnected from all networks

Allowed values for network are facebook, myspace, twitter and yahoo.



24
25
26
27
# File 'lib/giggly/rest/socialize.rb', line 24

def disconnect(provider = nil)
  validate_providers! %w[facebook yahoo myspace twitter], provider
  perform_post :disconnect, :provider => (provider.join(',') if provider)
end

#friends_info(options = {}) ⇒ Object

retrieves the friends of the current user

Params
  • enabled_providers comma separated list of providers to include. (ONLY)

  • disabled_providers comma separated list of providers to exclude. (NOT)

  • uids list of users to retrieve.

  • detail_level ‘basic’ or ‘extended’

Returns
  • Array of Giggly::User objects



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/giggly/rest/socialize.rb', line 37

def friends_info(options = {})
  validate_providers! %w[facebook yahoo myspace twitter], options[:enabled_providers]
  params = provider_hash(options)
  params[:user_ids], params[:detail_level] = options[:uids], options[:detailLevel]
  
  response = perform_post(:getFriendsInfo, params)
  friends = []
  response['friends']['friend'].each do |friend|
    friends << Giggly::Friend.new(friend)
  end
  friends
end

#publish_user_action(user_action_xml, providers = {}) ⇒ Object



88
89
90
91
# File 'lib/giggly/rest/socialize.rb', line 88

def publish_user_action(user_action_xml, providers = {})
  validate_providers! %w[facebook yahoo], providers[:enabled_providers]
  perform_post :publishUserAction, {:userAction => user_action_xml}.merge(provider_hash(providers))
end

#raw_data(provider, fields) ⇒ Object

get raw data from an individual provider about a user

Params
  • provider the provider to retrieve the raw data from, only facebook and myspace are currently supported

  • fields a array of provider specific fields to retrieve

Returns
  • Hash of the raw data



56
57
58
59
# File 'lib/giggly/rest/socialize.rb', line 56

def raw_data(provider, fields)
  validate_providers! %w[facebook myspace], provider
  perform_post :getRawData, {:provider => provider, :fields => fields.join(',')}
end

#send_notification(recipients, subject, body) ⇒ Object

Sends a notification to a list of friends

Params
  • recipients a string or array of uids to send the notification to

  • subject the subject line of the notification

  • body the body of the notification, do not use html, Gigya will autolink urls

this will post to both facebook and twitter



99
100
101
102
# File 'lib/giggly/rest/socialize.rb', line 99

def send_notification(recipients, subject, body)
  recipients = recipients.is_a?(Array) ? recipients.join(',') : recipients
  perform_post :sendNotification, :recipients => recipients, :subject => subject, :body => body
end

#session_info(provider, padding_mode = 'PKCS7') ⇒ Object

get the connection info for a session with a direct api provider this is useful to make calls to a specific provider (not via Socialize) for functions that are currently unsupported by Gigya Socialize

Params
  • provider the provider to get the connection information for,

    • possible values are facebook, myspace, twitter, or yahoo

  • padding_mode padding mode for the AES algorithm used in encryping some of the response parameters

    • values are PKCS5, PKCS7 or ZEROS PKCS7 will be used as the default

See wiki.gigya.com/030_Gigya_Socialize_API_2.0/030_API_reference/REST_API/socialize.getSessionInfo on decrypting



70
71
72
73
74
# File 'lib/giggly/rest/socialize.rb', line 70

def session_info(provider, padding_mode = 'PKCS7')
  validate_providers! %w[facebook yahoo myspace twitter], provider
  # TODO: possibly decrypt response
  Giggly::SessionInfo.new perform_post(:getSessionInfo, {:provider => provider, :paddingMode => padding_mode})
end

#set_status(status, providers = {}) ⇒ Object

sets the status of a user for the given providers (or all of them if blank)

Params
  • status the status to set for the user

  • providers an optional hash of arrays the has the keys of

  • enabled_providers an array of provider strings

  • disabled_providers an array of provider strings



110
111
112
113
# File 'lib/giggly/rest/socialize.rb', line 110

def set_status(status, providers = {})
  validate_providers! %w[facebook yahoo myspace twitter], providers[:enabled_providers]
  perform_post :setStatus, {:status => status}.merge(provider_hash(providers))
end

#status=(status) ⇒ Object

sets the status of a user for all providers

Params
  • status the status to set for the user

This method will return the status if it is successful, and raise an error on failure Use set status if you want to return the response object Its just in here because we think it looks cool and its convenient



121
122
123
# File 'lib/giggly/rest/socialize.rb', line 121

def status=(status)
  set_status status
end

#user_info(providers = {}) ⇒ Object

retrieves user information from gigya, including or excluding providers as indicated. default usage includes all providers. returns user.

Params
  • providers an optional hash of arrays the has the keys of

  • enabled_providers an array of provider strings

  • disabled_providers an array of provider strings



82
83
84
# File 'lib/giggly/rest/socialize.rb', line 82

def (providers = {})
  Giggly::User.new perform_post(:getUserInfo, provider_hash(providers))
end