Class: Contacts::Provider::Base

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

Direct Known Subclasses

OAuth, OAuth2

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_urlObject

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_idObject



17
18
19
# File 'lib/contacts/provider/base.rb', line 17

def provider_id
  self.name.gsub(/^.*::/, '').downcase
end

.valid_attributesObject



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

#attributesObject



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

#connectionObject



42
43
44
# File 'lib/contacts/provider/base.rb', line 42

def connection
  @connection ||= connect!
end

#contactsObject



58
59
60
# File 'lib/contacts/provider/base.rb', line 58

def contacts
  @contacts ||= parse_contacts!
end

#contacts_responseObject



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_urlObject



26
27
28
# File 'lib/contacts/provider/base.rb', line 26

def site_url
  self.class.site_url
end

#valid_attributesObject



30
31
32
# File 'lib/contacts/provider/base.rb', line 30

def valid_attributes
  self.class.valid_attributes
end