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
-
.boot! ⇒ Object
Load and resolve configuration.
-
.config ⇒ Configliere::Param
Chimps configuration.
- .define_config ⇒ Object
-
.load_plugins ⇒ Object
Require all Ruby files in the directory Chimps.config.
-
.log ⇒ Logger
The Chimps logger.
-
.log=(new_log) ⇒ Object
Set the Chimps logger.
-
.username ⇒ String
The username Chimps will pass to Infochimps.
-
.verbose? ⇒ true, ...
Is Chimps in verbose mode?.
-
.version ⇒ String
The current Chimps library version.
Class Method Details
.boot! ⇒ Object
Load and resolve configuration.
21 22 23 24 25 26 27 |
# File 'lib/chimps.rb', line 21 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.resolve! config[:dataset] = config[:site] if (! config[:dataset]) && config[:site] # backwards compatibility true end |
.config ⇒ Configliere::Param
Chimps configuration. Managed by Configliere
9 10 11 |
# File 'lib/chimps/config.rb', line 9 def self.config @config ||= Configliere.new end |
.define_config ⇒ Object
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.("~/.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 'dataset.username', :description => "Your Infochimps username", :type => String config.define 'dataset.host', :description => "Host to send Dataset API requests to", :type => String, :default => "http://www.infochimps.com", :env_var => "GEORGE", :no_help => true config.define 'dataset.key', :description => "API key for the Dataset API", :type => String config.define 'dataset.secret', :description => "API secret for the Dataset API", :type => String end |
.load_plugins ⇒ Object
Require all Ruby files in the directory Chimps.config.
60 61 62 63 64 65 66 |
# File 'lib/chimps/config.rb', line 60 def self.load_plugins return if Chimps.config[:skip_plugins] plugin_dirs = Chimps.config[:plugin_dirs] plugin_dirs.each do |dir| Dir[File.(dir) + "/*.rb"].each { |plugin| require plugin } end end |
.log ⇒ Logger
The Chimps logger. Set via Chimps.config and defaults to $stdout.
16 17 18 |
# File 'lib/chimps/utils.rb', line 16 def self.log @log ||= Log.new_logger end |
.log=(new_log) ⇒ Object
Set the Chimps logger.
23 24 25 |
# File 'lib/chimps/utils.rb', line 23 def self.log= new_log @log = new_log end |
.username ⇒ String
The username Chimps will pass to Infochimps.
45 46 47 |
# File 'lib/chimps/config.rb', line 45 def self.username config[:dataset][:username] or raise AuthenticationError.new("No Dataset API username set in #{Chimps.config[:config]} or #{Chimps.config[:site_config]}") end |
.verbose? ⇒ true, ...
Is Chimps in verbose mode?
38 39 40 |
# File 'lib/chimps/config.rb', line 38 def self.verbose? config[:verbose] end |
.version ⇒ String
The current Chimps library version.
52 53 54 55 56 |
# File 'lib/chimps/config.rb', line 52 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 |