opencpu 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: post
5
- uri: https://foo:bar@public.opencpu.org/ocpu/library/digest/R/hmac/json
5
+ uri: https://public.opencpu.org/ocpu/library/digest/R/hmac/json
6
6
  body:
7
7
  encoding: UTF-8
8
8
  string: '{"key":"baz","object":"qux"}'
@@ -15,13 +15,13 @@ http_interactions:
15
15
  message: OK
16
16
  headers:
17
17
  Server:
18
- - nginx/1.4.1 (Ubuntu)
18
+ - nginx/1.4.6 (Ubuntu)
19
19
  Date:
20
- - Thu, 10 Apr 2014 12:28:02 GMT
20
+ - Thu, 01 May 2014 14:34:19 GMT
21
21
  Content-Type:
22
22
  - application/json
23
23
  Location:
24
- - https://public.opencpu.org/ocpu/tmp/x030f9d57/
24
+ - https://public.opencpu.org/ocpu/tmp/x0a6d5ac9c2/
25
25
  Transfer-Encoding:
26
26
  - chunked
27
27
  Connection:
@@ -29,7 +29,7 @@ http_interactions:
29
29
  Cache-Control:
30
30
  - max-age=300, public
31
31
  X-Ocpu-Session:
32
- - x030f9d57
32
+ - x0a6d5ac9c2
33
33
  Access-Control-Allow-Origin:
34
34
  - "*"
35
35
  Access-Control-Allow-Headers:
@@ -37,20 +37,20 @@ http_interactions:
37
37
  Access-Control-Expose-Headers:
38
38
  - Location, X-ocpu-session, Content-Type, Cache-Control
39
39
  X-Ocpu-R:
40
- - R version 3.1.0 beta (2014-03-28 r65330)
40
+ - R version 3.1.0 (2014-04-10)
41
41
  X-Ocpu-Locale:
42
42
  - en_US.UTF-8
43
43
  X-Ocpu-Time:
44
- - 2014-04-10 05:28:02 PDT
44
+ - 2014-05-01 07:34:19 PDT
45
45
  X-Ocpu-Version:
46
- - 1.2.99
46
+ - 1.4.1.99
47
47
  X-Ocpu-Server:
48
48
  - rApache
49
49
  X-Ocpu-Cache:
50
- - MISS
50
+ - EXPIRED
51
51
  body:
52
52
  encoding: UTF-8
53
53
  string: "[\n\t\"22e2a7a268bf076801eefe7cd0119bb9\"\n]\n"
54
54
  http_version:
55
- recorded_at: Thu, 10 Apr 2014 12:28:03 GMT
55
+ recorded_at: Thu, 01 May 2014 14:34:22 GMT
56
56
  recorded_with: VCR 2.9.0
@@ -0,0 +1,52 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://public.opencpu.org/ocpu/library/digest/R/hmac/json
6
+ body:
7
+ encoding: UTF-8
8
+ string: "{}"
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ response:
13
+ status:
14
+ code: 400
15
+ message: Bad Request
16
+ headers:
17
+ Server:
18
+ - nginx/1.4.6 (Ubuntu)
19
+ Date:
20
+ - Thu, 01 May 2014 14:34:20 GMT
21
+ Content-Type:
22
+ - text/plain; charset=utf-8
23
+ Transfer-Encoding:
24
+ - chunked
25
+ Connection:
26
+ - keep-alive
27
+ Access-Control-Allow-Origin:
28
+ - "*"
29
+ Access-Control-Allow-Headers:
30
+ - Origin, Content-Type, Accept, Cache-Control
31
+ Access-Control-Expose-Headers:
32
+ - Location, X-ocpu-session, Content-Type, Cache-Control
33
+ X-Ocpu-R:
34
+ - R version 3.1.0 (2014-04-10)
35
+ X-Ocpu-Locale:
36
+ - en_US.UTF-8
37
+ X-Ocpu-Time:
38
+ - 2014-05-01 07:34:20 PDT
39
+ X-Ocpu-Version:
40
+ - 1.4.1.99
41
+ X-Ocpu-Server:
42
+ - rApache
43
+ body:
44
+ encoding: UTF-8
45
+ string: |
46
+ argument "key" is missing, with no default
47
+
48
+ In call:
49
+ makeRaw(k)
50
+ http_version:
51
+ recorded_at: Thu, 01 May 2014 14:34:23 GMT
52
+ recorded_with: VCR 2.9.0
@@ -0,0 +1,62 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://public.opencpu.org/ocpu/library/digest/R/hmac/
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"key":"baz","object":"qux"}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ response:
13
+ status:
14
+ code: 201
15
+ message: Created
16
+ headers:
17
+ Server:
18
+ - nginx/1.4.6 (Ubuntu)
19
+ Date:
20
+ - Thu, 01 May 2014 14:34:16 GMT
21
+ Content-Type:
22
+ - text/plain; charset=utf-8
23
+ Location:
24
+ - https://public.opencpu.org/ocpu/tmp/x0a79915480/
25
+ Transfer-Encoding:
26
+ - chunked
27
+ Connection:
28
+ - keep-alive
29
+ Cache-Control:
30
+ - max-age=300, public
31
+ X-Ocpu-Session:
32
+ - x0a79915480
33
+ Access-Control-Allow-Origin:
34
+ - "*"
35
+ Access-Control-Allow-Headers:
36
+ - Origin, Content-Type, Accept, Cache-Control
37
+ Access-Control-Expose-Headers:
38
+ - Location, X-ocpu-session, Content-Type, Cache-Control
39
+ X-Ocpu-R:
40
+ - R version 3.1.0 (2014-04-10)
41
+ X-Ocpu-Locale:
42
+ - en_US.UTF-8
43
+ X-Ocpu-Time:
44
+ - 2014-05-01 07:34:16 PDT
45
+ X-Ocpu-Version:
46
+ - 1.4.1.99
47
+ X-Ocpu-Server:
48
+ - rApache
49
+ X-Ocpu-Cache:
50
+ - EXPIRED
51
+ body:
52
+ encoding: UTF-8
53
+ string: |
54
+ /ocpu/tmp/x0a79915480/R/.val
55
+ /ocpu/tmp/x0a79915480/stdout
56
+ /ocpu/tmp/x0a79915480/warnings
57
+ /ocpu/tmp/x0a79915480/source
58
+ /ocpu/tmp/x0a79915480/console
59
+ /ocpu/tmp/x0a79915480/info
60
+ http_version:
61
+ recorded_at: Thu, 01 May 2014 14:34:19 GMT
62
+ recorded_with: VCR 2.9.0
@@ -2,49 +2,75 @@ require 'spec_helper'
2
2
 
3
3
  describe OpenCPU::Client do
4
4
 
5
+ before do
6
+ OpenCPU.configure do |config|
7
+ config.endpoint_url = 'https://public.opencpu.org/ocpu'
8
+ end
9
+ end
10
+
5
11
  it 'initializes with HTTParty' do
6
12
  expect(described_class.ancestors).to include HTTParty
7
13
  end
8
14
 
9
- it 'provides #default_options' do
10
- expect(described_class.new).to respond_to :default_options
15
+ it 'defines #execute' do
16
+ expect(described_class.new).to respond_to :execute
17
+ end
18
+
19
+ it 'defines #prepare' do
20
+ expect(described_class.new).to respond_to :prepare
11
21
  end
12
22
 
13
- context 'configured' do
23
+ describe 'initializes' do
14
24
  before do
15
25
  OpenCPU.configure do |config|
16
26
  config.endpoint_url = 'https://public.opencpu.org/ocpu'
17
- config.username = 'foo'
18
- config.password = 'bar'
19
27
  end
20
28
  end
21
29
 
22
- it 'initializes with configured attributes' do
30
+ it 'with configured attributes' do
23
31
  expect(described_class.new.class.base_uri).to eq 'https://public.opencpu.org/ocpu'
24
- expect(described_class.new.default_options).to eq({basic_auth: {username: 'foo', password: 'bar'}})
25
32
  end
26
33
  end
27
34
 
28
- it 'defines #execute' do
29
- expect(described_class.new).to respond_to :execute
35
+ describe '#prepare' do
36
+ let(:client) { described_class.new }
37
+ let(:delayed_calculation) { client.prepare('digest', 'hmac', key: "baz", object: "qux") }
38
+
39
+ it 'returns a DelayedCalculation' do
40
+ VCR.use_cassette :prepare do
41
+ expect(delayed_calculation).to be_a OpenCPU::DelayedCalculation
42
+ end
43
+ end
44
+
45
+ it 'returns a DelayedCalculation with correct path' do
46
+ VCR.use_cassette :prepare do
47
+ expect(delayed_calculation.location).to eq "https://public.opencpu.org/ocpu/tmp/x0a79915480/"
48
+ end
49
+ end
30
50
  end
31
51
 
32
52
  describe '#execute' do
33
- before do
34
- OpenCPU.configure do |config|
35
- config.endpoint_url = 'https://public.opencpu.org/ocpu'
36
- config.username = 'foo'
37
- config.password = 'bar'
53
+ let(:client) { described_class.new }
54
+
55
+ it 'is used to quickly return JSON results' do
56
+ VCR.use_cassette :animation_flip_coin, record: :new_episodes do
57
+ response = client.execute(:animation, 'flip.coin')
58
+ expect(response).to eq "freq" => [0.56, 0.44], "nmax" => [50]
38
59
  end
39
60
  end
40
61
 
41
- let(:client) { described_class.new }
62
+ it 'accepts R-function parameters as data' do
63
+ VCR.use_cassette :digest_hmac, record: :new_episodes do
64
+ response = client.execute(:digest, :hmac, key: 'baz', object: 'qux')
65
+ expect(response).to eq ["22e2a7a268bf076801eefe7cd0119bb9"]
66
+ end
67
+ end
42
68
 
43
- it 'returns a correct HMAC response' do
44
- VCR.use_cassette :digest_hmac do
45
- response = client.execute('digest', 'hmac', key: 'baz', object: 'qux')
46
- expect(response[0]).to eq '22e2a7a268bf076801eefe7cd0119bb9'
69
+ it 'raises 400 with body' do
70
+ VCR.use_cassette :digest_hmac_no_parameters do
71
+ expect { client.execute(:digest, :hmac) }.to raise_error
47
72
  end
48
73
  end
49
74
  end
75
+
50
76
  end
@@ -0,0 +1,122 @@
1
+ require 'spec_helper'
2
+
3
+ describe OpenCPU::DelayedCalculation do
4
+
5
+ let(:delayed_calculation) { described_class.new 'foo' }
6
+
7
+ describe "initializes" do
8
+ it "without resources" do
9
+ delayed_calculation = described_class.new 'foo'
10
+ expect(delayed_calculation.available_resources).to eq Hash.new
11
+ end
12
+
13
+ let(:resources) do
14
+ [
15
+ '/foo/bar',
16
+ '/foo/baz'
17
+ ]
18
+ end
19
+ let(:parsed_resources) do
20
+ {
21
+ bar: URI.parse('https://opencpu.org/foo/bar'),
22
+ baz: URI.parse('https://opencpu.org/foo/baz')
23
+ }
24
+ end
25
+ it "with resources" do
26
+ delayed_calculation = described_class.new 'https://opencpu.org/foo/', resources
27
+ expect(delayed_calculation.available_resources).to eq parsed_resources
28
+ end
29
+ end
30
+
31
+ let(:location) { "https://public.opencpu.org/ocpu/tmp/x09dd995a16/" }
32
+ let(:resources) do
33
+ [
34
+ "/ocpu/tmp/x09dd995a16/R/.val",
35
+ "/ocpu/tmp/x09dd995a16/graphics/1",
36
+ "/ocpu/tmp/x09dd995a16/graphics/2",
37
+ "/ocpu/tmp/x09dd995a16/graphics/3",
38
+ "/ocpu/tmp/x09dd995a16/graphics/4",
39
+ "/ocpu/tmp/x09dd995a16/source",
40
+ "/ocpu/tmp/x09dd995a16/console",
41
+ "/ocpu/tmp/x09dd995a16/info"
42
+ ]
43
+ end
44
+ let(:delayed_calculation) { described_class.new location, resources }
45
+
46
+ describe "#graphics" do
47
+
48
+ it 'defines methods to access graphic functions' do
49
+ VCR.use_cassette :animation_flip_coin, record: :new_episodes do
50
+ expect { delayed_calculation.graphics }.not_to raise_error
51
+ expect { delayed_calculation.stdout }.to raise_error OpenCPU::ResponseNotAvailableError
52
+ end
53
+ end
54
+
55
+ it "returns a SVG by default" do
56
+ VCR.use_cassette :animation_flip_coin, record: :new_episodes do
57
+ expect(delayed_calculation.graphics).to include 'svg xmlns'
58
+ end
59
+ end
60
+
61
+ it "can return a PNG" do
62
+ VCR.use_cassette :animation_flip_coin, record: :new_episodes do
63
+ expect(delayed_calculation.graphics(0, :png)).to include 'PNG'
64
+ end
65
+ end
66
+
67
+ it "does not support formats except PNG and SVG" do
68
+ VCR.use_cassette :animation_flip_coin, record: :new_episodes do
69
+ expect { delayed_calculation.graphics(0, :svg) }.not_to raise_error
70
+ expect { delayed_calculation.graphics(0, :png) }.not_to raise_error
71
+ expect { delayed_calculation.graphics(0, :foo) }.to raise_error OpenCPU::UnsupportedFormatError
72
+ expect { delayed_calculation.graphics(0, :bar) }.to raise_error OpenCPU::UnsupportedFormatError
73
+ end
74
+ end
75
+
76
+ it 'can handle multiple graphic output' do
77
+
78
+ end
79
+ end
80
+
81
+ describe 'standard getters' do
82
+ describe '#value' do
83
+ it "returns raw R calculation result" do
84
+ VCR.use_cassette :animation_flip_coin, record: :new_episodes do
85
+ expect(delayed_calculation.value).to eq "$freq\n 1 2 \n0.52 0.48 \n\n$nmax\n[1] 50"
86
+ end
87
+ end
88
+ end
89
+
90
+ describe '#stdout' do
91
+ it "returns cached stdout" do
92
+ VCR.use_cassette :animation_flip_coin, record: :new_episodes do
93
+ expect { delayed_calculation.stdout }.to raise_error OpenCPU::ResponseNotAvailableError
94
+ end
95
+ end
96
+ end
97
+
98
+ describe '#warnings' do
99
+ it 'returns cached warnings' do
100
+ VCR.use_cassette :animation_flip_coin, record: :new_episodes do
101
+ expect { delayed_calculation.warnings }.to raise_error OpenCPU::ResponseNotAvailableError
102
+ end
103
+ end
104
+ end
105
+
106
+ describe '#info' do
107
+ it 'returns cached info' do
108
+ VCR.use_cassette :animation_flip_coin, record: :new_episodes do
109
+ expect(delayed_calculation.info).to include("R version")
110
+ end
111
+ end
112
+ end
113
+
114
+ # describe "#console" do
115
+ # it 'returns cached console input' do
116
+ # VCR.use_cassette :animation_flip_coin, record: :new_episodes do
117
+ # expect(delayed_calculation.console).to include("hmac(key = \"baz\", object = \"qux\"")
118
+ # end
119
+ # end
120
+ # end
121
+ end
122
+ end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper.rb', __dir__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe OpenCPU do
4
4
 
@@ -26,7 +26,4 @@ describe OpenCPU do
26
26
  end
27
27
  end
28
28
 
29
- describe '#client' do
30
-
31
- end
32
29
  end
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.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Malykh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-10 00:00:00.000000000 Z
11
+ date: 2014-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yajl-ruby
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: webmock
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ~>
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 1.17.4
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ~>
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: 1.17.4
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: vcr
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -153,12 +153,17 @@ files:
153
153
  - lib/opencpu.rb
154
154
  - lib/opencpu/client.rb
155
155
  - lib/opencpu/configuration.rb
156
+ - lib/opencpu/delayed_calculation.rb
156
157
  - lib/opencpu/version.rb
157
158
  - opencpu.gemspec
159
+ - spec/fixtures/vcr_cassettes/animation_flip_coin.yml
158
160
  - spec/fixtures/vcr_cassettes/digest_hmac.yml
159
- - spec/lib/opencpu.rb
161
+ - spec/fixtures/vcr_cassettes/digest_hmac_no_parameters.yml
162
+ - spec/fixtures/vcr_cassettes/prepare.yml
160
163
  - spec/lib/opencpu/client_spec.rb
161
164
  - spec/lib/opencpu/configuration_spec.rb
165
+ - spec/lib/opencpu/delayed_calculation_spec.rb
166
+ - spec/lib/opencpu_spec.rb
162
167
  - spec/spec_helper.rb
163
168
  homepage: http://roqua.nl
164
169
  licenses:
@@ -180,13 +185,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
185
  version: '0'
181
186
  requirements: []
182
187
  rubyforge_project:
183
- rubygems_version: 2.0.3
188
+ rubygems_version: 2.0.14
184
189
  signing_key:
185
190
  specification_version: 4
186
191
  summary: Wrapper around OpenCPU REST API
187
192
  test_files:
193
+ - spec/fixtures/vcr_cassettes/animation_flip_coin.yml
188
194
  - spec/fixtures/vcr_cassettes/digest_hmac.yml
189
- - spec/lib/opencpu.rb
195
+ - spec/fixtures/vcr_cassettes/digest_hmac_no_parameters.yml
196
+ - spec/fixtures/vcr_cassettes/prepare.yml
190
197
  - spec/lib/opencpu/client_spec.rb
191
198
  - spec/lib/opencpu/configuration_spec.rb
199
+ - spec/lib/opencpu/delayed_calculation_spec.rb
200
+ - spec/lib/opencpu_spec.rb
192
201
  - spec/spec_helper.rb