Class: GroupOpenID::Client

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_openid = '', user_key = '') ⇒ Client

Returns a new instance of Client.



12
13
14
# File 'lib/group_open_id/client.rb', line 12

def initialize(user_openid = '', user_key = '')
  @user_key, @user_openid = user_key, user_openid
end

Class Attribute Details

.app_keyObject

Returns the value of attribute app_key.



9
10
11
# File 'lib/group_open_id/client.rb', line 9

def app_key
  @app_key
end

Instance Attribute Details

#fetcherObject



35
36
37
# File 'lib/group_open_id/client.rb', line 35

def fetcher
  @fetcher ||= Fetcher.new(self)
end

#user_keyObject

Returns the value of attribute user_key.



6
7
8
# File 'lib/group_open_id/client.rb', line 6

def user_key
  @user_key
end

#user_openidObject

Returns the value of attribute user_openid.



6
7
8
# File 'lib/group_open_id/client.rb', line 6

def user_openid
  @user_openid
end

Instance Method Details

#member?(group, member) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
# File 'lib/group_open_id/client.rb', line 28

def member?(group, member)
  (url = membership_location(group)) or raise InvalidGroupID
  url += '?openid=' + CGI.escape(::URI.parse(member).normalize.to_s)
  fetcher.head(url)['x-myid-membership'].to_s == 'true'
end

#members(group) ⇒ Object



21
22
23
24
25
26
# File 'lib/group_open_id/client.rb', line 21

def members(group)
  (url = membership_location(group)) or raise InvalidGroupID
  url += '?format=xml'
  p url
  parse_members(fetcher.get(url))
end

#membership_location(group) ⇒ Object Also known as: group_id?



16
17
18
# File 'lib/group_open_id/client.rb', line 16

def membership_location(group)
  fetcher.head(group)['x-myid-membership-location']
end

#parse_members(doc) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/group_open_id/client.rb', line 39

def parse_members(doc)
  Hpricot(doc).search('//relation').map do |rel|
    member = Member.new
    member.members.each{|sym| member.send("#{sym}=", rel.at(sym).inner_html)}
    member
  end 
end