quandl 0.4.4 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/README.md +133 -318
- data/lib/quandl.rb +27 -0
- data/lib/quandl/api_config.rb +33 -0
- data/lib/quandl/connection.rb +75 -0
- data/lib/quandl/errors/quandl_error.rb +56 -0
- data/lib/quandl/model/base.rb +31 -0
- data/lib/quandl/model/data.rb +32 -0
- data/lib/quandl/model/database.rb +62 -0
- data/lib/quandl/model/dataset.rb +24 -0
- data/lib/quandl/model/list.rb +45 -0
- data/lib/quandl/operations/base.rb +17 -0
- data/lib/quandl/operations/get.rb +21 -0
- data/lib/quandl/operations/list.rb +23 -0
- data/lib/quandl/util.rb +35 -0
- data/lib/quandl/version.rb +3 -0
- metadata +78 -319
- data/.gitignore +0 -16
- data/.travis.yml +0 -20
- data/Gemfile +0 -14
- data/Guardfile +0 -8
- data/LICENSE +0 -7
- data/Rakefile +0 -27
- data/UPGRADE.md +0 -262
- data/VERSION +0 -1
- data/bin/quandl +0 -25
- data/config/locales/en.yml +0 -26
- data/dist/resources/pkg/Distribution.erb +0 -15
- data/dist/resources/pkg/PackageInfo.erb +0 -6
- data/dist/resources/pkg/postinstall.erb +0 -47
- data/dist/resources/pkg/quandl +0 -25
- data/dist/resources/ruby/PackageInfo +0 -3
- data/dist/resources/windows/quandl +0 -25
- data/lib/commander/command/quandl_ext.rb +0 -21
- data/lib/quandl/command.rb +0 -47
- data/lib/quandl/command/client.rb +0 -0
- data/lib/quandl/command/client_ext.rb +0 -1
- data/lib/quandl/command/client_ext/user.rb +0 -11
- data/lib/quandl/command/compatibility_check.rb +0 -11
- data/lib/quandl/command/config.rb +0 -92
- data/lib/quandl/command/presenter.rb +0 -75
- data/lib/quandl/command/presenter/helper.rb +0 -19
- data/lib/quandl/command/presenter/record.rb +0 -113
- data/lib/quandl/command/presenters/dataset_presenter.rb +0 -19
- data/lib/quandl/command/presenters/error_presenter.rb +0 -31
- data/lib/quandl/command/presenters/nil_class_presenter.rb +0 -10
- data/lib/quandl/command/presenters/scraper_presenter.rb +0 -25
- data/lib/quandl/command/presenters/superset_presenter.rb +0 -10
- data/lib/quandl/command/task.rb +0 -44
- data/lib/quandl/command/task/callbacks.rb +0 -28
- data/lib/quandl/command/task/clientable.rb +0 -51
- data/lib/quandl/command/task/commandable.rb +0 -103
- data/lib/quandl/command/task/configurable.rb +0 -80
- data/lib/quandl/command/task/dependable.rb +0 -71
- data/lib/quandl/command/task/inputable.rb +0 -37
- data/lib/quandl/command/task/logging.rb +0 -83
- data/lib/quandl/command/task/presentation.rb +0 -36
- data/lib/quandl/command/task/reportable.rb +0 -35
- data/lib/quandl/command/task/threading.rb +0 -123
- data/lib/quandl/command/task/translations.rb +0 -37
- data/lib/quandl/command/task/updatable.rb +0 -80
- data/lib/quandl/command/task/validations.rb +0 -25
- data/lib/quandl/command/tasks.rb +0 -24
- data/lib/quandl/command/tasks/delete.rb +0 -34
- data/lib/quandl/command/tasks/download.rb +0 -44
- data/lib/quandl/command/tasks/info.rb +0 -48
- data/lib/quandl/command/tasks/list.rb +0 -31
- data/lib/quandl/command/tasks/login.rb +0 -47
- data/lib/quandl/command/tasks/replace.rb +0 -58
- data/lib/quandl/command/tasks/schedule.rb +0 -211
- data/lib/quandl/command/tasks/search.rb +0 -39
- data/lib/quandl/command/tasks/superset.rb +0 -66
- data/lib/quandl/command/tasks/uninstall.rb +0 -17
- data/lib/quandl/command/tasks/update.rb +0 -249
- data/lib/quandl/command/tasks/upload.rb +0 -60
- data/lib/quandl/command/version.rb +0 -5
- data/lib/quandl/lang.rb +0 -45
- data/lib/quandl/utility.rb +0 -2
- data/lib/quandl/utility/config.rb +0 -43
- data/lib/quandl/utility/ruby_version.rb +0 -143
- data/quandl.gemspec +0 -43
- data/scripts/compile_ruby_pkg.sh +0 -34
- data/scripts/install.sh +0 -51
- data/scripts/win/quandl_toolbelt.iss +0 -89
- data/spec/config/output.rb +0 -21
- data/spec/config/quandl.rb +0 -67
- data/spec/factories/dataset.rb +0 -10
- data/spec/factories/source.rb +0 -10
- data/spec/fixtures/scraper-test-file.rb +0 -6
- data/spec/lib/quandl/command/delete_spec.rb +0 -45
- data/spec/lib/quandl/command/download_spec.rb +0 -49
- data/spec/lib/quandl/command/replace_spec.rb +0 -22
- data/spec/lib/quandl/command/schedule_spec.rb +0 -45
- data/spec/lib/quandl/command/superset_spec.rb +0 -28
- data/spec/lib/quandl/command/upload_spec.rb +0 -86
- data/spec/lib/quandl/command_spec.rb +0 -38
- data/spec/spec_helper.rb +0 -43
- data/tasks/toolbelt.rake +0 -138
- data/tasks/toolbelt.rb +0 -116
- data/tasks/toolbelt/build.rb +0 -2
- data/tasks/toolbelt/build/darwin.rb +0 -118
- data/tasks/toolbelt/build/ruby.rb +0 -105
- data/tasks/toolbelt/build/tarball.rb +0 -79
- data/tasks/toolbelt/build/windows.rb +0 -25
- data/tasks/toolbelt/push.rb +0 -18
- data/tasks/toolbelt/storage.rb +0 -28
- data/tasks/toolbelt/tar.rb +0 -21
@@ -1,47 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
|
3
|
-
usershell=$(dscl localhost -read /Local/Default/Users/$USER shell | sed -e 's/[^ ]* //')
|
4
|
-
|
5
|
-
startup_files() {
|
6
|
-
case $(basename $usershell) in
|
7
|
-
zsh)
|
8
|
-
echo ".zlogin .zshrc .zprofile .zshenv"
|
9
|
-
;;
|
10
|
-
bash)
|
11
|
-
echo ".bashrc .bash_profile .bash_login .profile"
|
12
|
-
;;
|
13
|
-
*)
|
14
|
-
echo ".bash_profile .zshrc .profile"
|
15
|
-
;;
|
16
|
-
esac
|
17
|
-
}
|
18
|
-
|
19
|
-
install_path() {
|
20
|
-
for file in $(startup_files); do
|
21
|
-
[ -f $HOME/$file ] || continue
|
22
|
-
(grep "Added by the Quandl" $HOME/$file >/dev/null) && break
|
23
|
-
|
24
|
-
cat <<MESSAGE >>$HOME/$file
|
25
|
-
|
26
|
-
### Added by the Quandl Toolbelt
|
27
|
-
export PATH="/usr/local/quandl/bin:\$PATH"
|
28
|
-
MESSAGE
|
29
|
-
|
30
|
-
# done after we add to one file
|
31
|
-
break
|
32
|
-
done
|
33
|
-
}
|
34
|
-
|
35
|
-
# if the toolbelt is not returned by `which`, let's add to the PATH
|
36
|
-
case $(which quandl) in
|
37
|
-
/usr/bin/quandl|/usr/local/quandl/bin/quandl)
|
38
|
-
;;
|
39
|
-
*)
|
40
|
-
install_path
|
41
|
-
;;
|
42
|
-
esac
|
43
|
-
|
44
|
-
# symlink binary to /usr/bin/quandl
|
45
|
-
ln -sf /usr/local/quandl/releases/<%= timestamp %> /usr/local/quandl/current
|
46
|
-
chown -h $USER /usr/local/quandl/current
|
47
|
-
ln -sf /usr/local/quandl/bin/quandl /usr/bin/quandl
|
data/dist/resources/pkg/quandl
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
#!/usr/local/quandl/ruby/bin/ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
require "pathname"
|
5
|
-
bin_file = Pathname.new(__FILE__).realpath
|
6
|
-
|
7
|
-
# vendored gems path
|
8
|
-
gem_dir = File.expand_path("../../current/vendor/gems", bin_file)
|
9
|
-
# vendored gems?
|
10
|
-
if Dir.exists?(gem_dir)
|
11
|
-
Dir["#{gem_dir}/**/lib"].each do |libdir|
|
12
|
-
$:.unshift libdir
|
13
|
-
end
|
14
|
-
else
|
15
|
-
require 'rubygems'
|
16
|
-
end
|
17
|
-
|
18
|
-
# add self to libpath
|
19
|
-
$:.unshift File.expand_path("../../current/lib", bin_file)
|
20
|
-
|
21
|
-
require 'quandl/command'
|
22
|
-
require 'commander/import'
|
23
|
-
require 'commander/command/quandl_ext'
|
24
|
-
|
25
|
-
include Quandl::Command
|
@@ -1,25 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
require "pathname"
|
5
|
-
bin_file = Pathname.new(__FILE__).realpath
|
6
|
-
|
7
|
-
# vendored gems path
|
8
|
-
gem_dir = File.expand_path("../../current/vendor/gems", bin_file)
|
9
|
-
# vendored gems?
|
10
|
-
if Dir.exists?(gem_dir)
|
11
|
-
Dir["#{gem_dir}/**/lib"].each do |libdir|
|
12
|
-
$:.unshift libdir
|
13
|
-
end
|
14
|
-
else
|
15
|
-
require 'rubygems'
|
16
|
-
end
|
17
|
-
|
18
|
-
# add self to libpath
|
19
|
-
$:.unshift File.expand_path("../../current/lib", bin_file)
|
20
|
-
|
21
|
-
require 'quandl/command'
|
22
|
-
require 'commander/import'
|
23
|
-
require 'commander/command/quandl_ext'
|
24
|
-
|
25
|
-
include Quandl::Command
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Commander
|
2
|
-
class Command
|
3
|
-
class Options
|
4
|
-
|
5
|
-
delegate :each, :to_a, :[], to: :to_h
|
6
|
-
|
7
|
-
def class
|
8
|
-
Commander::Command::Options
|
9
|
-
end
|
10
|
-
|
11
|
-
def try(key)
|
12
|
-
self.to_h[key.to_sym]
|
13
|
-
end
|
14
|
-
|
15
|
-
def to_h
|
16
|
-
__hash__
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/lib/quandl/command.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'pry' if ENV['BUNDLE_LOCAL_GEMS']
|
2
|
-
|
3
|
-
module Quandl
|
4
|
-
module Command
|
5
|
-
def self.root
|
6
|
-
@root ||= File.expand_path(File.join(File.dirname(__FILE__), '../../'))
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
require 'quandl/lang'
|
12
|
-
require "quandl/command/version"
|
13
|
-
require 'quandl/command/config'
|
14
|
-
require 'quandl/command/presenter'
|
15
|
-
require 'quandl/command/tasks'
|
16
|
-
|
17
|
-
Quandl::Logger.use(Quandl::Logger::Outputs)
|
18
|
-
I18n.enforce_available_locales = false
|
19
|
-
|
20
|
-
module Quandl::Command
|
21
|
-
extend ActiveSupport::Concern
|
22
|
-
|
23
|
-
included do
|
24
|
-
|
25
|
-
program :name, 'Quandl Toolbelt'
|
26
|
-
program :description, 'http://quandl.com/ command line interface.'
|
27
|
-
program :version, Quandl::Command::VERSION
|
28
|
-
|
29
|
-
default_command :help
|
30
|
-
|
31
|
-
global_option '-T', '--token STRING', 'secret token used to authenticate requests.'
|
32
|
-
global_option '-V', '--verbose', 'use detailed log output'
|
33
|
-
global_option '-U', '--url STRING', 'the API host that will be used'
|
34
|
-
global_option '-F', '--output-format STRING', 'the output format [ pipes, json, qdf ]'
|
35
|
-
global_option '-C', '--output-column INTEGER', 'the column to output'
|
36
|
-
global_option '-E', '--environment INTEGER', 'the environment to load'
|
37
|
-
global_option '--threads INTEGER', 'how many threads to use for concurrent operations'
|
38
|
-
global_option '--stdout STRING', 'where to redirect stdout'
|
39
|
-
global_option '--stderr STRING', 'where to redirect stderr'
|
40
|
-
global_option '--force-yes', 'force y/n with yes'
|
41
|
-
global_option '--sandbox', 'sandbox specific default options'
|
42
|
-
|
43
|
-
Tasks.each{|t| t.configure(self) }
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
File without changes
|
@@ -1 +0,0 @@
|
|
1
|
-
require 'quandl/command/client_ext/user'
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'quandl/utility/ruby_version'
|
2
|
-
|
3
|
-
err = "UNSUPPORTED ruby version (#{Quandl::Utility::RubyVersion.full_version}) Quandl Toolbelt requires ruby >="
|
4
|
-
|
5
|
-
if Quandl::Utility::RubyVersion <= '1.9.2'
|
6
|
-
puts "#{err} 1.9.3"
|
7
|
-
raise LoadError, "#{err} 1.9.3"
|
8
|
-
elsif Quandl::Utility::RubyVersion.is?(2.0) && Quandl::Utility::RubyVersion.patchlevel < 353
|
9
|
-
puts "#{err} 2.0.0-p353"
|
10
|
-
raise LoadError, "#{err} 2.0.0-p353"
|
11
|
-
end
|
@@ -1,92 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'yaml'
|
3
|
-
require 'ostruct'
|
4
|
-
require 'quandl/support/attributes'
|
5
|
-
|
6
|
-
module Quandl
|
7
|
-
module Command
|
8
|
-
class Config
|
9
|
-
|
10
|
-
include Quandl::Support::Attributes
|
11
|
-
|
12
|
-
define_attributes :token, :quandl_url, :last_checked_for_update, :output_format, :send_crash_reports, :stdout, :stderr
|
13
|
-
|
14
|
-
attr_accessor :options
|
15
|
-
|
16
|
-
def initialize(opts={})
|
17
|
-
self.options = opts.symbolize_keys
|
18
|
-
convert_legacy_config
|
19
|
-
ensure_directory_is_present
|
20
|
-
@attributes = read_config_from_file.stringify_keys
|
21
|
-
end
|
22
|
-
|
23
|
-
def stdout
|
24
|
-
options[:stdout] || read_attribute(:stdout)
|
25
|
-
end
|
26
|
-
|
27
|
-
def stderr
|
28
|
-
options[:stderr] || read_attribute(:stderr)
|
29
|
-
end
|
30
|
-
|
31
|
-
def quandl_url
|
32
|
-
return @quandl_url if @quandl_url.present?
|
33
|
-
@quandl_url = options[:url] if options[:url].present?
|
34
|
-
@quandl_url = ENV['QUANDL_URL'] if @quandl_url.blank?
|
35
|
-
@quandl_url = read_attribute(:quandl_url) if @quandl_url.blank?
|
36
|
-
@quandl_url = 'http://quandl.com/api/' if @quandl_url.blank?
|
37
|
-
@quandl_url
|
38
|
-
end
|
39
|
-
|
40
|
-
def auth_token
|
41
|
-
return @auth_token if @auth_token.present?
|
42
|
-
@auth_token = options[:token] if options[:token].present?
|
43
|
-
@auth_token = ENV['QUANDL_TOKEN'] if @auth_token.blank?
|
44
|
-
@auth_token = read_attribute(:token) if @auth_token.blank?
|
45
|
-
@auth_token
|
46
|
-
end
|
47
|
-
|
48
|
-
def request_platform
|
49
|
-
'sandbox' if options[:sandbox].present?
|
50
|
-
end
|
51
|
-
|
52
|
-
def file_path
|
53
|
-
options[:file_path]
|
54
|
-
end
|
55
|
-
|
56
|
-
def file_dir
|
57
|
-
File.dirname(file_path)
|
58
|
-
end
|
59
|
-
|
60
|
-
private
|
61
|
-
|
62
|
-
def ensure_directory_is_present
|
63
|
-
return if File.exists?(file_path)
|
64
|
-
FileUtils.mkdir(file_dir) unless Dir.exists?(file_dir)
|
65
|
-
File.write( file_path, YAML.dump({}) )
|
66
|
-
end
|
67
|
-
|
68
|
-
def convert_legacy_config
|
69
|
-
return if File.directory?(file_dir) || !File.exists?(file_dir)
|
70
|
-
# otherwise move the old .quandl into .quandl/config
|
71
|
-
FileUtils.mv(file_dir, "#{file_dir}.old")
|
72
|
-
FileUtils.mkdir(file_dir)
|
73
|
-
token = File.read("#{file_dir}.old")
|
74
|
-
File.write(file_path, "token: #{token}")
|
75
|
-
end
|
76
|
-
|
77
|
-
def write_attribute(*args)
|
78
|
-
super(*args)
|
79
|
-
write_config_to_file
|
80
|
-
end
|
81
|
-
|
82
|
-
def read_config_from_file
|
83
|
-
YAML.load(File.read(file_path))
|
84
|
-
end
|
85
|
-
|
86
|
-
def write_config_to_file
|
87
|
-
File.write( file_path, YAML.dump(attributes) )
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'quandl/command/presenter/helper'
|
2
|
-
require 'quandl/command/presenter/record'
|
3
|
-
|
4
|
-
require 'quandl/command/presenters/dataset_presenter'
|
5
|
-
require 'quandl/command/presenters/nil_class_presenter'
|
6
|
-
require 'quandl/command/presenters/error_presenter'
|
7
|
-
require 'quandl/command/presenters/scraper_presenter'
|
8
|
-
require 'quandl/command/presenters/superset_presenter'
|
9
|
-
|
10
|
-
module Quandl
|
11
|
-
module Command
|
12
|
-
class Presenter
|
13
|
-
|
14
|
-
class << self
|
15
|
-
|
16
|
-
def wrap_record_in_presenter(record, options)
|
17
|
-
klass = find_presenter_for_record(record, options)
|
18
|
-
klass.new(record, options)
|
19
|
-
end
|
20
|
-
|
21
|
-
def find_presenter_for_record(record, options={})
|
22
|
-
name = 'Error' if record.kind_of?(Exception)
|
23
|
-
name = options[:as] || record.class.name.to_s.split("::").last unless name.present?
|
24
|
-
"Quandl::Command::Presenters::#{name}Presenter".constantize rescue Quandl::Command::Presenter::Record
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
attr_accessor :options, :type
|
30
|
-
|
31
|
-
def initialize( object, opts={} )
|
32
|
-
self.type = ( object.try(:class) == Her::Collection ) ? :docs : :doc
|
33
|
-
self.options = { type: type }.merge( opts.symbolize_keys! )
|
34
|
-
self.collection = object
|
35
|
-
end
|
36
|
-
|
37
|
-
def each(&block)
|
38
|
-
collection.each do |presenter|
|
39
|
-
block.call( presenter )
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def each_to_format(type, &block)
|
44
|
-
collection.each do |record|
|
45
|
-
output = record.send("to_#{type}") if record.respond_to?("to_#{type}")
|
46
|
-
block.call( output, record.object )
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def to_format(type)
|
51
|
-
output = []
|
52
|
-
collection.each do |record|
|
53
|
-
output << record.send("to_#{type}") if record.respond_to?("to_#{type}")
|
54
|
-
end
|
55
|
-
output.join("\n")
|
56
|
-
end
|
57
|
-
|
58
|
-
def collection=(records)
|
59
|
-
@collection = []
|
60
|
-
records = Array(records).flatten
|
61
|
-
records.each do |record|
|
62
|
-
@collection << self.class.wrap_record_in_presenter(record, options)
|
63
|
-
end
|
64
|
-
# present nil if the collection is empty
|
65
|
-
@collection = [self.class.wrap_record_in_presenter( nil, options )] if @collection.blank?
|
66
|
-
@collection
|
67
|
-
end
|
68
|
-
|
69
|
-
def collection
|
70
|
-
@collection ||= []
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Quandl
|
2
|
-
module Command
|
3
|
-
class Presenter
|
4
|
-
class << self
|
5
|
-
def pretty_errors(messages)
|
6
|
-
result = []
|
7
|
-
re = messages.delete(:response_errors) if messages.is_a?(Hash) && messages.has_key?(:response_errors)
|
8
|
-
re.each{|k,v| messages[k] = v } if re.present? && re.is_a?(Hash)
|
9
|
-
# format
|
10
|
-
messages.each do |k,v|
|
11
|
-
v = v.join(" & ") if v.respond_to?(:join)
|
12
|
-
result << "#{k}: #{v}"
|
13
|
-
end
|
14
|
-
result.join(", ")
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,113 +0,0 @@
|
|
1
|
-
module Quandl
|
2
|
-
module Command
|
3
|
-
class Presenter
|
4
|
-
|
5
|
-
class Record
|
6
|
-
|
7
|
-
attr_accessor :object, :options
|
8
|
-
|
9
|
-
def initialize(*args)
|
10
|
-
self.options = args.extract_options!
|
11
|
-
self.object = args.first
|
12
|
-
end
|
13
|
-
|
14
|
-
# supported formats
|
15
|
-
|
16
|
-
def to_format(f)
|
17
|
-
self.send("to_#{f}") if self.respond_to?("to_#{f}")
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
def to_pipes
|
22
|
-
column = options[:output_column] if options.present? && options.is_a?(Hash)
|
23
|
-
pipes = as_pipes.dup.compact
|
24
|
-
pipes = [ pipes[ column.to_i ] ] if column.present? && column.to_s.numeric?
|
25
|
-
pipes.join(" | ")
|
26
|
-
end
|
27
|
-
|
28
|
-
def to_stderr
|
29
|
-
as_stderr
|
30
|
-
end
|
31
|
-
|
32
|
-
def as_stderr
|
33
|
-
output = ''
|
34
|
-
output += "#{id}\n" if id.present?
|
35
|
-
output += "#{detail}\n" if detail.present?
|
36
|
-
output += errors if errors.present?
|
37
|
-
output += object.to_s if object.kind_of?(Exception)
|
38
|
-
output += object.backtrace.join("\n") if object.respond_to?(:backtrace) && options[:trace] == true
|
39
|
-
output += "\n---\n"
|
40
|
-
end
|
41
|
-
|
42
|
-
def to_qdf
|
43
|
-
object.try(:to_qdf)
|
44
|
-
end
|
45
|
-
|
46
|
-
def to_csv
|
47
|
-
object.try(:to_csv)
|
48
|
-
end
|
49
|
-
|
50
|
-
def to_json
|
51
|
-
as_json.try(:to_json)
|
52
|
-
end
|
53
|
-
|
54
|
-
def as_pipes
|
55
|
-
[ status, id, detail, message ]
|
56
|
-
end
|
57
|
-
|
58
|
-
def as_json
|
59
|
-
json = { status: status, id: id, detail: detail, message: message }
|
60
|
-
json[:attributes] = object.attributes if object.respond_to?(:attributes)
|
61
|
-
json[:metadata] = object.metadata if object.respond_to?(:metadata)
|
62
|
-
json[:errors] = object.error_messages if object.respond_to?(:error_messages)
|
63
|
-
json
|
64
|
-
end
|
65
|
-
|
66
|
-
# default attribute mappings
|
67
|
-
|
68
|
-
def valid?
|
69
|
-
return true if object.nil?
|
70
|
-
return true if [200,201,404].include?(object.try(:status))
|
71
|
-
false
|
72
|
-
end
|
73
|
-
|
74
|
-
def status
|
75
|
-
return Quandl::Client::HTTP_STATUS_CODES[422] if object.try(:errors).try(:present?)
|
76
|
-
return object.try(:human_status) if object.respond_to?(:human_status) && object.human_status.present?
|
77
|
-
Quandl::Client::HTTP_STATUS_CODES[404]
|
78
|
-
end
|
79
|
-
|
80
|
-
def id
|
81
|
-
object.try(:id)
|
82
|
-
end
|
83
|
-
|
84
|
-
def message
|
85
|
-
errors_without_spaces
|
86
|
-
end
|
87
|
-
|
88
|
-
def detail
|
89
|
-
end
|
90
|
-
|
91
|
-
def errors_without_spaces
|
92
|
-
errors.to_s.gsub("\n", ' ')
|
93
|
-
end
|
94
|
-
|
95
|
-
def errors
|
96
|
-
messages = object.try(:error_messages) || []
|
97
|
-
# extract response errors
|
98
|
-
Presenter.pretty_errors(messages)
|
99
|
-
end
|
100
|
-
|
101
|
-
def docs?
|
102
|
-
options[:type] == :docs
|
103
|
-
end
|
104
|
-
|
105
|
-
def doc?
|
106
|
-
options[:type] == :doc
|
107
|
-
end
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|