Class: GooglePlus::Activity

Inherits:
Object
  • Object
show all
Extended by:
Resource
Includes:
Entity
Defined in:
lib/google_plus/activity.rb

Overview

An Acitity in Google Plus

Constant Summary

Constants included from Resource

Resource::BASE_URI

Instance Attribute Summary

Attributes included from Entity

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Resource

make_request

Methods included from Entity

included, #method_missing, #respond_to?

Constructor Details

#initialize(hash) ⇒ GooglePlus::Activity

Load a new instance from an attributes hash Useful if you have the underlying response data for an object - Generally, what you want is #get though



83
84
85
# File 'lib/google_plus/activity.rb', line 83

def initialize(hash)
  load_hash(hash)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class GooglePlus::Entity

Class Method Details

.for_person(user_id, params = {}) ⇒ GooglePlus::Cursor

Get a list of activities from this person

Parameters:

  • user_id (String)

    The ID of the user to look up activities for

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :collection (Symbol)

    What collection to pull activities for defaults to :public

  • :key (Symbol)

    A different API key to use for this request

  • :user_ip (Symbol)

    The IP of the user on who’s behalf this request is made

Returns:

  • (GooglePlus::Cursor)

    a cursor that will paginate through the results for the activity list



41
42
43
44
45
# File 'lib/google_plus/activity.rb', line 41

def self.for_person(user_id, params = {})
  collection = params[:collection] || :public
  resource = "people/#{user_id}/activities/#{collection}"
  GooglePlus::Cursor.new(self, :get, resource, params)
end

.get(activity_id, params = {}) ⇒ GooglePlus::Activity

Get an activity by ID

Parameters:

  • activity_id (String)

    The id of the activity to look up

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :key (Symbol)

    A different API key to use for this request

  • :user_ip (Symbol)

    The IP of the user on who’s behalf this request is made

Returns:

  • (GooglePlus::Activity)

    an activity object for the activity, if it is found - otherwise, return nil



15
16
17
18
# File 'lib/google_plus/activity.rb', line 15

def self.get(activity_id, params = {})
  data = make_request(:get, "activities/#{activity_id}", params)
  Activity.new(JSON.parse(data)) if data
end

.search(query, params = {}) ⇒ GooglePlus::Cursor

Search for an activity

Parameters:

  • query (String)

    The query string to search for

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :key (Symbol)

    A different API key to use for this request

  • :user_ip (Symbol)

    The IP of the user on who’s behalf this request is made

Returns:

  • (GooglePlus::Cursor)

    a cursor that will paginate through the results for the activity search



26
27
28
29
30
31
# File 'lib/google_plus/activity.rb', line 26

def self.search(query, params = {})
  params[:query] = query
  params[:orderBy] = params.delete(:order_by) if params.has_key?(:order_by)
  resource = 'activities'
  GooglePlus::Cursor.new(self, :get, resource, params)
end

Instance Method Details

#list_commentsGooglePlus::Cursor

Get the list of comments for an activity

Returns:



49
50
51
# File 'lib/google_plus/activity.rb', line 49

def list_comments
  GooglePlus::Comment.for_activity(id) 
end

#list_people(collection) ⇒ GooglePlus::Cursor

List the people of a certain type of action on this activity

Parameters:

  • collection (Symbol)

    The collection to look up (ie: :plusoners, :resharers)

Returns:



62
63
64
65
# File 'lib/google_plus/activity.rb', line 62

def list_people(collection)
  resource = "activities/#{id}/people/#{collection}"
  GooglePlus::Cursor.new(GooglePlus::Person, :get, resource)
end

#personGooglePlus::Person

get the actor of this activity

Returns:



55
56
57
# File 'lib/google_plus/activity.rb', line 55

def person
  @person ||= GooglePlus::Person.get(actor.id)
end

#plusonersGooglePlus::Cursor

List the people that plusone’d this activity

Returns:



69
70
71
# File 'lib/google_plus/activity.rb', line 69

def plusoners
  list_people(:plusoners)
end

#resharersGooglePlus::Cursor

List the people that reshared this activity

Returns:



75
76
77
# File 'lib/google_plus/activity.rb', line 75

def resharers
  list_people(:resharers)
end