Class: Contacts::Consumer

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

Direct Known Subclasses

OAuthConsumer, WindowsLive

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Consumer

Returns a new instance of Consumer.



39
40
# File 'lib/contacts/consumer.rb', line 39

def initialize(options={})
end

Instance Attribute Details

#errorObject

An error message for the last call to #authorize.



81
82
83
# File 'lib/contacts/consumer.rb', line 81

def error
  @error
end

Class Method Details

.configurationObject

The configuration for this consumer.



13
14
15
# File 'lib/contacts/consumer.rb', line 13

def self.configuration
  @configuration
end

.configuration_attribute(name) ⇒ Object

Define an instance-level reader for the named configuration attribute.

Example:

class MyConsumer < Consumer
  configuration_attribute :app_id
end

MyConsumer.configure(:app_id => 'foo')
consumer = MyConsumer.new
consumer.app_id    # "foo"


31
32
33
34
35
36
37
# File 'lib/contacts/consumer.rb', line 31

def self.configuration_attribute(name)
  class_eval <<-EOS
    def #{name}
      self.class.configuration[:#{name}]
    end
  EOS
end

.configure(configuration) ⇒ Object

Configure this consumer from the given hash.



6
7
8
# File 'lib/contacts/consumer.rb', line 6

def self.configure(configuration)
  @configuration = Util.symbolize_keys(configuration)
end

.deserialize(string) ⇒ Object

Create a consumer from the given string of serialized data.

The serialized data should have been returned by #serialize.



57
58
59
60
61
62
# File 'lib/contacts/consumer.rb', line 57

def self.deserialize(string)
  data = string ? query_to_params(string) : {}
  consumer = new
  consumer.initialize_serialized(data) if data
  consumer
end

Instance Method Details

#authorize(params) ⇒ Object

Authorize the consumer’s token from the given parameters. params is the request parameters the user is redirected to your site with.

Return true if authorization is successful, false otherwise. If unsuccessful, an error message is set in #error. Authorization may fail, for example, if the user denied access, or the authorization is forged.

Raises:

  • (NotImplementedError)


74
75
76
# File 'lib/contacts/consumer.rb', line 74

def authorize(params)
  raise NotImplementedError, 'abstract'
end

#contactsObject

Return the list of contacts, or nil if none could be retrieved.

Raises:

  • (NotImplementedError)


86
87
88
# File 'lib/contacts/consumer.rb', line 86

def contacts
  raise NotImplementedError, 'abstract'
end

#serializeObject

Return a string of serialized data.

You may reconstruct the consumer by passing this string to .deserialize.



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

def serialize
  params_to_query(serializable_data)
end