Class: Contacts::Provider::Base
- Inherits:
-
Object
- Object
- Contacts::Provider::Base
- Defined in:
- lib/contacts/provider/base.rb
Class Attribute Summary collapse
-
.site_url ⇒ Object
Returns the value of attribute site_url.
Class Method Summary collapse
- .all(attrs = {}) ⇒ Object
- .provider_id ⇒ Object
- .valid_attributes ⇒ Object
- .valid_attributes=(attrs) ⇒ Object
Instance Method Summary collapse
- #attributes ⇒ Object
- #attributes=(attrs = {}) ⇒ Object
- #connect! ⇒ Object
- #connection ⇒ Object
- #contacts ⇒ Object
- #contacts_response ⇒ Object
-
#initialize(attrs = {}) ⇒ Base
constructor
A new instance of Base.
- #parse_attributes(attrs = {}) ⇒ Object
- #parse_contacts! ⇒ Object
- #retrieve_contacts! ⇒ Object
- #site_url ⇒ Object
- #valid_attributes ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Base
Returns a new instance of Base.
34 35 36 |
# File 'lib/contacts/provider/base.rb', line 34 def initialize attrs={} parse_attributes attrs end |
Class Attribute Details
.site_url ⇒ Object
Returns the value of attribute site_url.
6 7 8 |
# File 'lib/contacts/provider/base.rb', line 6 def site_url @site_url end |
Class Method Details
.all(attrs = {}) ⇒ Object
21 22 23 |
# File 'lib/contacts/provider/base.rb', line 21 def all attrs={} new(attrs).contacts end |
.provider_id ⇒ Object
17 18 19 |
# File 'lib/contacts/provider/base.rb', line 17 def provider_id self.name.gsub(/^.*::/, '').downcase end |
.valid_attributes ⇒ Object
13 14 15 |
# File 'lib/contacts/provider/base.rb', line 13 def valid_attributes @valid_attributes ||= [] end |
.valid_attributes=(attrs) ⇒ Object
8 9 10 11 |
# File 'lib/contacts/provider/base.rb', line 8 def valid_attributes= attrs @valid_attributes = attrs.map!(&:to_sym) attr_accessor *attrs end |
Instance Method Details
#attributes ⇒ Object
72 73 74 |
# File 'lib/contacts/provider/base.rb', line 72 def attributes self.class.valid_attributes.inject({}) {|result, attr| result.merge attr => send(attr) } end |
#attributes=(attrs = {}) ⇒ Object
66 67 68 69 70 |
# File 'lib/contacts/provider/base.rb', line 66 def attributes= attrs = {} attrs.each do |attr_name, attr_value| send("#{attr_name}=", attr_value) end end |
#connect! ⇒ Object
38 39 40 |
# File 'lib/contacts/provider/base.rb', line 38 def connect! raise "implement in subclass" end |
#connection ⇒ Object
42 43 44 |
# File 'lib/contacts/provider/base.rb', line 42 def connection @connection ||= connect! end |
#contacts ⇒ Object
58 59 60 |
# File 'lib/contacts/provider/base.rb', line 58 def contacts @contacts ||= parse_contacts! end |
#contacts_response ⇒ Object
50 51 52 |
# File 'lib/contacts/provider/base.rb', line 50 def contacts_response @contacts_response ||= retrieve_contacts! end |
#parse_attributes(attrs = {}) ⇒ Object
62 63 64 |
# File 'lib/contacts/provider/base.rb', line 62 def parse_attributes attrs = {} self.attributes = attrs.reject { |k,v| !self.class.valid_attributes.include?(k.to_sym) } end |
#parse_contacts! ⇒ Object
54 55 56 |
# File 'lib/contacts/provider/base.rb', line 54 def parse_contacts! raise "implement in subclass" end |
#retrieve_contacts! ⇒ Object
46 47 48 |
# File 'lib/contacts/provider/base.rb', line 46 def retrieve_contacts! raise "implement in subclass" end |
#site_url ⇒ Object
26 27 28 |
# File 'lib/contacts/provider/base.rb', line 26 def site_url self.class.site_url end |
#valid_attributes ⇒ Object
30 31 32 |
# File 'lib/contacts/provider/base.rb', line 30 def valid_attributes self.class.valid_attributes end |