module Birdwatcher::Concerns::Core
Constants
- DATA_DIRECTORY
Location of the data directory @private
Public Class Methods
# File lib/birdwatcher/concerns/core.rb, line 13 def self.included(base) base.extend(ClassMethods) end
Public Instance Methods
Get the current Console
instance
@return [Birdwatcher::Console]
# File lib/birdwatcher/concerns/core.rb, line 23 def console Birdwatcher::Console.instance end
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.
@return [Birdwatcher::Models::Workspace] instance of the currently active workspace @see sequel.jeremyevans.net/documentation.html
# File lib/birdwatcher/concerns/core.rb, line 37 def current_workspace Birdwatcher::Console.instance.current_workspace end
Set the current workspace
@param workspace [Birdwatcher::Models::Workspace]
# File lib/birdwatcher/concerns/core.rb, line 44 def current_workspace=(workspace) Birdwatcher::Console.instance.current_workspace = workspace end
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.
@return [Sequel::Database]
# File lib/birdwatcher/concerns/core.rb, line 88 def database Birdwatcher::Console.instance.database end
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.
@return [Birdwatcher::KloutClient] @see klout.com/s/developers/v2
# File lib/birdwatcher/concerns/core.rb, line 75 def klout_client Birdwatcher::Console.instance.klout_client end
Get the contents of a data file
@param name [String] file name to read
@return contents of file in Birdwatcher’s data directory @raise [Birdwatcher::Concerns::Core::DataFileNotFoundError] if the file doesn’t exist
# 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
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.
@return instance of Twitter::REST::Client @see github.com/sferik/twitter @see www.rubydoc.info/gems/twitter
# File lib/birdwatcher/concerns/core.rb, line 61 def twitter_client Birdwatcher::Console.instance.twitter_client end