Class: GooglePlus::Person

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

Overview

A Person 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::Person

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



59
60
61
# File 'lib/google_plus/person.rb', line 59

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

.get(user_id, params = {}) ⇒ GooglePlus::Person

Get a person by id

Parameters:

  • user_id (String)

    the id of the user 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::Person)

    a person object representing the person we’re looking up, if it is found - otherwise, return nil



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

def self.get(user_id, params = {})
  data = make_request(:get, "people/#{user_id}", params)
  Person.new(JSON.parse(data)) if data
end

.list(user_id = 'me', collection = 'visible', params = {}) ⇒ GooglePlus::Cursor

Get a list of people for a collection

Parameters:

  • 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:



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

def self.list(user_id = 'me', collection = 'visible', params = {})
  path_segments = ['people', user_id, 'people', collection]
  path = path_segments.map { |ps| URI.escape(ps) }.join('/')
  GooglePlus::Cursor.new(self, :get, path, params)
end

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

Search for a person

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:



37
38
39
40
41
# File 'lib/google_plus/person.rb', line 37

def self.search(query, params = {})
  params[:query] = query
  resource = 'people'
  GooglePlus::Cursor.new(self, :get, resource, params)
end

Instance Method Details

#list_activities(params = {}) ⇒ GooglePlus::Cursor

List the activities for this person

Returns:



45
46
47
# File 'lib/google_plus/person.rb', line 45

def list_activities(params = {})
  GooglePlus::Activity.for_person(id, params)
end

#list_visible_people(params = {}) ⇒ GooglePlus::Cursor

List visible people for the user

Returns:



51
52
53
# File 'lib/google_plus/person.rb', line 51

def list_visible_people(params = {})
  GooglePlus::Person.list('me', 'visible', params)
end