Module: Chimps

Defined in:
lib/chimps.rb,
lib/chimps/error.rb,
lib/chimps/utils.rb,
lib/chimps/config.rb,
lib/chimps/request.rb,
lib/chimps/response.rb,
lib/chimps/query_request.rb,
lib/chimps/utils/uses_curl.rb,
lib/chimps/utils/typewriter.rb,
lib/chimps/workflows/upload.rb,
lib/chimps/workflows/download.rb

Overview

The Chimps module provides classes which make making requests at Infochimps easy.

Using this tool you can search, download, edit, and upload data and metadata to and from Infochimps.

Defined Under Namespace

Modules: Log, Utils Classes: Download, QueryRequest, Request, Response, Upload

Constant Summary collapse

Error =

Base exception class for Chimps. All Chimps exceptions are subclasses of Chimps::Error so they can be easily caught.

Class.new(StandardError)
AuthenticationError =

Raised when the user hasn’t specified any API credentials or the server rejects the user’s API credentials.

Roughly corresponds to HTTP status code 401/403.

Class.new(Error)
ServerError =

Raised when the Infochimps server response is unexpected or missing.

Roughly corresponds to HTTP status code 5xx.

Class.new(Error)
UploadError =

Raised when there is an error in uploading to S3 or in notifiying Infochimps of the new package.

Class.new(Error)
NotImplementedError =

Raised when a subclass doesn’t fails to implement required methods.

Class.new(Error)
ParseError =

Raised when the response from Infochimps isn’t well-formed.

Class.new(Error)
Config =

Backwards compatibility for version < 0.3.0.

config

Class Method Summary collapse

Class Method Details

.boot!Object

Load and resolve configuration.



19
20
21
22
23
24
25
26
# File 'lib/chimps.rb', line 19

def self.boot!
  config.read config[:site_config] if config[:site_config] && File.exist?(config[:site_config])
  config.read config[:config]      if config[:config]      && File.exist?(config[:config])
  config[:catalog] = config[:site]    if (! config[:catalog]) && config[:site]    # backwards compatibility
  config[:catalog] = config[:dataset] if (! config[:catalog]) && config[:dataset] # backwards compatibility
  config.resolve!
  true
end

.configConfigliere::Param

Chimps configuration. Managed by Configliere

Returns:

  • (Configliere::Param)


9
10
11
# File 'lib/chimps/config.rb', line 9

def self.config
  @config ||= Configliere::Param.new
end

.define_configObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/chimps/config.rb', line 16

def self.define_config
  config.define :site_config,      :description => "Path to site-wide configuration file", :env_var => "CHIMPS_ETC", :default => "/etc/chimps/chimps.yaml", :type => String, :no_help => true
  config.define :config,           :description => "Path to user configuration file", :env_var => "CHIMPS_RC", :default => (ENV["HOME"] && File.expand_path("~/.chimps")), :flag => :c, :type => String
  config.define :log,              :description => "Path to log file", :flag => :l, :type => String
  config.define :timestamp_format, :description => "Format for timestamps", :type => String, :no_help => true, :default => "%Y%m%d-%H%M%S"
  config.define :plugin_dirs,      :description => "List of directories from which to load plugins", :type => Array, :no_help => true, :default => ['/usr/share/chimps', '/usr/local/share/chimps']
  config.define :skip_plugins,     :description => "Don't load any plugins", :flag => :q, :type => :boolean
  config.define :verbose,          :description => "Be verbose", :flag => :v, :type => :boolean
  
  config.define 'query.host',      :description => "Host to send Query API requests to", :type => String, :default => "http://api.infochimps.com", :no_help => true, :env_var => "APEYEYE", :no_help => true
  config.define 'query.key',       :description => "API key for the Query API", :type => String, :no_help => true
  
  config.define 'catalog.username',   :description => "Your Infochimps username", :type => String
  config.define 'catalog.host',       :description => "Host to send Catalog API requests to", :type => String, :default => "http://www.infochimps.com", :env_var => "GEORGE", :no_help => true
  config.define 'catalog.key',        :description => "API key for the Catalog API", :type => String
  config.define 'catalog.secret',     :description => "API secret for the Catalog API", :type => String
end

.load_pluginsObject

Require all Ruby files in the directory Chimps.config.



53
54
55
56
57
58
59
# File 'lib/chimps/config.rb', line 53

def self.load_plugins
  return if Chimps.config[:skip_plugins]
  plugin_dirs = Chimps.config[:plugin_dirs]
  plugin_dirs.each do |dir|
    Dir[File.expand_path(dir) + "/*.rb"].each { |plugin| require plugin }
  end
end

.logLogger

The Chimps logger. Set via Chimps.config and defaults to $stdout.

Returns:

  • (Logger)


15
16
17
# File 'lib/chimps/utils.rb', line 15

def self.log
  @log ||= Log.new_logger
end

.log=(new_log) ⇒ Object

Set the Chimps logger.

Parameters:

  • new_log (Logger)


22
23
24
# File 'lib/chimps/utils.rb', line 22

def self.log= new_log
  @log = new_log
end

.verbose?true, ...

Is Chimps in verbose mode?

Returns:

  • (true, false, nil)


38
39
40
# File 'lib/chimps/config.rb', line 38

def self.verbose?
  config[:verbose]
end

.versionString

The current Chimps library version.

Returns:



45
46
47
48
49
# File 'lib/chimps/config.rb', line 45

def self.version
  return @version if @version
  version_path = File.join(File.dirname(__FILE__), '../../VERSION')
  @version ||= File.exist?(version_path) && File.new(version_path).read
end