quandl_cassinatra 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 45ca43fd651a20aa4d3080d9c1014e6ed72aa856
4
+ data.tar.gz: 73f0f991491d825d937f72dc00bcc85bed694a8f
5
+ SHA512:
6
+ metadata.gz: 01debd1e9b40f1d9663880e720ecd9d3f10377314fc46328eaf96064b039a7cc5b6a6a172b6201d5c059fd3ea6c04065497b293aa8fba5517d6b59dbe04a56c8
7
+ data.tar.gz: d31b1ab614e56d96871d88f3ee96e364537cf55632ef1be67c5fa5e25fc580c7e19ef1e69e6050a985c048785eb39c0b6d5197d7b9d188dc5d0e5ca7e511dd70
@@ -11,7 +11,7 @@ module Cassinatra
11
11
  api = Her::API.new
12
12
  api.setup url: rest_url do |c|
13
13
  c.use Faraday::Request::UrlEncoded
14
- c.use Her::Middleware::DefaultParseJSON
14
+ c.use Quandl::Cassinatra::Middleware::ParseJSON
15
15
  c.use Faraday::Adapter::NetHttp
16
16
  end
17
17
  end
@@ -0,0 +1,51 @@
1
+ module Quandl
2
+ module Cassinatra
3
+ module Middleware
4
+
5
+ class ParseJSON < Faraday::Response::Middleware
6
+
7
+ def on_complete(env)
8
+ env[:body] = case env[:status]
9
+ when 204
10
+ parse('{}', env)
11
+ else
12
+ parse(env[:body], env)
13
+ end
14
+ end
15
+
16
+ def parse(body, env)
17
+ json = parse_json(body)
18
+ errors = json.delete(:errors) || {}
19
+ metadata = json.delete(:metadata) || {}
20
+ # collect some response data
21
+ metadata.merge!({
22
+ status: env[:status],
23
+ headers: env[:response_headers],
24
+ })
25
+ # return object
26
+ object = {
27
+ :data => json,
28
+ :errors => errors,
29
+ :metadata => metadata
30
+ }
31
+ env[:status] = 200
32
+ object
33
+ end
34
+
35
+ def parse_json(body = nil)
36
+ body ||= '{}'
37
+ message = "Response from the API must behave like a Hash or an Array (last JSON response was #{body.inspect})"
38
+
39
+ json = begin
40
+ Yajl.load(body, :symbolize_keys => true)
41
+ rescue Yajl::ParseError
42
+ { id: 1, errors: { parse_error: message } }
43
+ end
44
+ json
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,10 @@
1
+ require 'faraday'
2
+ require 'quandl/cassinatra/middleware/parse_json'
3
+
4
+ module Quandl
5
+ module Cassinatra
6
+ module Middleware
7
+
8
+ end
9
+ end
10
+ end
@@ -60,11 +60,17 @@ module Searchable
60
60
  }
61
61
 
62
62
  search_helper :format_trim_date, ->( date, start_or_end ){
63
+ # parse
63
64
  date = Date.jd(date.to_i) if date.kind_of?(String) && date.numeric?
64
65
  date = Date.jd(date) if date.is_a?(Integer)
65
- date = Date.parse(date) if date.is_a?(String)
66
- date = date.send("#{start_or_end}_of_frequency", collapse) if collapse.present?
67
- date.jd
66
+ date = Date.parse(date) if date.is_a?(String) && date =~ /^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/
67
+ # format
68
+ if date.is_a?(Date)
69
+ date = date.send("#{start_or_end}_of_frequency", collapse) if collapse.present?
70
+ date.jd
71
+ else
72
+ nil
73
+ end
68
74
  }
69
75
 
70
76
  search_helper :find, ->(id){
@@ -1,5 +1,5 @@
1
1
  module Quandl
2
2
  module Cassinatra
3
- VERSION = '0.1.9'
3
+ VERSION = '0.1.10'
4
4
  end
5
5
  end
@@ -13,6 +13,7 @@ require 'scope_composer'
13
13
  require "quandl/data"
14
14
 
15
15
  require "quandl/cassinatra/core_ext"
16
+ require 'quandl/cassinatra/middleware'
16
17
 
17
18
  require 'quandl/cassinatra/concerns'
18
19
  require 'quandl/cassinatra/her'
@@ -50,6 +50,14 @@ describe Dataset do
50
50
  date = Date.today.jd
51
51
  Dataset.trim_start(date).attributes[:trim_start].should eq Date.today.jd
52
52
  end
53
+
54
+ it "should reject invalid date" do
55
+ Dataset.trim_start("").attributes[:trim_start].should eq nil
56
+ end
57
+
58
+ it "should reject invalid date" do
59
+ Dataset.trim_start("asdf").attributes[:trim_start].should eq nil
60
+ end
53
61
 
54
62
  end
55
63
 
@@ -19,10 +19,12 @@ describe Multiset do
19
19
 
20
20
  it "should be in the right order" do
21
21
  m = Multiset.columns("#{d2.id.to_i}.1,#{d1.id.to_i}.1,#{d2.id.to_i}.3,#{d1.id.to_i}.2").to_dataset
22
- c1 = Dataset.find(d1.id).column_ids
23
- c2 = Dataset.find(d2.id).column_ids
24
- requested_order = [ c2[0], c1[0], c2[2], c1[1] ]
25
- m.column_ids.should eq requested_order
22
+ m.column_ids.should eq [
23
+ Dataset.find(d2.id).column_ids[0],
24
+ Dataset.find(d1.id).column_ids[0],
25
+ Dataset.find(d2.id).column_ids[2],
26
+ Dataset.find(d1.id).column_ids[1],
27
+ ]
26
28
  end
27
29
 
28
30
  it "should retrieve the requested columns" do
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quandl_cassinatra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
5
- prerelease:
4
+ version: 0.1.10
6
5
  platform: ruby
7
6
  authors:
8
7
  - Blake Hilscher
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-26 00:00:00.000000000 Z
11
+ date: 2013-07-29 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: factory_girl
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: fivemat
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,39 +69,34 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: pry
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: activesupport
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: 3.0.0
102
90
  type: :runtime
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: 3.0.0
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: her
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
101
  - - ~>
116
102
  - !ruby/object:Gem::Version
@@ -118,7 +104,6 @@ dependencies:
118
104
  type: :runtime
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
108
  - - ~>
124
109
  - !ruby/object:Gem::Version
@@ -126,7 +111,6 @@ dependencies:
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: yajl-ruby
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
115
  - - ~>
132
116
  - !ruby/object:Gem::Version
@@ -134,7 +118,6 @@ dependencies:
134
118
  type: :runtime
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
122
  - - ~>
140
123
  - !ruby/object:Gem::Version
@@ -142,7 +125,6 @@ dependencies:
142
125
  - !ruby/object:Gem::Dependency
143
126
  name: json
144
127
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
128
  requirements:
147
129
  - - ~>
148
130
  - !ruby/object:Gem::Version
@@ -150,7 +132,6 @@ dependencies:
150
132
  type: :runtime
151
133
  prerelease: false
152
134
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
135
  requirements:
155
136
  - - ~>
156
137
  - !ruby/object:Gem::Version
@@ -158,33 +139,29 @@ dependencies:
158
139
  - !ruby/object:Gem::Dependency
159
140
  name: quandl_data
160
141
  requirement: !ruby/object:Gem::Requirement
161
- none: false
162
142
  requirements:
163
- - - ! '>='
143
+ - - '>='
164
144
  - !ruby/object:Gem::Version
165
145
  version: 0.1.8
166
146
  type: :runtime
167
147
  prerelease: false
168
148
  version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
149
  requirements:
171
- - - ! '>='
150
+ - - '>='
172
151
  - !ruby/object:Gem::Version
173
152
  version: 0.1.8
174
153
  - !ruby/object:Gem::Dependency
175
154
  name: scope_composer
176
155
  requirement: !ruby/object:Gem::Requirement
177
- none: false
178
156
  requirements:
179
- - - ! '>='
157
+ - - '>='
180
158
  - !ruby/object:Gem::Version
181
159
  version: 0.1.0
182
160
  type: :runtime
183
161
  prerelease: false
184
162
  version_requirements: !ruby/object:Gem::Requirement
185
- none: false
186
163
  requirements:
187
- - - ! '>='
164
+ - - '>='
188
165
  - !ruby/object:Gem::Version
189
166
  version: 0.1.0
190
167
  description: An orm for the cassinatra rest interface.
@@ -210,6 +187,8 @@ files:
210
187
  - lib/quandl/cassinatra/core_ext.rb
211
188
  - lib/quandl/cassinatra/core_ext/string.rb
212
189
  - lib/quandl/cassinatra/her.rb
190
+ - lib/quandl/cassinatra/middleware.rb
191
+ - lib/quandl/cassinatra/middleware/parse_json.rb
213
192
  - lib/quandl/cassinatra/model.rb
214
193
  - lib/quandl/cassinatra/model/dataset.rb
215
194
  - lib/quandl/cassinatra/model/dataset/searchable.rb
@@ -225,27 +204,26 @@ files:
225
204
  homepage: http://blake.hilscher.ca/
226
205
  licenses:
227
206
  - MIT
207
+ metadata: {}
228
208
  post_install_message:
229
209
  rdoc_options: []
230
210
  require_paths:
231
211
  - lib
232
212
  required_ruby_version: !ruby/object:Gem::Requirement
233
- none: false
234
213
  requirements:
235
- - - ! '>='
214
+ - - '>='
236
215
  - !ruby/object:Gem::Version
237
216
  version: '0'
238
217
  required_rubygems_version: !ruby/object:Gem::Requirement
239
- none: false
240
218
  requirements:
241
- - - ! '>='
219
+ - - '>='
242
220
  - !ruby/object:Gem::Version
243
221
  version: '0'
244
222
  requirements: []
245
223
  rubyforge_project:
246
- rubygems_version: 1.8.25
224
+ rubygems_version: 2.0.5
247
225
  signing_key:
248
- specification_version: 3
226
+ specification_version: 4
249
227
  summary: Cassinatra rest orm.
250
228
  test_files:
251
229
  - spec/factories/dataset.rb