Class: Contacts::Consumer
- Inherits:
-
Object
- Object
- Contacts::Consumer
- Defined in:
- lib/contacts/consumer.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#error ⇒ Object
An error message for the last call to #authorize.
Class Method Summary collapse
-
.configuration ⇒ Object
The configuration for this consumer.
-
.configuration_attribute(name) ⇒ Object
Define an instance-level reader for the named configuration attribute.
-
.configure(configuration) ⇒ Object
Configure this consumer from the given hash.
-
.deserialize(string) ⇒ Object
Create a consumer from the given
string
of serialized data.
Instance Method Summary collapse
-
#authorize(params) ⇒ Object
Authorize the consumer’s token from the given parameters.
-
#contacts ⇒ Object
Return the list of contacts, or nil if none could be retrieved.
-
#initialize(options = {}) ⇒ Consumer
constructor
A new instance of Consumer.
-
#serialize ⇒ Object
Return a string of serialized data.
Constructor Details
#initialize(options = {}) ⇒ Consumer
Returns a new instance of Consumer.
39 40 |
# File 'lib/contacts/consumer.rb', line 39 def initialize(={}) end |
Instance Attribute Details
#error ⇒ Object
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
.configuration ⇒ Object
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.
74 75 76 |
# File 'lib/contacts/consumer.rb', line 74 def (params) raise NotImplementedError, 'abstract' end |
#contacts ⇒ Object
Return the list of contacts, or nil if none could be retrieved.
86 87 88 |
# File 'lib/contacts/consumer.rb', line 86 def contacts raise NotImplementedError, 'abstract' end |
#serialize ⇒ Object
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 |