quandl_client 2.7.11 → 2.7.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/.gitignore +7 -7
  2. data/.rspec +1 -1
  3. data/.travis.yml +20 -20
  4. data/.yardopts +2 -2
  5. data/Gemfile +12 -12
  6. data/Guardfile +8 -8
  7. data/LICENSE +7 -7
  8. data/README.md +303 -303
  9. data/Rakefile +31 -31
  10. data/UPGRADE.md +220 -214
  11. data/VERSION +1 -1
  12. data/examples/create.rb +32 -32
  13. data/examples/find.rb +17 -17
  14. data/examples/login.rb +12 -12
  15. data/examples/search.rb +12 -12
  16. data/examples/trims.rb +15 -15
  17. data/lib/quandl/client/base/attributes.rb +15 -15
  18. data/lib/quandl/client/base/model.rb +40 -40
  19. data/lib/quandl/client/base/search.rb +74 -74
  20. data/lib/quandl/client/base/validation.rb +103 -101
  21. data/lib/quandl/client/base.rb +91 -91
  22. data/lib/quandl/client/middleware/parse_json.rb +87 -85
  23. data/lib/quandl/client/middleware.rb +9 -9
  24. data/lib/quandl/client/models/dataset/data.rb +57 -57
  25. data/lib/quandl/client/models/dataset.rb +269 -269
  26. data/lib/quandl/client/models/location.rb +10 -10
  27. data/lib/quandl/client/models/report.rb +14 -14
  28. data/lib/quandl/client/models/scraper.rb +16 -16
  29. data/lib/quandl/client/models/sheet.rb +50 -50
  30. data/lib/quandl/client/models/source.rb +48 -48
  31. data/lib/quandl/client/models/superset.rb +65 -65
  32. data/lib/quandl/client/models/user.rb +7 -7
  33. data/lib/quandl/client/version.rb +14 -14
  34. data/lib/quandl/client.rb +54 -53
  35. data/lib/quandl/her/collection.rb +18 -0
  36. data/lib/quandl/her/remove_method_data.rb +8 -8
  37. data/lib/quandl/pattern/client.rb +8 -8
  38. data/lib/quandl/pattern.rb +37 -37
  39. data/quandl_client.gemspec +33 -33
  40. data/spec/factories/dataset.rb +10 -10
  41. data/spec/factories/sheet.rb +7 -7
  42. data/spec/factories/source.rb +9 -9
  43. data/spec/fixtures/scraper.rb +5 -5
  44. data/spec/lib/quandl/client/dataset/attributes_spec.rb +63 -63
  45. data/spec/lib/quandl/client/dataset/data_spec.rb +92 -92
  46. data/spec/lib/quandl/client/dataset/location_spec.rb +65 -65
  47. data/spec/lib/quandl/client/dataset/persistence_spec.rb +104 -104
  48. data/spec/lib/quandl/client/dataset/search_spec.rb +19 -19
  49. data/spec/lib/quandl/client/dataset/source_spec.rb +47 -47
  50. data/spec/lib/quandl/client/dataset/trim_spec.rb +35 -35
  51. data/spec/lib/quandl/client/dataset/validation_spec.rb +68 -68
  52. data/spec/lib/quandl/client/dataset_spec.rb +57 -57
  53. data/spec/lib/quandl/client/scraper_spec.rb +71 -71
  54. data/spec/lib/quandl/client/sheet_spec.rb +37 -37
  55. data/spec/lib/quandl/client/source_spec.rb +51 -51
  56. data/spec/spec_helper.rb +30 -30
  57. metadata +28 -4
@@ -1,86 +1,88 @@
1
- require 'json'
2
-
3
- module Quandl
4
- module Client
5
- module Middleware
6
-
7
- class ParseJSON < Faraday::Response::Middleware
8
-
9
- def on_complete(env)
10
- env[:body] = case env[:status]
11
- when 204
12
- parse('{}', env)
13
- else
14
- parse(env[:body], env)
15
- end
16
- end
17
-
18
- def parse(body, env)
19
- json = parse_json(body, env)
20
- json.has_key?(:docs) ? format_collection( json, env ) : format_record( json, env )
21
- end
22
-
23
- def format_record(json, env)
24
- errors = json.delete(:errors) || {}
25
- metadata = json.delete(:metadata) || {}
26
- # collect some response data
27
- metadata.merge!({
28
- status: env[:status],
29
- headers: env[:response_headers],
30
- })
31
- # return object
32
- object = {
33
- :data => json,
34
- :errors => errors,
35
- :metadata => metadata
36
- }
37
- env[:status] = 200
38
- object
39
- end
40
-
41
- def format_collection(json, env)
42
- errors = json.delete(:errors) || {}
43
- metadata = json.delete(:metadata) || {}
44
- docs = json.delete(:docs)
45
- # collect some response data
46
- metadata.merge!(json).merge!({
47
- status: env[:status],
48
- headers: env[:response_headers],
49
- })
50
- # each doc metadata references metadata
51
- docs.each{|d| d[:metadata] = metadata }
52
- # return object
53
- object = {
54
- :data => docs,
55
- :errors => errors,
56
- :metadata => metadata
57
- }
58
- env[:status] = 200
59
- object
60
- end
61
-
62
- def parse_json(body = nil, env)
63
- body ||= '{}'
64
- json = begin
65
- JSON.parse(body).symbolize_keys!
66
- rescue JSON::ParserError
67
- nil
68
- end
69
- # invalid json body?
70
- if json.blank?
71
- # fallback to error message
72
- json = {
73
- id: 1,
74
- errors: {
75
- parse_errors: [ "Quandl::Client::ParseJSON error. status: #{env[:status]}, body: #{body.inspect}" ]
76
- }
77
- }
78
- end
79
- json
80
- end
81
-
82
- end
83
-
84
- end
85
- end
1
+ require 'json'
2
+
3
+ module Quandl
4
+ module Client
5
+ module Middleware
6
+
7
+ class ParseJSON < Faraday::Response::Middleware
8
+
9
+ def on_complete(env)
10
+ env[:body] = case env[:status]
11
+ when 204
12
+ parse('{}', env)
13
+ else
14
+ parse(env[:body], env)
15
+ end
16
+ end
17
+
18
+ def parse(body, env)
19
+ json = parse_json(body, env)
20
+ json.has_key?(:docs) ? format_collection( json, env ) : format_record( json, env )
21
+ end
22
+
23
+ def format_record(json, env)
24
+ errors = json.delete(:errors) || {}
25
+ metadata = json.delete(:metadata) || {}
26
+ # collect some response data
27
+ metadata.merge!({
28
+ status: env[:status],
29
+ headers: env[:response_headers],
30
+ method: env[:method],
31
+ })
32
+ # return object
33
+ object = {
34
+ :data => json,
35
+ :errors => errors,
36
+ :metadata => metadata
37
+ }
38
+ env[:status] = 200
39
+ object
40
+ end
41
+
42
+ def format_collection(json, env)
43
+ errors = json.delete(:errors) || {}
44
+ metadata = json.delete(:metadata) || {}
45
+ docs = json.delete(:docs)
46
+ # collect some response data
47
+ metadata.merge!(json).merge!({
48
+ status: env[:status],
49
+ headers: env[:response_headers],
50
+ method: env[:method],
51
+ })
52
+ # each doc metadata references metadata
53
+ docs.each{|d| d[:metadata] = metadata }
54
+ # return object
55
+ object = {
56
+ :data => docs,
57
+ :errors => errors,
58
+ :metadata => metadata
59
+ }
60
+ env[:status] = 200
61
+ object
62
+ end
63
+
64
+ def parse_json(body = nil, env)
65
+ body ||= '{}'
66
+ json = begin
67
+ JSON.parse(body).symbolize_keys!
68
+ rescue JSON::ParserError
69
+ nil
70
+ end
71
+ # invalid json body?
72
+ if json.blank?
73
+ # fallback to error message
74
+ json = {
75
+ id: 1,
76
+ errors: {
77
+ parse_errors: [ "Quandl::Client::ParseJSON error. status: #{env[:status]}, body: #{body.inspect}" ]
78
+ }
79
+ }
80
+ end
81
+ json
82
+ end
83
+
84
+ end
85
+
86
+ end
87
+ end
86
88
  end
@@ -1,10 +1,10 @@
1
- require 'faraday'
2
- require 'quandl/client/middleware/parse_json'
3
-
4
- module Quandl
5
- module Client
6
- module Middleware
7
-
8
- end
9
- end
1
+ require 'faraday'
2
+ require 'quandl/client/middleware/parse_json'
3
+
4
+ module Quandl
5
+ module Client
6
+ module Middleware
7
+
8
+ end
9
+ end
10
10
  end
@@ -1,58 +1,58 @@
1
- class Quandl::Client::Dataset::Data < Quandl::Client::Base
2
-
3
- @_her_resource_path = "datasets/:id/data"
4
-
5
- has_scope_composer
6
-
7
- scope.class_eval do
8
- delegate *Quandl::Client::Dataset::Data.forwardable_scope_methods, :to_h, to: :to_table, allow_nil: true
9
- delegate *Quandl::Data.forwardable_methods, to: :to_table, allow_nil: true
10
- end
11
-
12
- scope *[:row, :rows, :limit, :offset, :accuracy, :column, :order,
13
- :transform, :collapse, :exclude_headers]
14
-
15
- scope :trim_start, ->(date){ date = parse_date(date); where( trim_start: date ) if date }
16
- scope :trim_end, ->(date){ date = parse_date(date); where( trim_end: date ) if date }
17
-
18
- scope_helper :parse_date, ->( value ){
19
- begin
20
- date = Date.jd(value.to_i) if value.kind_of?(String) && value.numeric?
21
- date = Date.jd(value) if value.is_a?(Integer)
22
- date = Date.parse(value) if value.is_a?(String) && value =~ /^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/
23
- date = value if value.is_a?(Date)
24
- date = value.to_date if value.respond_to?(:to_date)
25
- date.to_s
26
- rescue
27
- nil
28
- end
29
- }
30
-
31
- scope_helper :to_table, -> {
32
- data = fetch_once.data
33
- data.headers = fetch_once.column_names
34
- data
35
- }
36
-
37
- attributes :id, :limit, :collapse, :transformation, :trim_start, :trim_end,
38
- :rows, :row, :frequency, :data, :from_date, :to_date, :column_names
39
-
40
- def data
41
- read_data
42
- end
43
-
44
- def data=(value)
45
- write_data(value)
46
- end
47
-
48
- protected
49
-
50
- def read_data
51
- Quandl::Data.new( read_attribute(:data) )
52
- end
53
-
54
- def write_data(value )
55
- write_attribute(:data, Quandl::Data.new(value).to_csv )
56
- end
57
-
1
+ class Quandl::Client::Dataset::Data < Quandl::Client::Base
2
+
3
+ @_her_resource_path = "datasets/:id/data"
4
+
5
+ has_scope_composer
6
+
7
+ scope.class_eval do
8
+ delegate *Quandl::Client::Dataset::Data.forwardable_scope_methods, :to_h, to: :to_table, allow_nil: true
9
+ delegate *Quandl::Data.forwardable_methods, to: :to_table, allow_nil: true
10
+ end
11
+
12
+ scope *[:row, :rows, :limit, :offset, :accuracy, :column, :order,
13
+ :transform, :collapse, :exclude_headers]
14
+
15
+ scope :trim_start, ->(date){ date = parse_date(date); where( trim_start: date ) if date }
16
+ scope :trim_end, ->(date){ date = parse_date(date); where( trim_end: date ) if date }
17
+
18
+ scope_helper :parse_date, ->( value ){
19
+ begin
20
+ date = Date.jd(value.to_i) if value.kind_of?(String) && value.numeric?
21
+ date = Date.jd(value) if value.is_a?(Integer)
22
+ date = Date.parse(value) if value.is_a?(String) && value =~ /^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/
23
+ date = value if value.is_a?(Date)
24
+ date = value.to_date if value.respond_to?(:to_date)
25
+ date.to_s
26
+ rescue
27
+ nil
28
+ end
29
+ }
30
+
31
+ scope_helper :to_table, -> {
32
+ data = fetch_once.data
33
+ data.headers = fetch_once.column_names
34
+ data
35
+ }
36
+
37
+ attributes :id, :limit, :collapse, :transformation, :trim_start, :trim_end,
38
+ :rows, :row, :frequency, :data, :from_date, :to_date, :column_names
39
+
40
+ def data
41
+ read_data
42
+ end
43
+
44
+ def data=(value)
45
+ write_data(value)
46
+ end
47
+
48
+ protected
49
+
50
+ def read_data
51
+ Quandl::Data.new( read_attribute(:data) )
52
+ end
53
+
54
+ def write_data(value )
55
+ write_attribute(:data, Quandl::Data.new(value).to_csv )
56
+ end
57
+
58
58
  end