Module: Birdwatcher::Concerns::Core
- Included in:
- Birdwatcher::Command, Module
- Defined in:
- lib/birdwatcher/concerns/core.rb
Defined Under Namespace
Modules: ClassMethods Classes: DataFileNotFoundError
Constant Summary collapse
- DATA_DIRECTORY =
Location of the data directory
File.( File.join(File.dirname(__FILE__), "..", "..", "..", "data") ).freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#console ⇒ Birdwatcher::Console
Get the current Console instance.
-
#current_workspace ⇒ Birdwatcher::Models::Workspace
Get the currently active workspace model object.
-
#current_workspace=(workspace) ⇒ Object
Set the current workspace.
-
#database ⇒ Sequel::Database
Get the raw database client instance.
-
#klout_client ⇒ Birdwatcher::KloutClient
Get a Klout API client.
-
#read_data_file(name) ⇒ Object
Get the contents of a data file.
-
#twitter_client ⇒ Object
Get a Twitter API client.
Class Method Details
.included(base) ⇒ Object
13 14 15 |
# File 'lib/birdwatcher/concerns/core.rb', line 13 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#console ⇒ Birdwatcher::Console
Get the current Console instance
23 24 25 |
# File 'lib/birdwatcher/concerns/core.rb', line 23 def console Birdwatcher::Console.instance end |
#current_workspace ⇒ Birdwatcher::Models::Workspace
Get the currently active workspace model object
The current workspace is represented by its Sequel data model and can be used to query for data associated with the workspace.
Please read the Sequel gem documentation for more information about how to use the model.
37 38 39 |
# File 'lib/birdwatcher/concerns/core.rb', line 37 def current_workspace Birdwatcher::Console.instance.current_workspace end |
#current_workspace=(workspace) ⇒ Object
Set the current workspace
44 45 46 |
# File 'lib/birdwatcher/concerns/core.rb', line 44 def current_workspace=(workspace) Birdwatcher::Console.instance.current_workspace = workspace end |
#database ⇒ Sequel::Database
Get the raw database client instance
The raw database client object can be used to execute raw SQL queries against the configured database, however the #current_workspace method should be used whenever possible to execute SQL queries through the current workspace’s Sequel::Model instance instead. This ensures that the data returned is isolated to the current workspace.
88 89 90 |
# File 'lib/birdwatcher/concerns/core.rb', line 88 def database Birdwatcher::Console.instance.database end |
#klout_client ⇒ Birdwatcher::KloutClient
Get a Klout API client
The Klout API provides information about Twitter users such as their general “social score”, topics of interest and social influence graph.
The method will return an instance configured with a random API key from the ~/.birdwatcherrc configuration file.
75 76 77 |
# File 'lib/birdwatcher/concerns/core.rb', line 75 def klout_client Birdwatcher::Console.instance.klout_client end |
#read_data_file(name) ⇒ Object
Get the contents of a data file
98 99 100 101 102 |
# File 'lib/birdwatcher/concerns/core.rb', line 98 def read_data_file(name) path = File.join(DATA_DIRECTORY, name) fail(DataFileNotFoundError, "File #{name} was not found in data directory") unless File.exists?(path) File.read(path) end |
#twitter_client ⇒ Object
Get a Twitter API client
The Twitter API is being queried with the Twitter gem which provides an easy and intuitive interface to the API and its data objects. Please see the Twitter gem documentation for information on how to use the Twitter gem.
The method will return an instance configured with a random Twitter API keypair from the ~/.birdwatcherrc configuration file.
61 62 63 |
# File 'lib/birdwatcher/concerns/core.rb', line 61 def twitter_client Birdwatcher::Console.instance.twitter_client end |