Method: CloudKit::OpenIDStore#get_association

Defined in:
lib/cloudkit/openid_store.rb

#get_association(server_url, handle = nil) ⇒ Object

:nodoc:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cloudkit/openid_store.rb', line 17

def get_association(server_url, handle=nil) #:nodoc:
  options = {:server_url => server_url}
  options.merge!(:handle => Base64.encode64(handle)) if (handle && handle != '')
  result = @@store.get(CloudKit::URI.new('/cloudkit_openid_associations'), options)
  return nil unless result.status == 200
  return nil if result.parsed_content['total'] == 0

  ignore, associations = resolve_associations(result.parsed_content)
  return nil if associations.empty?

  associations.sort_by{|a| a['issued']}
  a = associations[-1]
  OpenID::Association.new(
    Base64.decode64(a['handle']),
    Base64.decode64(a['secret']),
    Time.at(a['issued']),
    a['lifetime'],
    a['assoc_type'])
end