Class: PortableContacts::Client

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

Overview

This is the main PortableContacts Client.

query options

The library supports the various filter and sorting parameters. The format of this may change for this library, so limit use to : :count and :start_index for now.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url, access_token) ⇒ Client

First parameter is the portable contacts base_url. Find this on your PortableContact providers documentation or through XRDS.

The second parameter is an OAuth::AccessToken instantiated for the provider.



23
24
25
26
# File 'lib/portable_contacts.rb', line 23

def initialize(base_url,access_token)
  @base_url=base_url
  @access_token=access_token
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



14
15
16
# File 'lib/portable_contacts.rb', line 14

def base_url
  @base_url
end

Instance Method Details

#all(options = {}) ⇒ Object

Returns the contacts of the user. It defaults to all fields and 100 entries

@contacts = @client.all # return 100 contacts
@contacts = @client.all :count=>10 # return 10 contacts
@contacts = @client.all :count=>10, :start_index=>10 # returns the second page of 10 contacts
puts @contacts.total_entries # returns the total amount of contacts on the server

Returns a PortableContacts::Collection which is a subclass of Array



42
43
44
# File 'lib/portable_contacts.rb', line 42

def all(options={})
  collection(get("/@me/@all",options.reverse_merge(:fields=>:all,:count=>100)))
end

#find(id, options = {}) ⇒ Object

Returns the full contact infor for a particular userid. TODO This is not tested well Returns an PortableContacts::Person object



48
49
50
# File 'lib/portable_contacts.rb', line 48

def find(id, options={})
  single(get("/@me/@all/#{id}",options.reverse_merge(:fields=>:all)))
end

#me(options = {}) ⇒ Object

Returns the AccessToken users contact details. Note this requests all fields from provider Returns an PortableContacts::Person object



30
31
32
# File 'lib/portable_contacts.rb', line 30

def me(options={})
  single(get("/@me/@self",options.reverse_merge(:fields=>:all)))
end