opencpu 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/CHANGELOG.md +4 -0
- data/lib/opencpu/client.rb +22 -5
- data/lib/opencpu/version.rb +1 -1
- data/spec/fixtures/vcr_cassettes/animation_flip_coin.yml +0 -1
- data/spec/fixtures/vcr_cassettes/response_with_na_values.yml +61 -0
- data/spec/lib/opencpu/client_spec.rb +28 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b22793ec74be38b993028d6173a3c248c94ebded
|
4
|
+
data.tar.gz: 36dcb14376dd06f049e2777c7bddc72dfcf00d29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f8b357ba69afe78df0de40ef150183cdaf47c32dc0afad57211651f5c1175d7eac039f1a0354506ff920acadbea0344d433ceeda42787c6504bb78b6dbd0bb4
|
7
|
+
data.tar.gz: 03c3e679339495a20c1959daf76b630598fae225092a854888b966cdf7c44d441d313ac34bad0844c289ed81f0fd7d1446cff14575250e91a26738423f175996
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/lib/opencpu/client.rb
CHANGED
@@ -8,12 +8,29 @@ module OpenCPU
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def execute(package, function, options = {})
|
11
|
-
user
|
12
|
-
data
|
13
|
-
format
|
14
|
-
github_remote
|
11
|
+
user = options.fetch :user, :system
|
12
|
+
data = options.fetch :data, {}
|
13
|
+
format = options.fetch :format, :json
|
14
|
+
github_remote = options.fetch :github_remote, false
|
15
|
+
should_convert_na_to_nil = options.fetch :convert_na_to_nil, false
|
16
|
+
|
15
17
|
process_query package_url(package, function, user, github_remote, :json), data, format do |response|
|
16
|
-
JSON.parse(response.body)
|
18
|
+
output = JSON.parse(response.body)
|
19
|
+
output = convert_na_to_nil(output) if should_convert_na_to_nil
|
20
|
+
output
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def convert_na_to_nil(data)
|
25
|
+
case data
|
26
|
+
when 'NA'
|
27
|
+
nil
|
28
|
+
when Hash
|
29
|
+
data.each { |k, v| data[k] = convert_na_to_nil(v) }
|
30
|
+
when Array
|
31
|
+
data.map! { |v| convert_na_to_nil(v) }
|
32
|
+
else
|
33
|
+
data
|
17
34
|
end
|
18
35
|
end
|
19
36
|
|
data/lib/opencpu/version.rb
CHANGED
@@ -0,0 +1,61 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://public.opencpu.org/ocpu/library/base/R/identity/json
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: x=data.frame(x%3D1%2Cy%3D1)
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
Server:
|
16
|
+
- nginx/1.4.6 (Ubuntu)
|
17
|
+
Date:
|
18
|
+
- Tue, 14 Oct 2014 19:01:39 GMT
|
19
|
+
Content-Type:
|
20
|
+
- application/json
|
21
|
+
Location:
|
22
|
+
- https://public.opencpu.org/ocpu/tmp/x0c19f32080/
|
23
|
+
Transfer-Encoding:
|
24
|
+
- chunked
|
25
|
+
Connection:
|
26
|
+
- keep-alive
|
27
|
+
Cache-Control:
|
28
|
+
- max-age=300, public
|
29
|
+
X-Ocpu-Session:
|
30
|
+
- x0c19f32080
|
31
|
+
Access-Control-Allow-Origin:
|
32
|
+
- "*"
|
33
|
+
Access-Control-Allow-Headers:
|
34
|
+
- Origin, Content-Type, Accept, Accept-Encoding, Cache-Control
|
35
|
+
Access-Control-Expose-Headers:
|
36
|
+
- Location, X-ocpu-session, Content-Type, Cache-Control
|
37
|
+
X-Ocpu-R:
|
38
|
+
- R version 3.1.1 (2014-07-10)
|
39
|
+
X-Ocpu-Locale:
|
40
|
+
- en_US.UTF-8
|
41
|
+
X-Ocpu-Time:
|
42
|
+
- 2014-10-14 12:01:39 PDT
|
43
|
+
X-Ocpu-Version:
|
44
|
+
- 1.4.4
|
45
|
+
X-Ocpu-Server:
|
46
|
+
- rApache
|
47
|
+
X-Ocpu-Cache:
|
48
|
+
- MISS
|
49
|
+
body:
|
50
|
+
encoding: UTF-8
|
51
|
+
string: |+
|
52
|
+
[
|
53
|
+
{
|
54
|
+
"x": "NA",
|
55
|
+
"y": "not_na"
|
56
|
+
}
|
57
|
+
]
|
58
|
+
|
59
|
+
http_version:
|
60
|
+
recorded_at: Tue, 14 Oct 2014 19:01:39 GMT
|
61
|
+
recorded_with: VCR 2.9.3
|
@@ -105,6 +105,15 @@ describe OpenCPU::Client do
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
+
context 'na_to_nil = true option is given' do
|
109
|
+
it 'converts "na" values to nil' do
|
110
|
+
VCR.use_cassette :response_with_na_values do |cassette|
|
111
|
+
response = client.execute(:base, :identity, format: nil, data: {}, convert_na_to_nil: true)
|
112
|
+
expect(response).to eq [{"x"=>nil, "y"=>"not_na"}]
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
108
117
|
context 'multipart form / file uploads' do
|
109
118
|
it "works" do
|
110
119
|
skip # vcr is broken for file uploads https://github.com/vcr/vcr/issues/441
|
@@ -190,6 +199,25 @@ describe OpenCPU::Client do
|
|
190
199
|
end
|
191
200
|
end
|
192
201
|
|
202
|
+
describe "#convert_na_to_nil" do
|
203
|
+
let(:client) { described_class.new }
|
204
|
+
|
205
|
+
it "converts 'NA' values in hashes in arrays" do
|
206
|
+
res = client.convert_na_to_nil([4, {foo: 'NA'}])
|
207
|
+
expect(res[1][:foo]).to be_nil
|
208
|
+
end
|
209
|
+
|
210
|
+
it "converts 'NA' values in arrays in hashes" do
|
211
|
+
res = client.convert_na_to_nil(foo: [1, 'NA'])
|
212
|
+
expect(res[:foo][1]).to be_nil
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'leaves other values alone' do
|
216
|
+
res = client.convert_na_to_nil(foo: [1, 'NOTNA'])
|
217
|
+
expect(res[:foo][1]).to eq 'NOTNA'
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
193
221
|
describe '#request_options' do
|
194
222
|
it 'uses verify_ssl setting' do
|
195
223
|
expect(described_class.new.send(:request_options, {}, nil)[:verify]).to be_truthy
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opencpu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Malykh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yajl-ruby
|
@@ -213,6 +213,7 @@ files:
|
|
213
213
|
- spec/fixtures/vcr_cassettes/github_animation_flip_coin.yml
|
214
214
|
- spec/fixtures/vcr_cassettes/github_animation_flip_coin_error.yml
|
215
215
|
- spec/fixtures/vcr_cassettes/prepare.yml
|
216
|
+
- spec/fixtures/vcr_cassettes/response_with_na_values.yml
|
216
217
|
- spec/fixtures/vcr_cassettes/url_encoded_request.yml
|
217
218
|
- spec/fixtures/vcr_cassettes/user_digest_hmac.yml
|
218
219
|
- spec/lib/opencpu/client_spec.rb
|
@@ -240,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
240
241
|
version: '0'
|
241
242
|
requirements: []
|
242
243
|
rubyforge_project:
|
243
|
-
rubygems_version: 2.
|
244
|
+
rubygems_version: 2.2.2
|
244
245
|
signing_key:
|
245
246
|
specification_version: 4
|
246
247
|
summary: Wrapper around OpenCPU REST API
|
@@ -252,6 +253,7 @@ test_files:
|
|
252
253
|
- spec/fixtures/vcr_cassettes/github_animation_flip_coin.yml
|
253
254
|
- spec/fixtures/vcr_cassettes/github_animation_flip_coin_error.yml
|
254
255
|
- spec/fixtures/vcr_cassettes/prepare.yml
|
256
|
+
- spec/fixtures/vcr_cassettes/response_with_na_values.yml
|
255
257
|
- spec/fixtures/vcr_cassettes/url_encoded_request.yml
|
256
258
|
- spec/fixtures/vcr_cassettes/user_digest_hmac.yml
|
257
259
|
- spec/lib/opencpu/client_spec.rb
|