Class: Contacts::Yahoo

Inherits:
OAuthConsumer show all
Defined in:
lib/contacts/yahoo.rb

Constant Summary collapse

CONSUMER_OPTIONS =
Util.frozen_hash(
  :site => "https://api.login.yahoo.com",
  :request_token_path => "/oauth/v2/get_request_token",
  :access_token_path => "/oauth/v2/get_token",
  :authorize_path => "/oauth/v2/request_auth"
)
REQUEST_TOKEN_PARAMS =
{}

Instance Attribute Summary

Attributes inherited from OAuthConsumer

#access_token, #request_token

Attributes inherited from Consumer

#error

Instance Method Summary collapse

Methods inherited from OAuthConsumer

#authentication_url, #authorize

Methods inherited from Consumer

#authorize, configuration, configuration_attribute, configure, deserialize, #serialize

Constructor Details

#initialize(options = {}) ⇒ Yahoo

Returns a new instance of Yahoo.



15
16
17
# File 'lib/contacts/yahoo.rb', line 15

def initialize(options={})
  super(CONSUMER_OPTIONS, REQUEST_TOKEN_PARAMS)
end

Instance Method Details

#contacts(options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/contacts/yahoo.rb', line 26

def contacts(options={})
  return nil if @access_token.nil?
  params = {:limit => 200}.update(options)
  yahoo_params = translate_contacts_options(params).merge('format' => 'json')
  guid = @access_token.params['xoauth_yahoo_guid']
  uri = URI.parse("http://social.yahooapis.com/v1/user/#{guid}/contacts")
  uri.query = params_to_query(yahoo_params)
  begin
    response = @access_token.get(uri.to_s)
  rescue OAuth::Unauthorized => error
    # Token probably expired.
    @error = error.message
    return nil
  end
  parse_contacts(response.body)
end

#initialize_serialized(data) ⇒ Object



19
20
21
22
23
24
# File 'lib/contacts/yahoo.rb', line 19

def initialize_serialized(data)
  super
  if @access_token && (guid = data['guid'])
    @access_token.params['xoauth_yahoo_guid'] = guid
  end
end

#serializable_dataObject



43
44
45
46
47
# File 'lib/contacts/yahoo.rb', line 43

def serializable_data
  data = super
  data['guid'] = @access_token.params['xoauth_yahoo_guid'] if @access_token
  data
end