opencpu 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile +6 -0
- data/README.md +10 -0
- data/lib/opencpu/client.rb +20 -8
- data/lib/opencpu/version.rb +1 -1
- data/opencpu.gemspec +0 -2
- data/spec/fixtures/vcr_cassettes/description.yml +56 -0
- data/spec/lib/opencpu/client_spec.rb +44 -7
- metadata +5 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4dd7cd2e25675a883669dcc7b2dff60c3bed910
|
4
|
+
data.tar.gz: fb2c04876cdf97dc4c0656a5c24fd79718a22ffd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3dcee9fba66c0e432feda4bb27e9b7b39f9453507dc5d26412d74fcfe576891bf09d82b8a0012b0df4d13646a529509248e72735108bcb0168c6ffdc1de9707
|
7
|
+
data.tar.gz: 490fac6cde42a5a53020c0b87d5029f24a2ee0b648608aed69b67090624a1da0c0c64b530cd41d1ff15cc56b0271b5544be7e92bff86b6b167e07afdf5a32896
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -161,6 +161,16 @@ If you want to send one or more files along, you can pass in a File object as da
|
|
161
161
|
client.execute :foo, :bar, user: :johndoe, data: {file: File.new('/tmp/test.foo')}, format: :urlencoded
|
162
162
|
```
|
163
163
|
|
164
|
+
**Package desciption**
|
165
|
+
|
166
|
+
To access the entire content of a package's DESCRIPTION file
|
167
|
+
```Ruby
|
168
|
+
client.description :mypackage
|
169
|
+
# => "Package: mypackage
|
170
|
+
# Version: 1.00
|
171
|
+
# ..."
|
172
|
+
```
|
173
|
+
|
164
174
|
## Testing
|
165
175
|
|
166
176
|
**NOTE:** Test mode is only supported in combination with `#execute` and the
|
data/lib/opencpu/client.rb
CHANGED
@@ -14,13 +14,21 @@ module OpenCPU
|
|
14
14
|
github_remote = options.fetch :github_remote, false
|
15
15
|
should_convert_na_to_nil = options.fetch :convert_na_to_nil, false
|
16
16
|
|
17
|
-
process_query
|
17
|
+
process_query function_url(package, function, user, github_remote, :json), data, format do |response|
|
18
18
|
output = JSON.parse(response.body)
|
19
19
|
output = convert_na_to_nil(output) if should_convert_na_to_nil
|
20
20
|
output
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
def description(package, options = {})
|
25
|
+
user = options.fetch :user, :system
|
26
|
+
github_remote = options.fetch :github_remote, false
|
27
|
+
|
28
|
+
url = "#{package_url(package, user, github_remote)}/info"
|
29
|
+
self.class.get(url, request_options(nil, :json))
|
30
|
+
end
|
31
|
+
|
24
32
|
def convert_na_to_nil(data)
|
25
33
|
case data
|
26
34
|
when 'NA'
|
@@ -39,7 +47,7 @@ module OpenCPU
|
|
39
47
|
data = options.fetch :data, {}
|
40
48
|
format = options.fetch :format, :json
|
41
49
|
github_remote = options.fetch :github_remote, false
|
42
|
-
process_query
|
50
|
+
process_query function_url(package, function, user, github_remote), data, format do |response|
|
43
51
|
location = response.headers['location']
|
44
52
|
resources = response.body.split(/\n/)
|
45
53
|
OpenCPU::DelayedCalculation.new(location, resources)
|
@@ -70,10 +78,10 @@ module OpenCPU
|
|
70
78
|
|
71
79
|
case format
|
72
80
|
when :json
|
73
|
-
options[:body] = data.to_json
|
81
|
+
options[:body] = data.to_json if data
|
74
82
|
options[:headers] = {"Content-Type" => 'application/json'}
|
75
83
|
when :urlencoded
|
76
|
-
options[:query] = data
|
84
|
+
options[:query] = data if data
|
77
85
|
end
|
78
86
|
|
79
87
|
if OpenCPU.configuration.username && OpenCPU.configuration.password
|
@@ -84,10 +92,14 @@ module OpenCPU
|
|
84
92
|
options
|
85
93
|
end
|
86
94
|
|
87
|
-
def
|
88
|
-
|
89
|
-
|
90
|
-
|
95
|
+
def function_url(package, function, user = :system, github_remote = false, format = nil)
|
96
|
+
"#{package_url(package, user, github_remote)}/R/#{function}/#{format.to_s}"
|
97
|
+
end
|
98
|
+
|
99
|
+
def package_url(package, user = :system, github_remote = false)
|
100
|
+
return "/library/#{package}" if user == :system
|
101
|
+
return "/github/#{user}/#{package}" if github_remote
|
102
|
+
return "/user/#{user}/library/#{package}"
|
91
103
|
end
|
92
104
|
|
93
105
|
def fake_response_for(url)
|
data/lib/opencpu/version.rb
CHANGED
data/opencpu.gemspec
CHANGED
@@ -28,6 +28,4 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency 'rspec', '~> 2.14', '>= 2.14.1'
|
29
29
|
spec.add_development_dependency 'webmock', '~> 1.17', '>= 1.17.4'
|
30
30
|
spec.add_development_dependency 'vcr', '~> 2.9', '>= 2.9.0'
|
31
|
-
spec.add_development_dependency 'guard-rspec', '~> 4.2', '>= 4.2.8'
|
32
|
-
spec.add_development_dependency 'guard-bundler', '~> 2.0', '>= 2.0.0'
|
33
31
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://public.opencpu.org/ocpu/library/ade4/info
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
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
|
+
- Fri, 10 Jun 2016 16:20:39 GMT
|
19
|
+
Content-Type:
|
20
|
+
- text/plain; charset=utf-8
|
21
|
+
Transfer-Encoding:
|
22
|
+
- chunked
|
23
|
+
Connection:
|
24
|
+
- keep-alive
|
25
|
+
Cache-Control:
|
26
|
+
- max-age=86400, public
|
27
|
+
Access-Control-Allow-Origin:
|
28
|
+
- "*"
|
29
|
+
Access-Control-Expose-Headers:
|
30
|
+
- Location, X-ocpu-session, Content-Type, Cache-Control
|
31
|
+
Access-Control-Allow-Headers:
|
32
|
+
- Origin, Content-Type, Accept, Accept-Encoding, Cache-Control, Authorization
|
33
|
+
Access-Control-Allow-Credentials:
|
34
|
+
- 'true'
|
35
|
+
X-Ocpu-R:
|
36
|
+
- R version 3.3.0 (2016-05-03)
|
37
|
+
X-Ocpu-Locale:
|
38
|
+
- en_US.UTF-8
|
39
|
+
X-Ocpu-Time:
|
40
|
+
- 2016-06-10 09:18:55 PDT
|
41
|
+
X-Ocpu-Version:
|
42
|
+
- 1.6.2
|
43
|
+
X-Ocpu-Server:
|
44
|
+
- rApache
|
45
|
+
Vary:
|
46
|
+
- Accept-Encoding
|
47
|
+
X-Ocpu-Cache:
|
48
|
+
- HIT
|
49
|
+
body:
|
50
|
+
encoding: ASCII-8BIT
|
51
|
+
string: |
|
52
|
+
Package: My package
|
53
|
+
Type: Package
|
54
|
+
http_version:
|
55
|
+
recorded_at: Fri, 10 Jun 2016 16:20:39 GMT
|
56
|
+
recorded_with: VCR 2.9.3
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe OpenCPU::Client do
|
4
|
+
let(:client) { described_class.new }
|
4
5
|
|
5
6
|
before do
|
6
7
|
OpenCPU.configure do |config|
|
@@ -47,7 +48,6 @@ describe OpenCPU::Client do
|
|
47
48
|
end
|
48
49
|
|
49
50
|
describe '#prepare' do
|
50
|
-
let(:client) { described_class.new }
|
51
51
|
let(:delayed_calculation) { client.prepare('digest', 'hmac', data: { key: "baz", object: "qux" }) }
|
52
52
|
|
53
53
|
it 'returns a DelayedCalculation' do
|
@@ -67,7 +67,6 @@ describe OpenCPU::Client do
|
|
67
67
|
after do
|
68
68
|
OpenCPU.disable_test_mode!
|
69
69
|
end
|
70
|
-
let(:client) { described_class.new }
|
71
70
|
|
72
71
|
it 'is used to quickly return JSON results' do
|
73
72
|
VCR.use_cassette :animation_flip_coin, record: :new_episodes do
|
@@ -92,7 +91,7 @@ describe OpenCPU::Client do
|
|
92
91
|
context 'url encoded request' do
|
93
92
|
it 'sends the parameters url_encoded' do
|
94
93
|
VCR.use_cassette :url_encoded_request do |cassette|
|
95
|
-
|
94
|
+
client.execute(:base, :identity, format: nil, data: { x: 'data.frame(x=1,y=1)' })
|
96
95
|
params = cassette.serializable_hash['http_interactions'][0]['request']['body']['string']
|
97
96
|
expect(params).to eq "x=data.frame(x%3D1%2Cy%3D1)"
|
98
97
|
end
|
@@ -138,7 +137,6 @@ describe OpenCPU::Client do
|
|
138
137
|
end
|
139
138
|
end
|
140
139
|
after { OpenCPU.reset_configuration! }
|
141
|
-
let(:client) { described_class.new }
|
142
140
|
|
143
141
|
it "can access user packages" do
|
144
142
|
VCR.use_cassette :user_digest_hmac do
|
@@ -155,7 +153,6 @@ describe OpenCPU::Client do
|
|
155
153
|
end
|
156
154
|
end
|
157
155
|
after { OpenCPU.reset_configuration! }
|
158
|
-
let(:client) { described_class.new }
|
159
156
|
|
160
157
|
it "can access github packages" do
|
161
158
|
VCR.use_cassette :github_animation_flip_coin do
|
@@ -199,9 +196,17 @@ describe OpenCPU::Client do
|
|
199
196
|
end
|
200
197
|
end
|
201
198
|
|
202
|
-
describe
|
203
|
-
|
199
|
+
describe '#description' do
|
200
|
+
it 'returns the content of the package DESCRIPTION file' do
|
201
|
+
VCR.use_cassette :description do |cassette|
|
202
|
+
response = client.description('ade4')
|
203
|
+
expect(response.body).to eq "Package: My package\n" \
|
204
|
+
"Type: Package\n"
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
204
208
|
|
209
|
+
describe "#convert_na_to_nil" do
|
205
210
|
it "converts 'NA' values in hashes in arrays" do
|
206
211
|
res = client.convert_na_to_nil([4, {foo: 'NA'}])
|
207
212
|
expect(res[1][:foo]).to be_nil
|
@@ -218,6 +223,38 @@ describe OpenCPU::Client do
|
|
218
223
|
end
|
219
224
|
end
|
220
225
|
|
226
|
+
describe '#function_url' do
|
227
|
+
before { allow(client).to receive(:package_url).and_return '<package url>' }
|
228
|
+
|
229
|
+
subject { client.send(:function_url, 'some_package', 'some_function', :kees, false, :json) }
|
230
|
+
|
231
|
+
it { is_expected.to eq '<package url>/R/some_function/json' }
|
232
|
+
end
|
233
|
+
|
234
|
+
describe '#package_url' do
|
235
|
+
let(:from_github) { false }
|
236
|
+
|
237
|
+
subject { client.send(:package_url, 'some_package', user, from_github) }
|
238
|
+
|
239
|
+
context ':system user' do
|
240
|
+
let(:user) { :system }
|
241
|
+
it { is_expected.to eq '/library/some_package' }
|
242
|
+
end
|
243
|
+
|
244
|
+
context 'other user' do
|
245
|
+
let(:user) { :kees }
|
246
|
+
|
247
|
+
context 'package is from GitHub' do
|
248
|
+
let(:from_github) { true }
|
249
|
+
it { is_expected.to eq '/github/kees/some_package' }
|
250
|
+
end
|
251
|
+
|
252
|
+
context 'other source' do
|
253
|
+
it { is_expected.to eq '/user/kees/library/some_package' }
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
221
258
|
describe '#request_options' do
|
222
259
|
it 'uses verify_ssl setting' do
|
223
260
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Malykh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yajl-ruby
|
@@ -144,46 +144,6 @@ dependencies:
|
|
144
144
|
- - ">="
|
145
145
|
- !ruby/object:Gem::Version
|
146
146
|
version: 2.9.0
|
147
|
-
- !ruby/object:Gem::Dependency
|
148
|
-
name: guard-rspec
|
149
|
-
requirement: !ruby/object:Gem::Requirement
|
150
|
-
requirements:
|
151
|
-
- - "~>"
|
152
|
-
- !ruby/object:Gem::Version
|
153
|
-
version: '4.2'
|
154
|
-
- - ">="
|
155
|
-
- !ruby/object:Gem::Version
|
156
|
-
version: 4.2.8
|
157
|
-
type: :development
|
158
|
-
prerelease: false
|
159
|
-
version_requirements: !ruby/object:Gem::Requirement
|
160
|
-
requirements:
|
161
|
-
- - "~>"
|
162
|
-
- !ruby/object:Gem::Version
|
163
|
-
version: '4.2'
|
164
|
-
- - ">="
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: 4.2.8
|
167
|
-
- !ruby/object:Gem::Dependency
|
168
|
-
name: guard-bundler
|
169
|
-
requirement: !ruby/object:Gem::Requirement
|
170
|
-
requirements:
|
171
|
-
- - "~>"
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: '2.0'
|
174
|
-
- - ">="
|
175
|
-
- !ruby/object:Gem::Version
|
176
|
-
version: 2.0.0
|
177
|
-
type: :development
|
178
|
-
prerelease: false
|
179
|
-
version_requirements: !ruby/object:Gem::Requirement
|
180
|
-
requirements:
|
181
|
-
- - "~>"
|
182
|
-
- !ruby/object:Gem::Version
|
183
|
-
version: '2.0'
|
184
|
-
- - ">="
|
185
|
-
- !ruby/object:Gem::Version
|
186
|
-
version: 2.0.0
|
187
147
|
description: This gem wraps the OpenCPU REST API.
|
188
148
|
email:
|
189
149
|
- ivan@roqua.nl
|
@@ -208,6 +168,7 @@ files:
|
|
208
168
|
- opencpu.gemspec
|
209
169
|
- spec/fixtures/test.csv
|
210
170
|
- spec/fixtures/vcr_cassettes/animation_flip_coin.yml
|
171
|
+
- spec/fixtures/vcr_cassettes/description.yml
|
211
172
|
- spec/fixtures/vcr_cassettes/digest_hmac.yml
|
212
173
|
- spec/fixtures/vcr_cassettes/digest_hmac_no_parameters.yml
|
213
174
|
- spec/fixtures/vcr_cassettes/github_animation_flip_coin.yml
|
@@ -241,13 +202,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
241
202
|
version: '0'
|
242
203
|
requirements: []
|
243
204
|
rubyforge_project:
|
244
|
-
rubygems_version: 2.
|
205
|
+
rubygems_version: 2.4.6
|
245
206
|
signing_key:
|
246
207
|
specification_version: 4
|
247
208
|
summary: Wrapper around OpenCPU REST API
|
248
209
|
test_files:
|
249
210
|
- spec/fixtures/test.csv
|
250
211
|
- spec/fixtures/vcr_cassettes/animation_flip_coin.yml
|
212
|
+
- spec/fixtures/vcr_cassettes/description.yml
|
251
213
|
- spec/fixtures/vcr_cassettes/digest_hmac.yml
|
252
214
|
- spec/fixtures/vcr_cassettes/digest_hmac_no_parameters.yml
|
253
215
|
- spec/fixtures/vcr_cassettes/github_animation_flip_coin.yml
|