opencpu 0.7.3 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f069794c0f3a81cd0b450e272d420a6492e47483
4
- data.tar.gz: 98eb45b503ce28cb028afb7ea35ae02df3e70e58
3
+ metadata.gz: 692156fd560c99e19bc184df8acbcabf7b23610c
4
+ data.tar.gz: 5119dc3829d33cf321f9a9c59dd93b7671120053
5
5
  SHA512:
6
- metadata.gz: 91bfef43f724e63b13012ac748b2121fa62bbb106debbe77a63086fff869ac2ef1bceb577b23692fd816ae85e95e3de7664d7ccb69d2bece38e43ee1b768cd1f
7
- data.tar.gz: f385b0c5c4fc23811305397319b4ab3f42504ceecffc487e15a4d4c6b7611ac3fe5566e2aaff18b48c88d67a84567c7633242d4e4b9163674a77d2e3f8535dc6
6
+ metadata.gz: 0c63135c6eb7a4e80d4212975445bb3a6180fc57fa062ac6dadf8661b0a7f07b29195df8c1e1770f32ee876d12f58710f6eba25b663021c1741ac95a5797ccfe
7
+ data.tar.gz: f51be79f860c06b6e9109c15a4637b8913d92059a24116c4039c9f8cf64d5425b159a0800ee3d65edd34b948aa990c13aad63c94c92a28e2befcebe237a7498c
data/lib/opencpu.rb CHANGED
@@ -42,6 +42,10 @@ module OpenCPU
42
42
  key = [package, script].join('/')
43
43
  self.configuration.add_fake_response key, response
44
44
  end
45
+
46
+ def self.reset_configuration!
47
+ self.configuration.reset!
48
+ end
45
49
  end
46
50
 
47
51
 
@@ -25,7 +25,16 @@ module OpenCPU
25
25
 
26
26
  def process_query(url, data, &block)
27
27
  return fake_response_for(url) if OpenCPU.test_mode?
28
- options = { body: data.to_json, headers: { "Content-Type" => 'application/json' } }
28
+ options = {
29
+ body: data.to_json,
30
+ headers: {"Content-Type" => 'application/json'}
31
+ }
32
+
33
+ if OpenCPU.configuration.username && OpenCPU.configuration.password
34
+ options[:basic_auth] = {
35
+ username: OpenCPU.configuration.username, password: OpenCPU.configuration.password
36
+ }
37
+ end
29
38
  response = self.class.post(url, options)
30
39
 
31
40
  case response.code
@@ -18,5 +18,14 @@ module OpenCPU
18
18
  def remove_fake_response(key)
19
19
  @fake_responses.delete key
20
20
  end
21
+
22
+ def reset!
23
+ @endpoint_url = nil
24
+ @timeout = nil
25
+ @username = nil
26
+ @password = nil
27
+ @mode = nil
28
+ @fake_responses = {}
29
+ end
21
30
  end
22
31
  end
@@ -1,6 +1,6 @@
1
1
  module OpenCPU
2
2
  MAJOR = 0
3
3
  MINOR = 7
4
- TINY = 3
4
+ TINY = 4
5
5
  VERSION = [MAJOR, MINOR, TINY].join('.')
6
6
  end
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: post
5
- uri: https://staging.opencpu.roqua.nl/ocpu/user/deploy/library/digest/R/hmac/json
5
+ uri: https://foo:bar@staging.opencpu.roqua.nl/ocpu/user/deploy/library/digest/R/hmac/json
6
6
  body:
7
7
  encoding: UTF-8
8
8
  string: '{"key":"foo","object":"bar"}'
@@ -36,11 +36,11 @@ describe OpenCPU::Client do
36
36
  end
37
37
  end
38
38
 
39
- it 'sets the base uri' do
39
+ it 'sets base uri' do
40
40
  expect(described_class.new.class.base_uri).to eq 'https://public.opencpu.org/ocpu'
41
41
  end
42
42
 
43
- it 'sets the default_timeout' do
43
+ it 'sets default_timeout' do
44
44
  expect(described_class.new.class.default_options[:timeout]).to eq 123
45
45
  end
46
46
  end
@@ -70,14 +70,14 @@ describe OpenCPU::Client do
70
70
  let(:client) { described_class.new }
71
71
 
72
72
  it 'is used to quickly return JSON results' do
73
- VCR.use_cassette :animation_flip_coin, record: :new_episodes do
73
+ VCR.use_cassette :animation_flip_coin do
74
74
  response = client.execute(:animation, 'flip.coin')
75
75
  expect(response).to eq "freq" => [0.56, 0.44], "nmax" => [50]
76
76
  end
77
77
  end
78
78
 
79
79
  it 'accepts R-function parameters as data' do
80
- VCR.use_cassette :digest_hmac, record: :new_episodes do
80
+ VCR.use_cassette :digest_hmac do
81
81
  response = client.execute(:digest, :hmac, data: { key: 'baz', object: 'qux' })
82
82
  expect(response).to eq ["22e2a7a268bf076801eefe7cd0119bb9"]
83
83
  end
@@ -93,12 +93,15 @@ describe OpenCPU::Client do
93
93
  before do
94
94
  OpenCPU.configure do |config|
95
95
  config.endpoint_url = 'https://staging.opencpu.roqua.nl/ocpu'
96
+ config.username = 'foo'
97
+ config.password = 'bar'
98
+ config.timeout = 123
96
99
  end
97
100
  end
98
101
  let(:client) { described_class.new }
99
102
 
100
103
  it "can access user packages" do
101
- VCR.use_cassette :user_digest_hmac, record: :new_episodes do
104
+ VCR.use_cassette :user_digest_hmac do
102
105
  response = client.execute(:digest, :hmac, user: 'deploy', data: { key: 'foo', object: 'bar' })
103
106
  expect(response).to eq ["0c7a250281315ab863549f66cd8a3a53"]
104
107
  end
@@ -128,5 +131,4 @@ describe OpenCPU::Client do
128
131
  end
129
132
  end
130
133
  end
131
-
132
134
  end
@@ -72,4 +72,21 @@ describe OpenCPU::Configuration do
72
72
  expect(config.fake_responses).to eq({})
73
73
  end
74
74
  end
75
+
76
+ describe "#reset!" do
77
+ let(:config) do
78
+ described_class.new.tap do |config|
79
+ config.endpoint_url = 'http://example.com'
80
+ config.username = 'foo'
81
+ config.password = 'bar'
82
+ end
83
+ end
84
+ it "resets already set configuration" do
85
+ config.reset!
86
+ expect(config.endpoint_url).to be_nil
87
+ expect(config.username).to be_nil
88
+ expect(config.password).to be_nil
89
+ expect(config.fake_responses).to eq({})
90
+ end
91
+ end
75
92
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe OpenCPU::DelayedCalculation do
4
4
 
5
5
  let(:delayed_calculation) { described_class.new 'foo' }
6
-
6
+
7
7
  describe "initializes" do
8
8
  it "without resources" do
9
9
  delayed_calculation = described_class.new 'foo'
@@ -25,7 +25,7 @@ describe OpenCPU::DelayedCalculation do
25
25
  it "with resources" do
26
26
  delayed_calculation = described_class.new 'https://opencpu.org/foo/', resources
27
27
  expect(delayed_calculation.available_resources).to eq parsed_resources
28
- end
28
+ end
29
29
  end
30
30
 
31
31
  let(:location) { "https://public.opencpu.org/ocpu/tmp/x09dd995a16/" }
@@ -42,30 +42,30 @@ describe OpenCPU::DelayedCalculation do
42
42
  ]
43
43
  end
44
44
  let(:delayed_calculation) { described_class.new location, resources }
45
-
45
+
46
46
  describe "#graphics" do
47
47
 
48
48
  it 'defines methods to access graphic functions' do
49
- VCR.use_cassette :animation_flip_coin, record: :new_episodes do
49
+ VCR.use_cassette :animation_flip_coin do
50
50
  expect { delayed_calculation.graphics }.not_to raise_error
51
51
  expect { delayed_calculation.stdout }.to raise_error OpenCPU::ResponseNotAvailableError
52
52
  end
53
53
  end
54
54
 
55
55
  it "returns a SVG by default" do
56
- VCR.use_cassette :animation_flip_coin, record: :new_episodes do
56
+ VCR.use_cassette :animation_flip_coin do
57
57
  expect(delayed_calculation.graphics).to include 'svg xmlns'
58
58
  end
59
59
  end
60
60
 
61
61
  it "can return a PNG" do
62
- VCR.use_cassette :animation_flip_coin, record: :new_episodes do
62
+ VCR.use_cassette :animation_flip_coin do
63
63
  expect(delayed_calculation.graphics(0, :png)).to include 'PNG'
64
64
  end
65
65
  end
66
66
 
67
67
  it "does not support formats except PNG and SVG" do
68
- VCR.use_cassette :animation_flip_coin, record: :new_episodes do
68
+ VCR.use_cassette :animation_flip_coin do
69
69
  expect { delayed_calculation.graphics(0, :svg) }.not_to raise_error
70
70
  expect { delayed_calculation.graphics(0, :png) }.not_to raise_error
71
71
  expect { delayed_calculation.graphics(0, :foo) }.to raise_error OpenCPU::UnsupportedFormatError
@@ -74,14 +74,14 @@ describe OpenCPU::DelayedCalculation do
74
74
  end
75
75
 
76
76
  it 'can handle multiple graphic output' do
77
-
77
+
78
78
  end
79
79
  end
80
80
 
81
81
  describe 'standard getters' do
82
82
  describe '#value' do
83
83
  it "returns raw R calculation result" do
84
- VCR.use_cassette :animation_flip_coin, record: :new_episodes do
84
+ VCR.use_cassette :animation_flip_coin do
85
85
  expect(delayed_calculation.value).to eq "$freq\n 1 2 \n0.52 0.48 \n\n$nmax\n[1] 50"
86
86
  end
87
87
  end
@@ -89,7 +89,7 @@ describe OpenCPU::DelayedCalculation do
89
89
 
90
90
  describe '#stdout' do
91
91
  it "returns cached stdout" do
92
- VCR.use_cassette :animation_flip_coin, record: :new_episodes do
92
+ VCR.use_cassette :animation_flip_coin do
93
93
  expect { delayed_calculation.stdout }.to raise_error OpenCPU::ResponseNotAvailableError
94
94
  end
95
95
  end
@@ -97,15 +97,15 @@ describe OpenCPU::DelayedCalculation do
97
97
 
98
98
  describe '#warnings' do
99
99
  it 'returns cached warnings' do
100
- VCR.use_cassette :animation_flip_coin, record: :new_episodes do
100
+ VCR.use_cassette :animation_flip_coin do
101
101
  expect { delayed_calculation.warnings }.to raise_error OpenCPU::ResponseNotAvailableError
102
102
  end
103
- end
103
+ end
104
104
  end
105
105
 
106
106
  describe '#info' do
107
107
  it 'returns cached info' do
108
- VCR.use_cassette :animation_flip_coin, record: :new_episodes do
108
+ VCR.use_cassette :animation_flip_coin do
109
109
  expect(delayed_calculation.info).to include("R version")
110
110
  end
111
111
  end
@@ -113,7 +113,7 @@ describe OpenCPU::DelayedCalculation do
113
113
 
114
114
  # describe "#console" do
115
115
  # it 'returns cached console input' do
116
- # VCR.use_cassette :animation_flip_coin, record: :new_episodes do
116
+ # VCR.use_cassette :animation_flip_coin do
117
117
  # expect(delayed_calculation.console).to include("hmac(key = \"baz\", object = \"qux\"")
118
118
  # end
119
119
  # end
@@ -14,14 +14,18 @@ describe OpenCPU do
14
14
  expect(described_class).to respond_to :configuration
15
15
  end
16
16
 
17
- it "responds to #enable_test_mode" do
17
+ it "responds to #enable_test_mode!" do
18
18
  expect(described_class).to respond_to :enable_test_mode!
19
19
  end
20
20
 
21
- it "responds to #disable_test_mode" do
21
+ it "responds to #disable_test_mode!" do
22
22
  expect(described_class).to respond_to :disable_test_mode!
23
23
  end
24
24
 
25
+ it "responds to #reset_configuration!" do
26
+ expect(described_class).to respond_to :reset_configuration!
27
+ end
28
+
25
29
  describe '#configure' do
26
30
  before do
27
31
  described_class.configure do |config|
@@ -66,4 +70,16 @@ describe OpenCPU do
66
70
  expect(OpenCPU.configuration.fake_responses['hoi/hai']).to be_nil
67
71
  end
68
72
  end
73
+
74
+ describe 'resetting configuration' do
75
+ before do
76
+ described_class.configure do |config|
77
+ config.endpoint_url = 'http://example.com/opencpu'
78
+ end
79
+ end
80
+ it "can reset configuration" do
81
+ described_class.reset_configuration!
82
+ expect(described_class.configuration.endpoint_url).to be_nil
83
+ end
84
+ end
69
85
  end
metadata CHANGED
@@ -1,187 +1,187 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opencpu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.7.4
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-07-14 00:00:00.000000000 Z
11
+ date: 2014-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yajl-ruby
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.2'
20
- - - '>='
20
+ - - ">="
21
21
  - !ruby/object:Gem::Version
22
22
  version: 1.2.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - ~>
27
+ - - "~>"
28
28
  - !ruby/object:Gem::Version
29
29
  version: '1.2'
30
- - - '>='
30
+ - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 1.2.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: httparty
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ~>
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0.12'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ~>
44
+ - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0.12'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - ~>
51
+ - - "~>"
52
52
  - !ruby/object:Gem::Version
53
53
  version: '1.6'
54
- - - '>='
54
+ - - ">="
55
55
  - !ruby/object:Gem::Version
56
56
  version: 1.6.0
57
57
  type: :development
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - ~>
61
+ - - "~>"
62
62
  - !ruby/object:Gem::Version
63
63
  version: '1.6'
64
- - - '>='
64
+ - - ">="
65
65
  - !ruby/object:Gem::Version
66
66
  version: 1.6.0
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: rake
69
69
  requirement: !ruby/object:Gem::Requirement
70
70
  requirements:
71
- - - ~>
71
+ - - "~>"
72
72
  - !ruby/object:Gem::Version
73
73
  version: '10.3'
74
- - - '>='
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
76
  version: 10.3.1
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - ~>
81
+ - - "~>"
82
82
  - !ruby/object:Gem::Version
83
83
  version: '10.3'
84
- - - '>='
84
+ - - ">="
85
85
  - !ruby/object:Gem::Version
86
86
  version: 10.3.1
87
87
  - !ruby/object:Gem::Dependency
88
88
  name: rspec
89
89
  requirement: !ruby/object:Gem::Requirement
90
90
  requirements:
91
- - - ~>
91
+ - - "~>"
92
92
  - !ruby/object:Gem::Version
93
93
  version: '2.14'
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: 2.14.1
97
97
  type: :development
98
98
  prerelease: false
99
99
  version_requirements: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ~>
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
103
  version: '2.14'
104
- - - '>='
104
+ - - ">="
105
105
  - !ruby/object:Gem::Version
106
106
  version: 2.14.1
107
107
  - !ruby/object:Gem::Dependency
108
108
  name: webmock
109
109
  requirement: !ruby/object:Gem::Requirement
110
110
  requirements:
111
- - - ~>
111
+ - - "~>"
112
112
  - !ruby/object:Gem::Version
113
113
  version: '1.17'
114
- - - '>='
114
+ - - ">="
115
115
  - !ruby/object:Gem::Version
116
116
  version: 1.17.4
117
117
  type: :development
118
118
  prerelease: false
119
119
  version_requirements: !ruby/object:Gem::Requirement
120
120
  requirements:
121
- - - ~>
121
+ - - "~>"
122
122
  - !ruby/object:Gem::Version
123
123
  version: '1.17'
124
- - - '>='
124
+ - - ">="
125
125
  - !ruby/object:Gem::Version
126
126
  version: 1.17.4
127
127
  - !ruby/object:Gem::Dependency
128
128
  name: vcr
129
129
  requirement: !ruby/object:Gem::Requirement
130
130
  requirements:
131
- - - ~>
131
+ - - "~>"
132
132
  - !ruby/object:Gem::Version
133
133
  version: '2.9'
134
- - - '>='
134
+ - - ">="
135
135
  - !ruby/object:Gem::Version
136
136
  version: 2.9.0
137
137
  type: :development
138
138
  prerelease: false
139
139
  version_requirements: !ruby/object:Gem::Requirement
140
140
  requirements:
141
- - - ~>
141
+ - - "~>"
142
142
  - !ruby/object:Gem::Version
143
143
  version: '2.9'
144
- - - '>='
144
+ - - ">="
145
145
  - !ruby/object:Gem::Version
146
146
  version: 2.9.0
147
147
  - !ruby/object:Gem::Dependency
148
148
  name: guard-rspec
149
149
  requirement: !ruby/object:Gem::Requirement
150
150
  requirements:
151
- - - ~>
151
+ - - "~>"
152
152
  - !ruby/object:Gem::Version
153
153
  version: '4.2'
154
- - - '>='
154
+ - - ">="
155
155
  - !ruby/object:Gem::Version
156
156
  version: 4.2.8
157
157
  type: :development
158
158
  prerelease: false
159
159
  version_requirements: !ruby/object:Gem::Requirement
160
160
  requirements:
161
- - - ~>
161
+ - - "~>"
162
162
  - !ruby/object:Gem::Version
163
163
  version: '4.2'
164
- - - '>='
164
+ - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: 4.2.8
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: guard-bundler
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - ~>
171
+ - - "~>"
172
172
  - !ruby/object:Gem::Version
173
173
  version: '2.0'
174
- - - '>='
174
+ - - ">="
175
175
  - !ruby/object:Gem::Version
176
176
  version: 2.0.0
177
177
  type: :development
178
178
  prerelease: false
179
179
  version_requirements: !ruby/object:Gem::Requirement
180
180
  requirements:
181
- - - ~>
181
+ - - "~>"
182
182
  - !ruby/object:Gem::Version
183
183
  version: '2.0'
184
- - - '>='
184
+ - - ">="
185
185
  - !ruby/object:Gem::Version
186
186
  version: 2.0.0
187
187
  description: This gem wraps the OpenCPU REST API.
@@ -191,7 +191,7 @@ executables: []
191
191
  extensions: []
192
192
  extra_rdoc_files: []
193
193
  files:
194
- - .gitignore
194
+ - ".gitignore"
195
195
  - Gemfile
196
196
  - Guardfile
197
197
  - LICENSE.txt
@@ -224,17 +224,17 @@ require_paths:
224
224
  - lib
225
225
  required_ruby_version: !ruby/object:Gem::Requirement
226
226
  requirements:
227
- - - '>='
227
+ - - ">="
228
228
  - !ruby/object:Gem::Version
229
229
  version: 1.9.3
230
230
  required_rubygems_version: !ruby/object:Gem::Requirement
231
231
  requirements:
232
- - - '>='
232
+ - - ">="
233
233
  - !ruby/object:Gem::Version
234
234
  version: '0'
235
235
  requirements: []
236
236
  rubyforge_project:
237
- rubygems_version: 2.0.14
237
+ rubygems_version: 2.2.2
238
238
  signing_key:
239
239
  specification_version: 4
240
240
  summary: Wrapper around OpenCPU REST API