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.
Files changed (107) hide show
  1. checksums.yaml +5 -13
  2. data/README.md +133 -318
  3. data/lib/quandl.rb +27 -0
  4. data/lib/quandl/api_config.rb +33 -0
  5. data/lib/quandl/connection.rb +75 -0
  6. data/lib/quandl/errors/quandl_error.rb +56 -0
  7. data/lib/quandl/model/base.rb +31 -0
  8. data/lib/quandl/model/data.rb +32 -0
  9. data/lib/quandl/model/database.rb +62 -0
  10. data/lib/quandl/model/dataset.rb +24 -0
  11. data/lib/quandl/model/list.rb +45 -0
  12. data/lib/quandl/operations/base.rb +17 -0
  13. data/lib/quandl/operations/get.rb +21 -0
  14. data/lib/quandl/operations/list.rb +23 -0
  15. data/lib/quandl/util.rb +35 -0
  16. data/lib/quandl/version.rb +3 -0
  17. metadata +78 -319
  18. data/.gitignore +0 -16
  19. data/.travis.yml +0 -20
  20. data/Gemfile +0 -14
  21. data/Guardfile +0 -8
  22. data/LICENSE +0 -7
  23. data/Rakefile +0 -27
  24. data/UPGRADE.md +0 -262
  25. data/VERSION +0 -1
  26. data/bin/quandl +0 -25
  27. data/config/locales/en.yml +0 -26
  28. data/dist/resources/pkg/Distribution.erb +0 -15
  29. data/dist/resources/pkg/PackageInfo.erb +0 -6
  30. data/dist/resources/pkg/postinstall.erb +0 -47
  31. data/dist/resources/pkg/quandl +0 -25
  32. data/dist/resources/ruby/PackageInfo +0 -3
  33. data/dist/resources/windows/quandl +0 -25
  34. data/lib/commander/command/quandl_ext.rb +0 -21
  35. data/lib/quandl/command.rb +0 -47
  36. data/lib/quandl/command/client.rb +0 -0
  37. data/lib/quandl/command/client_ext.rb +0 -1
  38. data/lib/quandl/command/client_ext/user.rb +0 -11
  39. data/lib/quandl/command/compatibility_check.rb +0 -11
  40. data/lib/quandl/command/config.rb +0 -92
  41. data/lib/quandl/command/presenter.rb +0 -75
  42. data/lib/quandl/command/presenter/helper.rb +0 -19
  43. data/lib/quandl/command/presenter/record.rb +0 -113
  44. data/lib/quandl/command/presenters/dataset_presenter.rb +0 -19
  45. data/lib/quandl/command/presenters/error_presenter.rb +0 -31
  46. data/lib/quandl/command/presenters/nil_class_presenter.rb +0 -10
  47. data/lib/quandl/command/presenters/scraper_presenter.rb +0 -25
  48. data/lib/quandl/command/presenters/superset_presenter.rb +0 -10
  49. data/lib/quandl/command/task.rb +0 -44
  50. data/lib/quandl/command/task/callbacks.rb +0 -28
  51. data/lib/quandl/command/task/clientable.rb +0 -51
  52. data/lib/quandl/command/task/commandable.rb +0 -103
  53. data/lib/quandl/command/task/configurable.rb +0 -80
  54. data/lib/quandl/command/task/dependable.rb +0 -71
  55. data/lib/quandl/command/task/inputable.rb +0 -37
  56. data/lib/quandl/command/task/logging.rb +0 -83
  57. data/lib/quandl/command/task/presentation.rb +0 -36
  58. data/lib/quandl/command/task/reportable.rb +0 -35
  59. data/lib/quandl/command/task/threading.rb +0 -123
  60. data/lib/quandl/command/task/translations.rb +0 -37
  61. data/lib/quandl/command/task/updatable.rb +0 -80
  62. data/lib/quandl/command/task/validations.rb +0 -25
  63. data/lib/quandl/command/tasks.rb +0 -24
  64. data/lib/quandl/command/tasks/delete.rb +0 -34
  65. data/lib/quandl/command/tasks/download.rb +0 -44
  66. data/lib/quandl/command/tasks/info.rb +0 -48
  67. data/lib/quandl/command/tasks/list.rb +0 -31
  68. data/lib/quandl/command/tasks/login.rb +0 -47
  69. data/lib/quandl/command/tasks/replace.rb +0 -58
  70. data/lib/quandl/command/tasks/schedule.rb +0 -211
  71. data/lib/quandl/command/tasks/search.rb +0 -39
  72. data/lib/quandl/command/tasks/superset.rb +0 -66
  73. data/lib/quandl/command/tasks/uninstall.rb +0 -17
  74. data/lib/quandl/command/tasks/update.rb +0 -249
  75. data/lib/quandl/command/tasks/upload.rb +0 -60
  76. data/lib/quandl/command/version.rb +0 -5
  77. data/lib/quandl/lang.rb +0 -45
  78. data/lib/quandl/utility.rb +0 -2
  79. data/lib/quandl/utility/config.rb +0 -43
  80. data/lib/quandl/utility/ruby_version.rb +0 -143
  81. data/quandl.gemspec +0 -43
  82. data/scripts/compile_ruby_pkg.sh +0 -34
  83. data/scripts/install.sh +0 -51
  84. data/scripts/win/quandl_toolbelt.iss +0 -89
  85. data/spec/config/output.rb +0 -21
  86. data/spec/config/quandl.rb +0 -67
  87. data/spec/factories/dataset.rb +0 -10
  88. data/spec/factories/source.rb +0 -10
  89. data/spec/fixtures/scraper-test-file.rb +0 -6
  90. data/spec/lib/quandl/command/delete_spec.rb +0 -45
  91. data/spec/lib/quandl/command/download_spec.rb +0 -49
  92. data/spec/lib/quandl/command/replace_spec.rb +0 -22
  93. data/spec/lib/quandl/command/schedule_spec.rb +0 -45
  94. data/spec/lib/quandl/command/superset_spec.rb +0 -28
  95. data/spec/lib/quandl/command/upload_spec.rb +0 -86
  96. data/spec/lib/quandl/command_spec.rb +0 -38
  97. data/spec/spec_helper.rb +0 -43
  98. data/tasks/toolbelt.rake +0 -138
  99. data/tasks/toolbelt.rb +0 -116
  100. data/tasks/toolbelt/build.rb +0 -2
  101. data/tasks/toolbelt/build/darwin.rb +0 -118
  102. data/tasks/toolbelt/build/ruby.rb +0 -105
  103. data/tasks/toolbelt/build/tarball.rb +0 -79
  104. data/tasks/toolbelt/build/windows.rb +0 -25
  105. data/tasks/toolbelt/push.rb +0 -18
  106. data/tasks/toolbelt/storage.rb +0 -28
  107. data/tasks/toolbelt/tar.rb +0 -21
@@ -1,37 +0,0 @@
1
- module Quandl
2
- module Command
3
- class Task
4
-
5
- module Inputable
6
-
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
- end
11
-
12
- module ClassMethods
13
- end
14
-
15
- def each_line_in_background(args, &block)
16
- args.each_line do |arg|
17
- background_job do
18
- block.call( arg )
19
- end
20
- end
21
- end
22
-
23
- def args_or_stdin
24
- return args.join("\n") if args.first.present?
25
- $stdin
26
- end
27
-
28
- def file_or_stdin
29
- return File.open( args.first, 'r' ) if args.first.present?
30
- $stdin
31
- end
32
-
33
- end
34
-
35
- end
36
- end
37
- end
@@ -1,83 +0,0 @@
1
- module Quandl
2
- module Command
3
- class Task
4
-
5
- module Logging
6
-
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
- before_call :start_request_timer
11
- before_execute :configure_logger
12
- after_call :log_request_time
13
-
14
- attr_accessor :request_timer
15
-
16
- end
17
-
18
- def start_request_timer
19
- self.request_timer = Time.now
20
- end
21
-
22
- def configure_logger
23
- @stderr_logger = initialize_logger(config.stderr) if config.stderr.present?
24
- @stdout_logger = initialize_logger(config.stdout) if config.stdout.present?
25
- end
26
-
27
- def initialize_logger(path)
28
- l = ::Logger.new( path, 2, 52428800 )
29
- l.formatter = proc do |severity, datetime, progname, msg|
30
- "# [#{datetime.strftime("%Y-%m-%d %H:%M:%S")}]\n#{msg}"
31
- end
32
- l
33
- end
34
-
35
- def log_request_time
36
- debug("Started: #{request_timer}. Finished: #{Time.now}. Elapsed: #{request_timer.elapsed_ms}")
37
- end
38
-
39
- def summarize(item)
40
- return summarize_hash(item) if item.kind_of?(Hash)
41
- item
42
- end
43
-
44
- def summarize_hash(item)
45
- item.collect do |k,v|
46
- next "#{k}: '#{v}'" if v.kind_of?(String)
47
- "#{k}: #{v}"
48
- end.join(', ')
49
- end
50
-
51
- def table(*args)
52
- Array(args).flatten.join(" | ")
53
- end
54
-
55
- def info(*args)
56
- logger.info(*args)
57
- end
58
-
59
- def debug(*args)
60
- args.each{|a| logger.debug("# #{a}") } if verbose?
61
- end
62
-
63
- def error(*args)
64
- stderr_logger.error(*args)
65
- end
66
-
67
- def fatal(*args)
68
- stderr_logger.fatal("FATAL: #{args.join(" ")}")
69
- end
70
-
71
- def logger
72
- @stdout_logger ||= Quandl::Logger
73
- end
74
-
75
- def stderr_logger
76
- @stderr_logger ||= Quandl::Logger
77
- end
78
-
79
- end
80
-
81
- end
82
- end
83
- end
@@ -1,36 +0,0 @@
1
- module Quandl
2
- module Command
3
- class Task
4
-
5
- module Presentation
6
-
7
- extend ActiveSupport::Concern
8
-
9
- def present(object, opts={})
10
- opts = opts.symbolize_keys!
11
- opts.reverse_merge!(options.to_h) if options.to_h.present?
12
- presenters = Quandl::Command::Presenter.new( object, opts )
13
- # format order of importance
14
- format = get_output_format( opts )
15
- # convert each object to_format and write to stdout
16
- presenters.each do |presenter|
17
- # write requested format to stdout
18
- info( presenter.to_format(format) )
19
- # write errors to stderr
20
- error( presenter.to_stderr ) unless presenter.valid?
21
- end
22
- end
23
-
24
- private
25
-
26
- def get_output_format(override={})
27
- format = options.output_format || config.output_format || override[:output_format] || 'pipes'
28
- format = 'pipes' unless %w{ pipes json qdf }.include?(format.to_s)
29
- format
30
- end
31
-
32
- end
33
-
34
- end
35
- end
36
- end
@@ -1,35 +0,0 @@
1
- module Quandl
2
- module Command
3
- class Task
4
-
5
- module Reportable
6
-
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
- before_execute :ask_to_send_crash_reports
11
- end
12
-
13
- def ask_to_send_crash_reports
14
- if config.send_crash_reports.nil?
15
- status = ['y','yes'].include? ask("Do you want to send crash reports if toolbelt fails? (y/n)").to_s.strip.rstrip.downcase
16
- config.send_crash_reports = status
17
- end
18
- end
19
-
20
- def call
21
- begin
22
- super
23
- rescue Exception => err
24
- if config.send_crash_reports == true
25
- Quandl::Client::Report.create( message: err.to_s, full_message: err.backtrace ) rescue nil
26
- end
27
- raise $!, "#{$!}", $!.backtrace
28
- end
29
- end
30
-
31
- end
32
-
33
- end
34
- end
35
- end
@@ -1,123 +0,0 @@
1
- module Quandl
2
- module Command
3
- class Task
4
-
5
- module Threading
6
-
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
-
11
- before_execute :force_load_json_support
12
- before_execute :shutdown_thread_pool_on_sigint
13
-
14
- after_execute :shutdown_thread_pool_uninterruptedly!
15
-
16
- end
17
-
18
- module ClassMethods
19
- end
20
-
21
- def shutdown_thread_pool_on_sigint
22
- debug("starting up with #{threads} threads")
23
- return unless threads?
24
- trap('SIGINT') do
25
- debug "exit signal received"
26
- unless thread_pool.shutdown?
27
- debug "waiting for executing jobs to finish"
28
- thread_pool.shutdown
29
- end
30
- debug "exiting now"
31
- exit
32
- end
33
- end
34
-
35
- def background_job(*args, &block)
36
- # dont execute jobs when shutdown signaled
37
- return false if exiting?
38
- # options
39
- opts = args.extract_options!.symbolize_keys!
40
- key = opts[:lock]
41
- # without threads process in foreground
42
- return block.call unless threads?
43
- # process with pool
44
- job = thread_pool.process do
45
- # wait for lock
46
- await_thread_pool_lock!(key) if key.present?
47
- # if this key is locked
48
- block.call
49
- # unlock
50
- release_thread_pool_lock(key) if key.present?
51
- end
52
- # onwards
53
- job
54
- end
55
-
56
- def mutex
57
- @mutex ||= Mutex.new
58
- end
59
-
60
- def await_thread_pool_lock!(key)
61
- got_lock = false
62
- # try to get a lock
63
- mutex.synchronize do
64
- unless thread_pool_locked?(key)
65
- obtain_thread_pool_lock(key)
66
- got_lock = true
67
- end
68
- end
69
- # try again unless lock was obtained
70
- if !got_lock
71
- sleep(0.05)
72
- await_thread_pool_lock!(key)
73
- end
74
- end
75
-
76
- def thread_pool
77
- @thread_pool ||= Thread.pool( threads )
78
- end
79
-
80
- def obtain_thread_pool_lock(key)
81
- thread_pool_locks[key] = true
82
- end
83
-
84
- def release_thread_pool_lock(key)
85
- thread_pool_locks.delete(key)
86
- end
87
-
88
- def thread_pool_locked?(key)
89
- thread_pool_locks[key] == true
90
- end
91
-
92
- def thread_pool_locks
93
- @thread_pool_locks ||= {}
94
- end
95
-
96
- def threads?
97
- threads > 1
98
- end
99
-
100
- def threads
101
- @threads ||= options.threads.present? ? options.threads.to_i : 10
102
- end
103
-
104
- def exiting?
105
- threads? && thread_pool.shutdown?
106
- end
107
-
108
- def force_load_json_support
109
- { force_load: true }.to_json rescue nil
110
- end
111
-
112
- protected
113
-
114
- def shutdown_thread_pool_uninterruptedly!
115
- return false unless Thread.respond_to?(:pool)
116
- thread_pool.shutdown unless exiting?
117
- end
118
-
119
- end
120
-
121
- end
122
- end
123
- end
@@ -1,37 +0,0 @@
1
- module Quandl
2
- module Command
3
- class Task
4
-
5
- module Translations
6
-
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
-
11
- end
12
-
13
- module ClassMethods
14
-
15
- def t(key)
16
- key = key.to_s
17
- translation = lang
18
- key.split('.').each{|m| translation = translation.respond_to?(m) ? translation.send(m) : nil }
19
- translation
20
- end
21
-
22
- def lang
23
- @lang ||= Quandl::Lang.send(language).quandl.command.tasks.send(command_name)
24
- end
25
-
26
- def language
27
- # stub
28
- 'en'
29
- end
30
-
31
- end
32
-
33
- end
34
-
35
- end
36
- end
37
- end
@@ -1,80 +0,0 @@
1
- module Quandl
2
- module Command
3
- class Task
4
-
5
- module Updatable
6
-
7
- extend ActiveSupport::Concern
8
-
9
- VERSION_URL="https://s3.amazonaws.com/quandl-command/VERSION"
10
-
11
- included do
12
- before_execute :check_for_update_once_daily
13
- end
14
-
15
- def check_for_update_once_daily
16
- # short circuit
17
- return if options.sandbox
18
- # onwards
19
- check_time = config.last_checked_for_update
20
- # check time present?
21
- if check_time.present? && check_time.is_a?(Time)
22
- # has it been more than one day?
23
- check_for_update if Time.now - 1.day > check_time || check_time > Time.now
24
- else
25
- check_for_update
26
- end
27
- end
28
-
29
- def check_for_update
30
- # notify user of impending update check
31
- print("# Checking for updates ... ")
32
- # lazy load dependencies since this happens infrequently
33
- require_check_for_update_dependencies
34
- # build request
35
- http, request = prepare_update_request
36
- # send request
37
- response = send_update_request(http, request)
38
- # handle output
39
- handle_update_response(response)
40
- rescue => err
41
- info("An unexpected error occured while checking for updates ... #{err}")
42
- info err.backtrace.join("\n") if trace?
43
- ensure
44
- config.last_checked_for_update = Time.now
45
- end
46
-
47
- private
48
-
49
- def require_check_for_update_dependencies
50
- require 'uri'
51
- require 'net/http'
52
- require 'open-uri'
53
- end
54
-
55
- def prepare_update_request
56
- uri = URI.parse( VERSION_URL )
57
- http = Net::HTTP.new(uri.host, uri.port)
58
- http.use_ssl = true
59
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
60
- [ http, Net::HTTP::Get.new(uri.request_uri) ]
61
- end
62
-
63
- def send_update_request(http, request)
64
- # send request
65
- response = http.request(request)
66
- # fetch version number
67
- response.body.strip.rstrip
68
- end
69
-
70
- def handle_update_response(response)
71
- return info(" you are up to date! #{response}") if Quandl::Command::VERSION == response
72
- # otherwise they are out of sync
73
- info(" A new version of quandl toolbelt has been released. #{response}. Please run 'quandl update'")
74
- end
75
-
76
- end
77
-
78
- end
79
- end
80
- end
@@ -1,25 +0,0 @@
1
- module Quandl
2
- module Command
3
- class Task
4
-
5
- module Validations
6
-
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
- before_execute :run_task_validations!
11
- end
12
-
13
- def run_task_validations!
14
- unless valid?
15
- debug("run_task_validations! valid? false")
16
- error( table(errors.full_messages) )
17
- false
18
- end
19
- end
20
-
21
- end
22
-
23
- end
24
- end
25
- end