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.expand_path(
  File.join(File.dirname(__FILE__), "..", "..", "..", "data")
).freeze

Class Method Summary collapse

Instance Method Summary collapse

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

#consoleBirdwatcher::Console

Get the current Console instance



23
24
25
# File 'lib/birdwatcher/concerns/core.rb', line 23

def console
  Birdwatcher::Console.instance
end

#current_workspaceBirdwatcher::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.

Returns:

  • (Birdwatcher::Models::Workspace)

    instance of the currently active workspace

See Also:



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

Parameters:

  • workspace (Birdwatcher::Models::Workspace)


44
45
46
# File 'lib/birdwatcher/concerns/core.rb', line 44

def current_workspace=(workspace)
  Birdwatcher::Console.instance.current_workspace = workspace
end

#databaseSequel::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.

Returns:

  • (Sequel::Database)


88
89
90
# File 'lib/birdwatcher/concerns/core.rb', line 88

def database
  Birdwatcher::Console.instance.database
end

#klout_clientBirdwatcher::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

Parameters:

  • name (String)

    file name to read

Returns:

  • contents of file in Birdwatcher’s data directory

Raises:



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_clientObject

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.

Returns:

  • instance of Twitter::REST::Client

See Also:



61
62
63
# File 'lib/birdwatcher/concerns/core.rb', line 61

def twitter_client
  Birdwatcher::Console.instance.twitter_client
end