opencpu 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc821de62d9d3981b61ed2c4a501c9c67fd14335
4
- data.tar.gz: 2257ce6bd32d940475aab7063b9c8f0812a38a75
3
+ metadata.gz: b22793ec74be38b993028d6173a3c248c94ebded
4
+ data.tar.gz: 36dcb14376dd06f049e2777c7bddc72dfcf00d29
5
5
  SHA512:
6
- metadata.gz: 326ddd1a403277239f0e9ba3ba8e860ecf50ef960b03efbd65dc596dccac401f68dfa5d878ea414f3a1477ea806b55f265abf25cf5f98c8a5e0406f81da09a14
7
- data.tar.gz: b2f0770627b0663321cd710b1bff62148ba6c123c1ab76c0ec96473e4ce79d7d434d699cc97b781c64ca2c216c2e7a1258cd72750659fdb3cf3055974c063bd0
6
+ metadata.gz: 6f8b357ba69afe78df0de40ef150183cdaf47c32dc0afad57211651f5c1175d7eac039f1a0354506ff920acadbea0344d433ceeda42787c6504bb78b6dbd0bb4
7
+ data.tar.gz: 03c3e679339495a20c1959daf76b630598fae225092a854888b966cdf7c44d441d313ac34bad0844c289ed81f0fd7d1446cff14575250e91a26738423f175996
@@ -4,3 +4,5 @@ rvm:
4
4
  - 2.0.0-p576
5
5
  - 2.1.3
6
6
  script: bundle exec rspec spec
7
+ before_install:
8
+ - gem install bundler
@@ -1,3 +1,7 @@
1
+ # 0.9.1
2
+
3
+ * Added `convert_na_to_nil=true/false` option to Client#execute
4
+
1
5
  # 0.9.0
2
6
 
3
7
  * Added support for Github R repos through OpenCPU
@@ -8,12 +8,29 @@ module OpenCPU
8
8
  end
9
9
 
10
10
  def execute(package, function, options = {})
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
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
 
@@ -1,6 +1,6 @@
1
1
  module OpenCPU
2
2
  MAJOR = 0
3
3
  MINOR = 9
4
- TINY = 0
4
+ TINY = 1
5
5
  VERSION = [MAJOR, MINOR, TINY].join('.')
6
6
  end
@@ -3004,4 +3004,3 @@ http_interactions:
3004
3004
  \ \n"
3005
3005
  http_version:
3006
3006
  recorded_at: Tue, 14 Oct 2014 18:51:02 GMT
3007
- recorded_with: VCR 2.9.3
@@ -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.0
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: 2015-06-08 00:00:00.000000000 Z
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.4.5
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