class Contacts::Consumer
Attributes
error[RW]
An error message for the last call to authorize
.
Public Class Methods
configuration()
click to toggle source
The configuration for this consumer.
# File lib/contacts/consumer.rb, line 13 def self.configuration @configuration end
configuration_attribute(name)
click to toggle source
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"
# 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)
click to toggle source
Configure this consumer from the given hash.
# File lib/contacts/consumer.rb, line 6 def self.configure(configuration) @configuration = Util.symbolize_keys(configuration) end
deserialize(string)
click to toggle source
Create a consumer from the given string
of serialized data.
The serialized data should have been returned by serialize
.
# 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
new(options={})
click to toggle source
# File lib/contacts/consumer.rb, line 39 def initialize(options={}) end
Protected Class Methods
params_to_query(params)
click to toggle source
# File lib/contacts/consumer.rb, line 100 def self.params_to_query(params) params.map do |key, value| "#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}" end.join('&') end
query_to_params(data)
click to toggle source
# File lib/contacts/consumer.rb, line 106 def self.query_to_params(data) params={} data.split(/&/).each do |pair| key, value = *pair.split(/=/) params[CGI.unescape(key)] = value ? CGI.unescape(value) : '' end params end
Public Instance Methods
contacts()
click to toggle source
Return the list of contacts, or nil if none could be retrieved.
# File lib/contacts/consumer.rb, line 86 def contacts raise NotImplementedError, 'abstract' end
serialize()
click to toggle source
Return a string of serialized data.
You may reconstruct the consumer by passing this string to .deserialize.
# File lib/contacts/consumer.rb, line 48 def serialize params_to_query(serializable_data) end
Protected Instance Methods
initialize_serialized(data)
click to toggle source
# File lib/contacts/consumer.rb, line 92 def initialize_serialized(data) raise NotImplementedError, 'abstract' end
params_to_query(params)
click to toggle source
# File lib/contacts/consumer.rb, line 115 def params_to_query(params) self.class.params_to_query(params) end
query_to_params(data)
click to toggle source
# File lib/contacts/consumer.rb, line 119 def query_to_params(data) self.class.query_to_params(data) end
serialized_data()
click to toggle source
# File lib/contacts/consumer.rb, line 96 def serialized_data raise NotImplementedError, 'abstract' end