Class: Blackbook
Defined Under Namespace
Modules: Exporter, Importer Classes: BadCredentialsError, BlackbookError
Constant Summary collapse
- VERSION =
'1.0.4'
Instance Attribute Summary collapse
-
#exporters ⇒ Object
Returns the value of attribute exporters.
-
#importers ⇒ Object
Returns the value of attribute importers.
Class Method Summary collapse
Instance Method Summary collapse
-
#export(importer, exporter, options) ⇒ Object
Sends the vcards from the import to whatever is handling the export.
-
#find_importer(options) ⇒ Object
Searches registered importers for one that will handle the given options.
-
#get(*args) ⇒ Object
Fetches contacts from various services or filetypes.
-
#initialize ⇒ Blackbook
constructor
A new instance of Blackbook.
Constructor Details
#initialize ⇒ Blackbook
Returns a new instance of Blackbook.
59 60 61 62 |
# File 'lib/blackbook.rb', line 59 def initialize self.importers = {} self.exporters = {} end |
Instance Attribute Details
#exporters ⇒ Object
Returns the value of attribute exporters.
13 14 15 |
# File 'lib/blackbook.rb', line 13 def exporters @exporters end |
#importers ⇒ Object
Returns the value of attribute importers.
12 13 14 |
# File 'lib/blackbook.rb', line 12 def importers @importers end |
Class Method Details
.get(*args) ⇒ Object
15 16 17 |
# File 'lib/blackbook.rb', line 15 def self.get( *args ) instance.get( *args ) end |
.register(name, adapter_class) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/blackbook.rb', line 19 def self.register(name, adapter_class) case adapter = adapter_class.new when Importer::Base instance.importers[name.to_sym] = adapter when Exporter::Base instance.exporters[name.to_sym] = adapter else raise ArgumentError, "Unknown adapter" end end |
Instance Method Details
#export(importer, exporter, options) ⇒ Object
Sends the vcards from the import to whatever is handling the export
31 32 33 |
# File 'lib/blackbook.rb', line 31 def export( importer, exporter, ) exporter.export importer.import( ) end |
#find_importer(options) ⇒ Object
Searches registered importers for one that will handle the given options
36 37 38 39 |
# File 'lib/blackbook.rb', line 36 def find_importer( ) importers.each{ |key, importer| return importer if importer =~ } nil end |
#get(*args) ⇒ Object
Fetches contacts from various services or filetypes. The default is to return an array of hashes - Blackbook’s internal format
Handles several different calls:
get( :username => '[email protected]', :password => 'whatever' )
get( :as => :xml, :username => '[email protected]', :password => 'whatever' )
get( :csv, :file => #<File:/path/to/file.csv> )
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/blackbook.rb', line 48 def get( *args ) = args.last.is_a?(Hash) ? args.pop : {} to_format = exporters[ [:as] || :basic ] source = (importers[args.first.to_sym] rescue nil) || find_importer() raise ArgumentError, "Unknown exporter" unless to_format raise ArgumentError, "Unknown source" unless source export source, to_format, end |