opencpu 0.9.2 → 0.10.0

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: b4dd7cd2e25675a883669dcc7b2dff60c3bed910
4
- data.tar.gz: fb2c04876cdf97dc4c0656a5c24fd79718a22ffd
3
+ metadata.gz: 5070269fee0cea90489369a6c10b7df8f9a4d946
4
+ data.tar.gz: 2f4c0996615c1febdf2f69af2f3a3e88fb3e0d30
5
5
  SHA512:
6
- metadata.gz: f3dcee9fba66c0e432feda4bb27e9b7b39f9453507dc5d26412d74fcfe576891bf09d82b8a0012b0df4d13646a529509248e72735108bcb0168c6ffdc1de9707
7
- data.tar.gz: 490fac6cde42a5a53020c0b87d5029f24a2ee0b648608aed69b67090624a1da0c0c64b530cd41d1ff15cc56b0271b5544be7e92bff86b6b167e07afdf5a32896
6
+ metadata.gz: b9e5ef651e28801b06f0df1aaf4a55c716425f67c7f850915a3bbb4f98621f72a70c22af851ca0cec2c1e5fe95595a485420b22879aa0d97178e4c92a66fc06c
7
+ data.tar.gz: a15e61815b1e2803704c77768359e9b3376575c321615bc983136dd85b44c7e76e163b26bb0adc97207a31a1a5ab91b472d97e9f659f7927b645db403247c43d
data/.gitignore CHANGED
@@ -17,5 +17,6 @@ spec/reports
17
17
  test/tmp
18
18
  test/version_tmp
19
19
  tmp
20
+ .byebug-history
20
21
 
21
22
  .ruby-version
@@ -1,3 +1,8 @@
1
+ # 0.10.0
2
+
3
+ * BREAKING CHANGE: on request failure, it raises a specific error (BadRequest, InternalServerError or Unknown Error)
4
+ instead of StandardError
5
+
1
6
  # 0.9.2
2
7
 
3
8
  * Added `OpenCPU::Client#description` to retrieve a packages' description file
@@ -1,5 +1,8 @@
1
+ require 'opencpu/errors'
2
+
1
3
  module OpenCPU
2
4
  class Client
5
+ include Errors
3
6
  include HTTMultiParty
4
7
 
5
8
  def initialize
@@ -64,10 +67,21 @@ module OpenCPU
64
67
  case response.code
65
68
  when 200..201
66
69
  return yield(response)
67
- when 400
68
- fail '400: Bad Request\n' + response.body
69
70
  else
70
- fail "#{response.code}:\n #{response.body}"
71
+ fail error_class_for(response.code), "#{response.code}:\n #{response.body}"
72
+ end
73
+ end
74
+
75
+ def error_class_for(response_code)
76
+ case response_code
77
+ when 403
78
+ AccessDenied
79
+ when 400..499
80
+ BadRequest
81
+ when 500..599
82
+ InternalServerError
83
+ else
84
+ UnknownError
71
85
  end
72
86
  end
73
87
 
@@ -0,0 +1,9 @@
1
+ module OpenCPU
2
+ module Errors
3
+ class OpenCPUError < StandardError; end
4
+ class BadRequest < OpenCPUError; end
5
+ class InternalServerError < OpenCPUError; end
6
+ class AccessDenied < OpenCPUError; end
7
+ class UnknownError < OpenCPUError; end
8
+ end
9
+ end
@@ -1,6 +1,6 @@
1
1
  module OpenCPU
2
2
  MAJOR = 0
3
- MINOR = 9
4
- TINY = 2
3
+ MINOR = 10
4
+ TINY = 0
5
5
  VERSION = [MAJOR, MINOR, TINY].join('.')
6
6
  end
@@ -0,0 +1,56 @@
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: '{"some":"data"}'
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.10.0 (Ubuntu)
19
+ Date:
20
+ - Thu, 30 Jun 2016 10:16:58 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-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.1 (2016-06-21)
37
+ X-Ocpu-Locale:
38
+ - en_US.UTF-8
39
+ X-Ocpu-Time:
40
+ - 2016-06-30 06:16:58 EDT
41
+ X-Ocpu-Version:
42
+ - 1.6.3
43
+ X-Ocpu-Server:
44
+ - rApache
45
+ Vary:
46
+ - Accept-Encoding
47
+ body:
48
+ encoding: UTF-8
49
+ string: |
50
+ unused argument (some = "data")
51
+
52
+ In call:
53
+ identity(some = "data")
54
+ http_version:
55
+ recorded_at: Thu, 30 Jun 2016 10:16:58 GMT
56
+ recorded_with: VCR 2.9.3
@@ -21,6 +21,34 @@ describe OpenCPU::Client do
21
21
  expect(described_class.new).to respond_to :prepare
22
22
  end
23
23
 
24
+ describe '#process_query' do
25
+ let(:client) { described_class.new}
26
+ let(:url) { '/library/base/R/identity/json' }
27
+ let(:data) { { some: 'data' } }
28
+ let(:format) { :json }
29
+ let(:response_handler) { -> { nil } }
30
+
31
+ subject { client.send(:process_query, url, data, format) { |response| response_handler(response) } }
32
+
33
+ context 'test mode' do
34
+ it 'calls fake_response_for(url)' do
35
+ allow(OpenCPU).to receive(:test_mode?).and_return true
36
+ expect(client).to receive(:fake_response_for)
37
+ subject
38
+ end
39
+ end
40
+
41
+ context 'no test mode' do
42
+ context 'HTTP failure' do
43
+ it 'returns the appropiate status code' do
44
+ VCR.use_cassette :bad_request do
45
+ expect { subject }.to raise_error OpenCPU::Errors::BadRequest
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+
24
52
  describe 'initializes' do
25
53
 
26
54
  describe 'without configured attributes' do
@@ -167,7 +195,7 @@ describe OpenCPU::Client do
167
195
  VCR.use_cassette :github_animation_flip_coin_error do
168
196
  expect {
169
197
  client.execute(:foo, :bar, {user: "baz", github_remote: true})
170
- }.to raise_error RuntimeError, /400: Bad Request/
198
+ }.to raise_error OpenCPU::Errors::BadRequest, /400/
171
199
  end
172
200
  end
173
201
  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.9.2
4
+ version: 0.10.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: 2016-06-15 00:00:00.000000000 Z
11
+ date: 2016-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yajl-ruby
@@ -164,10 +164,12 @@ files:
164
164
  - lib/opencpu/client.rb
165
165
  - lib/opencpu/configuration.rb
166
166
  - lib/opencpu/delayed_calculation.rb
167
+ - lib/opencpu/errors.rb
167
168
  - lib/opencpu/version.rb
168
169
  - opencpu.gemspec
169
170
  - spec/fixtures/test.csv
170
171
  - spec/fixtures/vcr_cassettes/animation_flip_coin.yml
172
+ - spec/fixtures/vcr_cassettes/bad_request.yml
171
173
  - spec/fixtures/vcr_cassettes/description.yml
172
174
  - spec/fixtures/vcr_cassettes/digest_hmac.yml
173
175
  - spec/fixtures/vcr_cassettes/digest_hmac_no_parameters.yml
@@ -202,13 +204,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
204
  version: '0'
203
205
  requirements: []
204
206
  rubyforge_project:
205
- rubygems_version: 2.4.6
207
+ rubygems_version: 2.4.5.1
206
208
  signing_key:
207
209
  specification_version: 4
208
210
  summary: Wrapper around OpenCPU REST API
209
211
  test_files:
210
212
  - spec/fixtures/test.csv
211
213
  - spec/fixtures/vcr_cassettes/animation_flip_coin.yml
214
+ - spec/fixtures/vcr_cassettes/bad_request.yml
212
215
  - spec/fixtures/vcr_cassettes/description.yml
213
216
  - spec/fixtures/vcr_cassettes/digest_hmac.yml
214
217
  - spec/fixtures/vcr_cassettes/digest_hmac_no_parameters.yml
@@ -223,3 +226,4 @@ test_files:
223
226
  - spec/lib/opencpu/delayed_calculation_spec.rb
224
227
  - spec/lib/opencpu_spec.rb
225
228
  - spec/spec_helper.rb
229
+ has_rdoc: