nolij_web 1.1.0 → 1.2.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fc3762bd0096669b24ea98624301805113fa207c
4
+ data.tar.gz: 3760f6b1bd03602102a98ee237c1afeeeab4a1f3
5
+ SHA512:
6
+ metadata.gz: c749b2069299e2af3eaffd48e7616a3681f558ea502e99882381b766f77c0a405b4be5e6a235b28772310fc71961bed2145a8b4833b829093c34a81229595c96
7
+ data.tar.gz: 3bfccb342790994659c1feea4769bac4715e2bd17e0ba7cbe0bed611cc592094f811ae7cd736d44b11b2324fad40cb55ceb09ee2a718e6c1f3ce05b5b9e47a5b
data/README.rdoc CHANGED
@@ -33,7 +33,8 @@ Configuration can be passed as an assigned hash
33
33
  config = {
34
34
  :username => 'username',
35
35
  :password => 'password',
36
- :base_url => 'https://somedomain.com/NolijWeb'
36
+ :base_url => 'https://somedomain.com/NolijWeb',
37
+ :verify_ssl => true # optional, defaults to true
37
38
  }
38
39
 
39
40
  Configuration can be read from a YAML file by passing the file path. The file should contain a hash structure:
@@ -41,6 +42,7 @@ Configuration can be read from a YAML file by passing the file path. The file sh
41
42
  :username: 'username'
42
43
  :password: 'password'
43
44
  :base_url: 'https://somedomain.com/NolijWeb'
45
+ :verify_ssl: true # optional, defaults to true
44
46
 
45
47
  == Passing a block to NolijWeb::Handler methods
46
48
  You may pass a custom block to handler methods. Please note that your block should return the response for successful request. Some of the methods rely on parsing XML responses from the server.
@@ -16,7 +16,7 @@ Nolijweb::Connection is the class that handles actual Nolijweb api sessions and
16
16
  ===Manual Usage
17
17
  You can manually establish a connection and use the _custom_connection methods to execute multiple requests in series.
18
18
 
19
- Be sure the close the connection when you are finished.
19
+ Be sure to close the connection when you are finished.
20
20
 
21
21
  conn = NolijWeb::Connection.new(config_hash_or_yaml_path)
22
22
  conn.establish_connection
@@ -30,7 +30,7 @@ Be sure the close the connection when you are finished.
30
30
  attr_reader :connection
31
31
  attr_reader :headers
32
32
 
33
- @@valid_config_keys = [:username, :password, :base_url]
33
+ @@valid_config_keys = [:username, :password, :base_url, :verify_ssl]
34
34
 
35
35
  def initialize(config)
36
36
  if config.is_a?(String)
@@ -51,6 +51,7 @@ Be sure the close the connection when you are finished.
51
51
  @base_url = @config[:base_url] || ''
52
52
  @username = @config[:username] || ''
53
53
  @password = @config[:password] || ''
54
+ @verify_ssl = (@config[:verify_ssl].nil? || @config[:verify_ssl] === true) ? true : !((@config[:verify_ssl] === false) || (@config[:verify_ssl] =~ /^(false|f|no|n|0)$/i))
54
55
  @connection = nil
55
56
  @cookies = nil
56
57
  @headers = {}
@@ -73,7 +74,7 @@ Be sure the close the connection when you are finished.
73
74
  end
74
75
 
75
76
  def establish_connection
76
- @connection = RestClient.post("#{@base_url}/j_spring_security_check", {:j_username => @username, :j_password => @password}) { |response, request, result, &block|
77
+ @connection = post_custom_connection("#{@base_url}/j_spring_security_check", {:j_username => @username, :j_password => @password}) { |response, request, result, &block|
77
78
  if [301, 302, 307].include? response.code
78
79
  response
79
80
  else
@@ -86,7 +87,7 @@ Be sure the close the connection when you are finished.
86
87
  end
87
88
 
88
89
  def close_connection
89
- RestClient.get("#{@base_url}/j_spring_security_logout", :cookies => @cookies) if @connection
90
+ rest_client_wrapper(:get, "#{@base_url}/j_spring_security_logout", :cookies => @cookies) if @connection
90
91
  @connection = nil
91
92
  @cookies = nil
92
93
  @headers = {}
@@ -125,21 +126,28 @@ Be sure the close the connection when you are finished.
125
126
  def get_custom_connection(path, headers = {}, &block)
126
127
  block ||= default_response_handler
127
128
  url = URI.join(@base_url, URI.parse(@base_url).path + '/', path.to_s).to_s
128
- RestClient.get(url, headers, &block)
129
+ rest_client_wrapper(:get, url, headers, &block)
129
130
  end
130
131
 
131
132
  # Use this inside an execute block to make mulitiple calls in the same request
132
133
  def delete_custom_connection(path, headers = {}, &block)
133
134
  block ||= default_response_handler
134
135
  url = URI.join(@base_url, URI.parse(@base_url).path + '/', path.to_s).to_s
135
- RestClient.delete(url, headers, &block)
136
+ rest_client_wrapper(:delete, url, headers, &block)
136
137
  end
137
138
 
138
139
  # Use this inside an execute block to make mulitiple calls in the same request
139
140
  def post_custom_connection(path, payload, headers = {}, &block)
140
141
  block ||= default_response_handler
141
142
  url = URI.join(@base_url, URI.parse(@base_url).path + '/', path.to_s).to_s
142
- RestClient.post(url, payload, headers, &block)
143
+ RestClient::Request.execute(method: :post, url: url, payload: payload, headers: headers, verify_ssl: @verify_ssl, &block)
144
+ end
145
+
146
+ # RestClient.get/put/delete offer no way to pass additional arguments, so
147
+ # a wrapper is recommended:
148
+ # https://github.com/rest-client/rest-client/issues/297
149
+ def rest_client_wrapper(method, url, headers={}, &block)
150
+ RestClient::Request.execute(method: method, url: url, headers: headers, verify_ssl: @verify_ssl, &block)
143
151
  end
144
152
 
145
153
  private
@@ -47,7 +47,7 @@ module NolijWeb
47
47
  # Submit a file.
48
48
  # A local file path is required.
49
49
  # required options: :folder_id
50
- # additional options: :user_code, :wfma_code, :index_code, :dept_code, :custom_name, :folder_name
50
+ # additional options: :user_code, :wfma_code, :index_code, :dept_code, :custom_name
51
51
  def submit_document(local_file, options = {}, &block)
52
52
  folder_id = options[:folder_id]
53
53
  folder_id = if folder_id.kind_of?(Numeric) || folder_id.kind_of?(String)
@@ -1,5 +1,5 @@
1
1
  module NolijWeb
2
2
  class Version
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
@@ -16,12 +16,12 @@ describe NolijWeb::Connection do
16
16
 
17
17
  #stubs connection and requests for full authenticated round trip
18
18
  def stub_connection_round_trip(connection)
19
- @cookies = {'k' => 'v', 'a' => 'b'}
19
+ @cookies = {'a' => 'b'}
20
20
 
21
21
  @stubbed_login = stub_request(:post, "#{@base_url}/j_spring_security_check").
22
- with(:body => {"j_password"=> connection.instance_variable_get(:@password), "j_username"=> connection.instance_variable_get(:@username)}).to_return(:status => 200, :headers => {'Set-Cookie' => to_cookie(@cookies)})
22
+ with(:body => {"j_password"=> connection.instance_variable_get(:@password), "j_username"=> connection.instance_variable_get(:@username)}).to_return(:status => 200, :headers => {'Set-Cookie' => to_cookie(@cookies)}.merge(WEBMOCK_HEADERS))
23
23
 
24
- @stubbed_logout = stub_request(:get, "#{@base_url}/j_spring_security_logout").with(:headers => {'Cookie' => to_cookie(@cookies)})
24
+ @stubbed_logout = stub_request(:get, "#{@base_url}/j_spring_security_logout").with(:headers => {'Cookie' => to_cookie(@cookies)}.merge(WEBMOCK_HEADERS))
25
25
  end
26
26
 
27
27
  describe '# initialize' do
@@ -134,6 +134,72 @@ with(:body => {"j_password"=> connection.instance_variable_get(:@password), "j_u
134
134
  it "should define nil cookies" do
135
135
  @conn.instance_variable_get(:@cookies).must_be_nil
136
136
  end
137
+
138
+ it "should default to verifying SSL" do
139
+ @conn.instance_variable_get(:@verify_ssl).must_equal true
140
+ end
141
+
142
+ it "should interpret boolean settings for verifying SSL" do
143
+ @conn.configure({:verify_ssl => true})
144
+ @conn.instance_variable_get(:@verify_ssl).must_equal true
145
+ @conn.configure({:verify_ssl => false})
146
+ @conn.instance_variable_get(:@verify_ssl).must_equal false
147
+ end
148
+
149
+ it "should interpret true|false string settings for verifying SSL" do
150
+ @conn.configure({:verify_ssl => 'true'})
151
+ @conn.instance_variable_get(:@verify_ssl).must_equal true
152
+ @conn.configure({:verify_ssl => 'false'})
153
+ @conn.instance_variable_get(:@verify_ssl).must_equal false
154
+ end
155
+
156
+ it "should use the default (true) when a weird setting is used for verifying SSL" do
157
+ @conn.configure({:verify_ssl => 'something weird!'})
158
+ @conn.instance_variable_get(:@verify_ssl).must_equal true
159
+ end
160
+
161
+ it "should interpret t|f settings for verifying SSL" do
162
+ @conn.configure({:verify_ssl => 't'})
163
+ @conn.instance_variable_get(:@verify_ssl).must_equal true
164
+ @conn.configure({:verify_ssl => 'f'})
165
+ @conn.instance_variable_get(:@verify_ssl).must_equal false
166
+ end
167
+
168
+ it "should interpret yes|no settings for verifying SSL" do
169
+ @conn.configure({:verify_ssl => 'yes'})
170
+ @conn.instance_variable_get(:@verify_ssl).must_equal true
171
+ @conn.configure({:verify_ssl => 'no'})
172
+ @conn.instance_variable_get(:@verify_ssl).must_equal false
173
+ end
174
+
175
+ it "should interpret y|n settings for verifying SSL" do
176
+ @conn.configure({:verify_ssl => 'y'})
177
+ @conn.instance_variable_get(:@verify_ssl).must_equal true
178
+ @conn.configure({:verify_ssl => 'n'})
179
+ @conn.instance_variable_get(:@verify_ssl).must_equal false
180
+ end
181
+
182
+ it "should interpret 1|0 settings for verifying SSL" do
183
+ @conn.configure({:verify_ssl => '1'})
184
+ @conn.instance_variable_get(:@verify_ssl).must_equal true
185
+ @conn.configure({:verify_ssl => '0'})
186
+ @conn.instance_variable_get(:@verify_ssl).must_equal false
187
+ end
188
+
189
+ it "should interpret T|F settings for verifying SSL" do
190
+ @conn.configure({:verify_ssl => 'T'})
191
+ @conn.instance_variable_get(:@verify_ssl).must_equal true
192
+ @conn.configure({:verify_ssl => 'F'})
193
+ @conn.instance_variable_get(:@verify_ssl).must_equal false
194
+ end
195
+
196
+ it "should interpret Y|N settings for verifying SSL" do
197
+ @conn.configure({:verify_ssl => 'Y'})
198
+ @conn.instance_variable_get(:@verify_ssl).must_equal true
199
+ @conn.configure({:verify_ssl => 'N'})
200
+ @conn.instance_variable_get(:@verify_ssl).must_equal false
201
+ end
202
+
137
203
  end
138
204
 
139
205
  describe '#configure_with' do
@@ -243,7 +309,7 @@ with(:body => {"j_password"=> connection.instance_variable_get(:@password), "j_u
243
309
  before do
244
310
  setup_configured_connection
245
311
  stub_connection_round_trip(@conn)
246
- @stubbed_get = stub_request(:get, "#{@base_url}/go").to_return(:status => 200, :headers => {'Cookie' => to_cookie(@cookies)})
312
+ @stubbed_get = stub_request(:get, "#{@base_url}/go").to_return(:status => 200, :headers => {'Cookie' => to_cookie(@cookies)}.merge(WEBMOCK_HEADERS))
247
313
  end
248
314
 
249
315
  it "should not open connection" do
@@ -266,7 +332,7 @@ with(:body => {"j_password"=> connection.instance_variable_get(:@password), "j_u
266
332
  before do
267
333
  setup_configured_connection
268
334
  stub_connection_round_trip(@conn)
269
- @stubbed_get = stub_request(:get, "#{@base_url}/go").to_return(:status => 200, :headers => {'Cookie' => to_cookie(@cookies)})
335
+ @stubbed_get = stub_request(:get, "#{@base_url}/go").to_return(:status => 200, :headers => {'Cookie' => to_cookie(@cookies)}.merge(WEBMOCK_HEADERS))
270
336
  end
271
337
 
272
338
  it "should open connection" do
@@ -289,7 +355,7 @@ with(:body => {"j_password"=> connection.instance_variable_get(:@password), "j_u
289
355
  before do
290
356
  setup_configured_connection
291
357
  stub_connection_round_trip(@conn)
292
- @stubbed_get = stub_request(:delete, "#{@base_url}/go").to_return(:status => 200, :headers => {'Cookie' => to_cookie(@cookies)})
358
+ @stubbed_get = stub_request(:delete, "#{@base_url}/go").to_return(:status => 200, :headers => {'Cookie' => to_cookie(@cookies)}.merge(WEBMOCK_HEADERS))
293
359
  end
294
360
 
295
361
  it "should not open connection" do
@@ -312,7 +378,7 @@ with(:body => {"j_password"=> connection.instance_variable_get(:@password), "j_u
312
378
  before do
313
379
  setup_configured_connection
314
380
  stub_connection_round_trip(@conn)
315
- @stubbed_get = stub_request(:delete, "#{@base_url}/go").to_return(:status => 200, :headers => {'Cookie' => to_cookie(@cookies)})
381
+ @stubbed_get = stub_request(:delete, "#{@base_url}/go").to_return(:status => 200, :headers => {'Cookie' => to_cookie(@cookies)}.merge(WEBMOCK_HEADERS))
316
382
  end
317
383
 
318
384
  it "should open connection" do
@@ -336,7 +402,7 @@ with(:body => {"j_password"=> connection.instance_variable_get(:@password), "j_u
336
402
  setup_configured_connection
337
403
  stub_connection_round_trip(@conn)
338
404
  @post_params = {'a' => 'b'}
339
- @stubbed_post = stub_request(:post, "#{@base_url}/go").with(:body => @post_params).to_return(:status => 200, :headers => {'Cookie' => to_cookie(@cookies)})
405
+ @stubbed_post = stub_request(:post, "#{@base_url}/go").with(:body => @post_params).to_return(:status => 200, :headers => {'Cookie' => to_cookie(@cookies)}.merge(WEBMOCK_HEADERS))
340
406
  end
341
407
 
342
408
  it "should not open connection" do
@@ -360,7 +426,7 @@ with(:body => {"j_password"=> connection.instance_variable_get(:@password), "j_u
360
426
  setup_configured_connection
361
427
  stub_connection_round_trip(@conn)
362
428
  @post_params = {'a' => 'b'}
363
- @stubbed_post = stub_request(:post, "#{@base_url}/go").with(:body => @post_params).to_return(:status => 200, :headers => {'Cookie' => to_cookie(@cookies)})
429
+ @stubbed_post = stub_request(:post, "#{@base_url}/go").with(:body => @post_params).to_return(:status => 200, :headers => {'Cookie' => to_cookie(@cookies)}.merge(WEBMOCK_HEADERS))
364
430
  end
365
431
 
366
432
  it "should open connection" do
data/test/test_helper.rb CHANGED
@@ -8,4 +8,6 @@ require 'webmock/minitest'
8
8
 
9
9
  require File.expand_path('../../lib/nolij_web.rb', __FILE__)
10
10
 
11
- WebMock.disable_net_connect!
11
+ WebMock.disable_net_connect!(:allow_localhost => true)
12
+
13
+ WEBMOCK_HEADERS = {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}
metadata CHANGED
@@ -1,110 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nolij_web
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Shannon Henderson
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-05-22 00:00:00.000000000 Z
11
+ date: 2015-06-09 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rest-client
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.6'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.6'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: nokogiri
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '1.6'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '1.6'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: minitest
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: 5.0.0
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
54
  version: 5.0.0
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: bundler
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ~>
59
+ - - "~>"
68
60
  - !ruby/object:Gem::Version
69
61
  version: '1.3'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ~>
66
+ - - "~>"
76
67
  - !ruby/object:Gem::Version
77
68
  version: '1.3'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rake
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: webmock
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ~>
87
+ - - "~>"
100
88
  - !ruby/object:Gem::Version
101
89
  version: '1.13'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ~>
94
+ - - "~>"
108
95
  - !ruby/object:Gem::Version
109
96
  version: '1.13'
110
97
  description: A Ruby wrapper for the Nolij Web API
@@ -116,7 +103,7 @@ extra_rdoc_files:
116
103
  - README.rdoc
117
104
  - LICENSE.txt
118
105
  files:
119
- - .gitignore
106
+ - ".gitignore"
120
107
  - Gemfile
121
108
  - LICENSE.txt
122
109
  - README.rdoc
@@ -146,31 +133,30 @@ files:
146
133
  homepage: https://github.com/reed-college/nolij_web/
147
134
  licenses:
148
135
  - MIT
136
+ metadata: {}
149
137
  post_install_message:
150
138
  rdoc_options:
151
- - --line-numbers
152
- - --inline-source
153
- - --main
139
+ - "--line-numbers"
140
+ - "--inline-source"
141
+ - "--main"
154
142
  - README.rdoc
155
143
  require_paths:
156
144
  - lib
157
145
  required_ruby_version: !ruby/object:Gem::Requirement
158
- none: false
159
146
  requirements:
160
- - - ! '>='
147
+ - - ">="
161
148
  - !ruby/object:Gem::Version
162
149
  version: 1.9.3
163
150
  required_rubygems_version: !ruby/object:Gem::Requirement
164
- none: false
165
151
  requirements:
166
- - - ! '>='
152
+ - - ">="
167
153
  - !ruby/object:Gem::Version
168
154
  version: '0'
169
155
  requirements: []
170
156
  rubyforge_project:
171
- rubygems_version: 1.8.23
157
+ rubygems_version: 2.2.2
172
158
  signing_key:
173
- specification_version: 3
159
+ specification_version: 4
174
160
  summary: Interact with Nolijweb's REST API
175
161
  test_files:
176
162
  - test/nolij_web/attribute_missing_error_test.rb