opensrs 0.3.6 → 0.4.2

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
- SHA1:
3
- metadata.gz: 859e3e67b33ab3a4c5f7c071531a409e16048650
4
- data.tar.gz: ca25ef41d7a29a3f8bd1b491a022c4af1135caf1
2
+ SHA256:
3
+ metadata.gz: 7bf3d8a1a7fc99157bf196ab56c8d34832ef523160a9d092a3db0e5b17de2e7f
4
+ data.tar.gz: dc587d48682875b59af971baf6b5552437f5da5fcffea5030985d848c7986457
5
5
  SHA512:
6
- metadata.gz: 783c86e4637b6f6ba6f4c12e4519118e42e3c4e700c2ccf2ad702021ebe569d3a62e419f167827e74176ea1b2892cbd78d6768fcf94f73ee88c4fd8180d093ed
7
- data.tar.gz: 8d271520d7d262eb3c11cf5645d3849e1f03ebfcf727fe4c1f2043d800a9dfdac745dd7d4f7b04d6d2fd9152daa05f7d1c630ade248d6a8f32c6b12b07916503
6
+ metadata.gz: 9b00c5ad6a516c5f00fd292e81b437abb496c47cfd5b690cd44e6113bf1ac613bd348561caafb420bb94891e4b2bf319b1e947592c780c23c0e97147e4dfa1fa
7
+ data.tar.gz: 6ae7ca1eb7b675d079015b37b6efc79740ba98dabce8aa60a6f79fe610ca3f30bb75014ee54b0edb4ee6cc97c9050b8eca1ccf82acb3d82b6952f00f90f29dbe
@@ -0,0 +1,43 @@
1
+ # pulled from repo
2
+ name: "Rubocop"
3
+
4
+ on:
5
+ push:
6
+ branches: [ master, rubocop ]
7
+ pull_request:
8
+ # The branches below must be a subset of the branches above
9
+ branches: [ master, rubocop ]
10
+ schedule:
11
+ - cron: '37 10 * * 2'
12
+
13
+ jobs:
14
+ rubocop:
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ fail-fast: false
18
+
19
+ steps:
20
+ - name: Checkout repository
21
+ uses: actions/checkout@v2
22
+
23
+ # If running on a self-hosted runner, check it meets the requirements
24
+ # listed at https://github.com/ruby/setup-ruby#using-self-hosted-runners
25
+ - name: Set up Ruby
26
+ uses: ruby/setup-ruby@v1
27
+ with:
28
+ ruby-version: 2.6
29
+
30
+ - name: Install dependencies
31
+ run: bundle install
32
+
33
+ - name: Rubocop run
34
+ run: |
35
+ bash -c "
36
+ bundle exec rubocop --require code_scanning --format CodeScanning::SarifFormatter -o rubocop.sarif
37
+ [[ $? -ne 2 ]]
38
+ "
39
+
40
+ - name: Upload Sarif output
41
+ uses: github/codeql-action/upload-sarif@v1
42
+ with:
43
+ sarif_file: rubocop.sarif
@@ -0,0 +1,28 @@
1
+ name: Ruby
2
+
3
+ on: push
4
+
5
+ jobs:
6
+ test:
7
+ name: "Rspec (on Ruby ${{ matrix.ruby }})"
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ fail-fast: false
11
+ matrix:
12
+ ruby: ['2.5', '2.6', '2.7', '3.0', '3.1', 'head']
13
+
14
+ steps:
15
+ - name: Set up Ruby ${{ matrix.ruby }}
16
+ uses: ruby/setup-ruby@v1
17
+ with:
18
+ bundler-cache: true
19
+ ruby-version: ${{ matrix.ruby }}
20
+
21
+ - name: Checkout repository
22
+ uses: actions/checkout@v2
23
+
24
+ - name: Install dependencies
25
+ run: gem install bundler && bundle install
26
+
27
+ - name: Run Rspec
28
+ run: bundle exec rspec spec
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  /.bundle/
2
+ /.vscode
2
3
  /.yardoc
3
4
  /Gemfile.lock
4
5
  /_yardoc/
@@ -13,3 +14,5 @@
13
14
  *.a
14
15
  *.gem
15
16
  mkmf.log
17
+ *.sarif
18
+ /vendor
data/.rubocop.yml ADDED
@@ -0,0 +1,131 @@
1
+ require: rubocop-rspec
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.5
5
+ SuggestExtensions: false
6
+
7
+ Style/FrozenStringLiteralComment:
8
+ Enabled: false
9
+
10
+ RSpec/InstanceVariable:
11
+ Enabled: false
12
+
13
+ Metrics/BlockLength:
14
+ Enabled: false
15
+
16
+ RSpec/FilePath:
17
+ Enabled: false
18
+
19
+ Layout/LineLength:
20
+ Enabled: false
21
+
22
+ RSpec/MultipleExpectations:
23
+ Enabled: false
24
+
25
+ RSpec/ExampleLength:
26
+ Enabled: false
27
+
28
+ RSpec/NestedGroups:
29
+ Enabled: false
30
+
31
+ RSpec/MultipleMemoizedHelpers:
32
+ Enabled: false
33
+
34
+ RSpec/MessageSpies:
35
+ Enabled: false
36
+
37
+ RSpec/StubbedMock:
38
+ Enabled: false
39
+
40
+ RSpec/VerifiedDoubles:
41
+ Enabled: false
42
+
43
+ Metrics/MethodLength:
44
+ Enabled: false
45
+
46
+ Metrics/AbcSize:
47
+ Enabled: false
48
+
49
+ Style/ClassVars:
50
+ Enabled: false
51
+
52
+ Gemspec/DateAssignment: # (new in 1.10)
53
+ Enabled: true
54
+ Layout/LineEndStringConcatenationIndentation: # (new in 1.18)
55
+ Enabled: true
56
+ Layout/SpaceBeforeBrackets: # (new in 1.7)
57
+ Enabled: true
58
+ Lint/AmbiguousAssignment: # (new in 1.7)
59
+ Enabled: true
60
+ Lint/AmbiguousRange: # (new in 1.19)
61
+ Enabled: true
62
+ Lint/DeprecatedConstants: # (new in 1.8)
63
+ Enabled: true
64
+ Lint/DuplicateBranch: # (new in 1.3)
65
+ Enabled: true
66
+ Lint/DuplicateRegexpCharacterClassElement: # (new in 1.1)
67
+ Enabled: true
68
+ Lint/EmptyBlock: # (new in 1.1)
69
+ Enabled: true
70
+ Lint/EmptyClass: # (new in 1.3)
71
+ Enabled: true
72
+ Lint/EmptyInPattern: # (new in 1.16)
73
+ Enabled: true
74
+ Lint/LambdaWithoutLiteralBlock: # (new in 1.8)
75
+ Enabled: true
76
+ Lint/NoReturnInBeginEndBlocks: # (new in 1.2)
77
+ Enabled: true
78
+ Lint/NumberedParameterAssignment: # (new in 1.9)
79
+ Enabled: true
80
+ Lint/OrAssignmentToConstant: # (new in 1.9)
81
+ Enabled: true
82
+ Lint/RedundantDirGlobSort: # (new in 1.8)
83
+ Enabled: true
84
+ Lint/SymbolConversion: # (new in 1.9)
85
+ Enabled: true
86
+ Lint/ToEnumArguments: # (new in 1.1)
87
+ Enabled: true
88
+ Lint/TripleQuotes: # (new in 1.9)
89
+ Enabled: true
90
+ Lint/UnexpectedBlockArity: # (new in 1.5)
91
+ Enabled: true
92
+ Lint/UnmodifiedReduceAccumulator: # (new in 1.1)
93
+ Enabled: true
94
+ Naming/InclusiveLanguage: # (new in 1.18)
95
+ Enabled: true
96
+ Style/ArgumentsForwarding: # (new in 1.1)
97
+ Enabled: true
98
+ Style/CollectionCompact: # (new in 1.2)
99
+ Enabled: true
100
+ Style/DocumentDynamicEvalDefinition: # (new in 1.1)
101
+ Enabled: true
102
+ Style/EndlessMethod: # (new in 1.8)
103
+ Enabled: true
104
+ Style/HashConversion: # (new in 1.10)
105
+ Enabled: true
106
+ Style/HashExcept: # (new in 1.7)
107
+ Enabled: true
108
+ Style/IfWithBooleanLiteralBranches: # (new in 1.9)
109
+ Enabled: true
110
+ Style/InPatternThen: # (new in 1.16)
111
+ Enabled: true
112
+ Style/MultilineInPatternThen: # (new in 1.16)
113
+ Enabled: true
114
+ Style/NegatedIfElseCondition: # (new in 1.2)
115
+ Enabled: true
116
+ Style/NilLambda: # (new in 1.3)
117
+ Enabled: true
118
+ Style/QuotedSymbols: # (new in 1.16)
119
+ Enabled: true
120
+ Style/RedundantArgument: # (new in 1.4)
121
+ Enabled: true
122
+ Style/RedundantSelfAssignmentBranch: # (new in 1.19)
123
+ Enabled: true
124
+ Style/StringChars: # (new in 1.12)
125
+ Enabled: true
126
+ Style/SwapValues: # (new in 1.1)
127
+ Enabled: true
128
+ RSpec/IdenticalEqualityAssertion: # (new in 2.4)
129
+ Enabled: true
130
+ RSpec/Rails/AvoidSetupHook: # (new in 2.4)
131
+ Enabled: true
data/Gemfile.lock CHANGED
@@ -1,65 +1,96 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- opensrs (0.3.6)
5
- libxml-ruby (~> 2)
4
+ opensrs (0.4.1)
6
5
 
7
6
  GEM
8
7
  remote: https://rubygems.org/
9
8
  specs:
10
- activesupport (4.2.1)
9
+ activesupport (4.2.11.3)
11
10
  i18n (~> 0.7)
12
- json (~> 1.7, >= 1.7.7)
13
11
  minitest (~> 5.1)
14
12
  thread_safe (~> 0.3, >= 0.3.4)
15
13
  tzinfo (~> 1.1)
16
- coderay (1.1.0)
17
- diff-lcs (1.2.5)
18
- i18n (0.7.0)
19
- json (1.8.2)
20
- libxml-ruby (2.8.0)
21
- method_source (0.8.2)
22
- mini_portile (0.6.2)
23
- minitest (5.6.1)
24
- nokogiri (1.6.6.2)
25
- mini_portile (~> 0.6.0)
26
- pry (0.10.1)
27
- coderay (~> 1.1.0)
28
- method_source (~> 0.8.1)
29
- slop (~> 3.4)
30
- rake (10.4.2)
31
- rspec (3.2.0)
32
- rspec-core (~> 3.2.0)
33
- rspec-expectations (~> 3.2.0)
34
- rspec-mocks (~> 3.2.0)
35
- rspec-core (3.2.3)
36
- rspec-support (~> 3.2.0)
37
- rspec-expectations (3.2.1)
14
+ ast (2.4.2)
15
+ code-scanning-rubocop (0.6.1)
16
+ rubocop (~> 1.0)
17
+ coderay (1.1.3)
18
+ concurrent-ruby (1.1.10)
19
+ diff-lcs (1.5.0)
20
+ i18n (0.9.5)
21
+ concurrent-ruby (~> 1.0)
22
+ libxml-ruby (3.2.2)
23
+ method_source (1.0.0)
24
+ mini_portile2 (2.8.0)
25
+ minitest (5.15.0)
26
+ nokogiri (1.13.6)
27
+ mini_portile2 (~> 2.8.0)
28
+ racc (~> 1.4)
29
+ parallel (1.22.1)
30
+ parser (3.1.2.0)
31
+ ast (~> 2.4.1)
32
+ pry (0.14.1)
33
+ coderay (~> 1.1)
34
+ method_source (~> 1.0)
35
+ racc (1.6.0)
36
+ rainbow (3.1.1)
37
+ rake (13.0.6)
38
+ regexp_parser (2.4.0)
39
+ rexml (3.2.5)
40
+ rspec (3.11.0)
41
+ rspec-core (~> 3.11.0)
42
+ rspec-expectations (~> 3.11.0)
43
+ rspec-mocks (~> 3.11.0)
44
+ rspec-core (3.11.0)
45
+ rspec-support (~> 3.11.0)
46
+ rspec-expectations (3.11.0)
38
47
  diff-lcs (>= 1.2.0, < 2.0)
39
- rspec-support (~> 3.2.0)
40
- rspec-mocks (3.2.1)
48
+ rspec-support (~> 3.11.0)
49
+ rspec-mocks (3.11.1)
41
50
  diff-lcs (>= 1.2.0, < 2.0)
42
- rspec-support (~> 3.2.0)
43
- rspec-support (3.2.2)
44
- shoulda (3.5.0)
45
- shoulda-context (~> 1.0, >= 1.0.1)
46
- shoulda-matchers (>= 1.4.1, < 3.0)
47
- shoulda-context (1.2.1)
48
- shoulda-matchers (2.8.0)
49
- activesupport (>= 3.0.0)
50
- slop (3.6.0)
51
- thread_safe (0.3.5)
52
- tzinfo (1.2.2)
51
+ rspec-support (~> 3.11.0)
52
+ rspec-support (3.11.0)
53
+ rubocop (1.29.0)
54
+ parallel (~> 1.10)
55
+ parser (>= 3.1.0.0)
56
+ rainbow (>= 2.2.2, < 4.0)
57
+ regexp_parser (>= 1.8, < 3.0)
58
+ rexml (>= 3.2.5, < 4.0)
59
+ rubocop-ast (>= 1.17.0, < 2.0)
60
+ ruby-progressbar (~> 1.7)
61
+ unicode-display_width (>= 1.4.0, < 3.0)
62
+ rubocop-ast (1.17.0)
63
+ parser (>= 3.1.1.0)
64
+ rubocop-rspec (2.10.0)
65
+ rubocop (~> 1.19)
66
+ ruby-progressbar (1.11.0)
67
+ shoulda (4.0.0)
68
+ shoulda-context (~> 2.0)
69
+ shoulda-matchers (~> 4.0)
70
+ shoulda-context (2.0.0)
71
+ shoulda-matchers (4.5.1)
72
+ activesupport (>= 4.2.0)
73
+ thread_safe (0.3.6)
74
+ tzinfo (1.2.9)
53
75
  thread_safe (~> 0.1)
76
+ unicode-display_width (2.1.0)
54
77
 
55
78
  PLATFORMS
56
79
  ruby
57
80
 
58
81
  DEPENDENCIES
82
+ activesupport (~> 4.2.2)
59
83
  bundler
60
- nokogiri
84
+ code-scanning-rubocop (~> 0.5)
85
+ libxml-ruby (~> 3)
86
+ nokogiri (~> 1.13.4)
61
87
  opensrs!
62
88
  pry
63
89
  rake
64
90
  rspec
91
+ rubocop (~> 1)
92
+ rubocop-rspec
65
93
  shoulda
94
+
95
+ BUNDLED WITH
96
+ 2.3.13
data/README.md CHANGED
@@ -1,17 +1,13 @@
1
1
  # OpenSRS
2
2
 
3
- [![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/voxxit/opensrs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
-
5
- [![Build Status](https://travis-ci.org/voxxit/opensrs.svg?branch=master)](https://travis-ci.org/voxxit/opensrs)
6
- [![Code Climate](https://codeclimate.com/github/voxxit/opensrs/badges/gpa.svg)](https://codeclimate.com/github/voxxit/opensrs)
7
3
  [![Coverage Status](https://img.shields.io/coveralls/voxxit/opensrs.svg)](https://coveralls.io/r/voxxit/opensrs)
8
4
 
9
- This (unofficial) OpenSRS gem provides basic support to connect to, and utilize the [OpenSRS API.](http://www.opensrs.com/site/resources/documentation/api) This library has been well-tested in high-performance production
5
+ This unofficial OpenSRS gem provides basic support to connect to and utilize the [OpenSRS API.](http://www.opensrs.com/site/resources/documentation/api) This library has been well-tested in high-performance production
10
6
  environments.
11
7
 
12
8
  ### Requirements
13
9
 
14
- * Ruby **>= 1.9.2** or **>= 2.0.0** or **>= 2.1.2**
10
+ * Ruby **>= 2.5**
15
11
 
16
12
  ### Installation
17
13
 
@@ -25,7 +21,9 @@ You can then include it in a Ruby project, like so:
25
21
 
26
22
  For Rails 3.x and above, add it to the `Gemfile`:
27
23
 
28
- gem "opensrs"
24
+ gem 'opensrs'
25
+ gem 'nokogiri' # if you want to use nokogiri as the XML parser
26
+ gem 'libxml-ruby' # if you want to use libxml as the XML parser
29
27
 
30
28
  ### Usage
31
29
 
@@ -40,6 +38,10 @@ Currently, the library supports LibXML and Nokogiri as XML parsers. By default,
40
38
 
41
39
  OpenSRS::Server.xml_processor = :nokogiri
42
40
 
41
+ or
42
+
43
+ OpenSRS::Server.xml_processor = :libxml
44
+
43
45
  To connect, instantiate a new <tt>OpenSRS::Server</tt> object:
44
46
 
45
47
  server = OpenSRS::Server.new(
@@ -95,7 +97,6 @@ Responses from OpenSRS are returned in an OpenSRS::Response object, which gives
95
97
  Method | Description
96
98
  ---|---
97
99
  `response.response` | This gives you the response in a Hash form, which is highly accessible to most other actions in your application.
98
- `response.response` | This gives you the response in a Hash form, which is highly accessible to most other actions in your application.
99
100
  `response.errors` | If there are errors which come back from OpenSRS, they are returned here. If not, it returns nil.
100
101
  `response.success?` | Returns true if the response was labeled as successful. If not, it returns false.
101
102
  `response.request_xml` | Returns raw request XML.
@@ -115,15 +116,10 @@ If you have any bugs or feature requests for this gem, feel free to [open an iss
115
116
 
116
117
  ### Contributors (in order of appearance)
117
118
 
118
- * [Joshua Delsman](http://github.com/voxxit)
119
- * Glenn Roberts
119
+ See ["Contributors"](https://github.com/voxxit/opensrs/graphs/contributors) section of GitHub Insights.
120
120
 
121
121
  ### Copyright
122
122
 
123
- Copyright (c) 2010-2014 Joshua Delsman.
123
+ Copyright (c) 2010-2022 Joshua Delsman.
124
124
 
125
125
  Distributed under the MIT license. See `LICENSE` for details.
126
-
127
-
128
- [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/voxxit/opensrs/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
129
-
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
data/SECURITY.md ADDED
@@ -0,0 +1,12 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ | Version | Supported |
6
+ | ------- | ------------------ |
7
+ | 0.4.x | :white_check_mark: |
8
+ | < 0.4.x | :x: |
9
+
10
+ ## Reporting a Vulnerability
11
+
12
+ Please encyrpt your message to me at https://keybase.io/encrypt#jdelsman, then send to j@srv.im. Since this is an unsupported open-source project, I will get to it as quickly as I can.
data/bin/console CHANGED
@@ -1,10 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'bundler/setup'
3
+ require 'opensrs'
2
4
 
3
- require "bundler/setup"
4
- require "opensrs"
5
-
6
- require "pry"
5
+ require 'pry'
7
6
  Pry.start
8
7
 
9
- require "irb"
8
+ require 'irb'
10
9
  IRB.start
@@ -1,4 +1,5 @@
1
1
  module OpenSRS
2
+ # Response
2
3
  class Response
3
4
  attr_reader :request_xml, :response_xml
4
5
  attr_accessor :response, :success
@@ -13,19 +14,22 @@ module OpenSRS
13
14
  # We need to return the error message unless the
14
15
  # response is successful.
15
16
  def errors
16
- unless success?
17
- msg = @response["response_text"]
18
- code = @response["response_code"]
17
+ return if success?
19
18
 
20
- return msg && code ? "#{msg} (Code #{code})" : "Unknown error"
21
- end
19
+ msg = @response['response_text']
20
+ code = @response['response_code']
21
+
22
+ msg && code ? "#{msg} (Code #{code})" : 'Unknown error'
22
23
  end
23
24
 
24
25
  # If 'is_success' is returned, the API is letting us know that they
25
26
  # will explicitly tell us whether something has succeeded or not.
26
- # Otherwise, just assume it is successful.
27
+ #
28
+ # Otherwise, just assume it failed.
27
29
  def success?
28
- @response["is_success"] && @response["is_success"] == "1" ? true : false
30
+ return false unless @response['is_success']
31
+
32
+ @response['is_success'] == '1'
29
33
  end
30
34
  end
31
35
  end
@@ -0,0 +1,21 @@
1
+ require 'delegate'
2
+
3
+ module OpenSRS
4
+ # SanitizableString
5
+ class SanitizableString < SimpleDelegator
6
+ @enable_sanitization = false
7
+
8
+ class << self
9
+ attr_accessor :enable_sanitization
10
+ end
11
+
12
+ def initialize(original_string, sanitized_string)
13
+ super(original_string)
14
+ @sanitized_string = sanitized_string
15
+ end
16
+
17
+ def sanitized
18
+ self.class.enable_sanitization ? @sanitized_string : self
19
+ end
20
+ end
21
+ end
@@ -1,45 +1,53 @@
1
- require "uri"
2
- require "net/https"
3
- require "digest/md5"
4
- require "openssl"
1
+ require 'uri'
2
+ require 'net/https'
3
+ require 'digest/md5'
4
+ require 'openssl'
5
5
 
6
6
  module OpenSRS
7
7
  class OpenSRSError < StandardError; end
8
8
 
9
9
  class BadResponse < OpenSRSError; end
10
+
10
11
  class ConnectionError < OpenSRSError; end
12
+
11
13
  class TimeoutError < ConnectionError; end
12
14
 
15
+ # Server
13
16
  class Server
14
- attr_accessor :server, :username, :password, :key, :timeout, :open_timeout, :logger
17
+ attr_accessor :server, :username, :password, :key, :timeout, :open_timeout, :logger, :proxy
15
18
 
16
19
  def initialize(options = {})
17
- @server = URI.parse(options[:server] || "https://rr-n1-tor.opensrs.net:55443/")
20
+ @server = URI.parse(options[:server] || 'https://rr-n1-tor.opensrs.net:55443/')
18
21
  @username = options[:username]
19
22
  @password = options[:password]
20
23
  @key = options[:key]
21
24
  @timeout = options[:timeout]
22
25
  @open_timeout = options[:open_timeout]
23
26
  @logger = options[:logger]
27
+ @proxy = URI.parse(options[:proxy]) if options[:proxy]
28
+ @sanitize_request = options[:sanitize_request]
29
+
30
+ OpenSRS::SanitizableString.enable_sanitization = @sanitize_request
24
31
  end
25
32
 
26
33
  def call(data = {})
27
- xml = xml_processor.build({ :protocol => "XCP" }.merge!(data))
28
- log('Request', xml, data)
34
+ xml = xml_processor.build({ protocol: 'XCP' }.merge!(data))
35
+ log('Request', xml.sanitized, data)
29
36
 
30
37
  begin
31
38
  response = http.post(server_path, xml, headers(xml))
32
39
  log('Response', response.body, data)
33
40
  rescue Net::HTTPBadResponse
34
- raise OpenSRS::BadResponse, "Received a bad response from OpenSRS. Please check that your IP address is added to the whitelist, and try again."
41
+ raise OpenSRS::BadResponse,
42
+ 'Received a bad response from OpenSRS. Please check that your IP address is added to the whitelist, and try again.'
35
43
  end
36
44
 
37
45
  parsed_response = xml_processor.parse(response.body)
38
- return OpenSRS::Response.new(parsed_response, xml, response.body)
39
- rescue Timeout::Error => err
40
- raise OpenSRS::TimeoutError, err
41
- rescue Errno::ECONNRESET, Errno::ECONNREFUSED => err
42
- raise OpenSRS::ConnectionError, err
46
+ OpenSRS::Response.new(parsed_response, xml.sanitized, response.body)
47
+ rescue Timeout::Error => e
48
+ raise OpenSRS::TimeoutError, e
49
+ rescue Errno::ECONNRESET, Errno::ECONNREFUSED => e
50
+ raise OpenSRS::ConnectionError, e
43
51
  end
44
52
 
45
53
  def xml_processor
@@ -48,19 +56,17 @@ module OpenSRS
48
56
 
49
57
  def self.xml_processor=(name)
50
58
  require "opensrs/xml_processor/#{name.to_s.downcase}"
51
- @@xml_processor = OpenSRS::XmlProcessor.const_get("#{name.to_s.capitalize}")
59
+ @@xml_processor = OpenSRS::XmlProcessor.const_get(name.to_s.capitalize.to_s)
52
60
  end
53
61
 
54
- OpenSRS::Server.xml_processor = :libxml
55
-
56
62
  private
57
63
 
58
64
  def headers(request)
59
65
  {
60
- "Content-Length" => request.length.to_s,
61
- "Content-Type" => "text/xml",
62
- "X-Username" => username,
63
- "X-Signature" => signature(request)
66
+ 'Content-Length' => request.length.to_s,
67
+ 'Content-Type' => 'text/xml',
68
+ 'X-Username' => username,
69
+ 'X-Signature' => signature(request)
64
70
  }
65
71
  end
66
72
 
@@ -69,8 +75,13 @@ module OpenSRS
69
75
  end
70
76
 
71
77
  def http
72
- http = Net::HTTP.new(server.host, server.port)
73
- http.use_ssl = (server.scheme == "https")
78
+ http = if @proxy
79
+ Net::HTTP.new(server.host, server.port, @proxy.host, @proxy.port, @proxy.user, @proxy.password)
80
+ else
81
+ Net::HTTP.new(server.host, server.port)
82
+ end
83
+
84
+ http.use_ssl = (server.scheme == 'https')
74
85
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
75
86
  http.read_timeout = http.open_timeout = @timeout if @timeout
76
87
  http.open_timeout = @open_timeout if @open_timeout
@@ -1,3 +1,3 @@
1
1
  module OpenSRS
2
- VERSION = "0.3.6"
2
+ VERSION = '0.4.2'.freeze
3
3
  end
@@ -1,12 +1,13 @@
1
1
  begin
2
2
  require 'libxml'
3
3
  rescue LoadError => e
4
- $stderr.puts "Cannot find `libxml` gem. Please install it before using it as the XML processor"
4
+ warn 'Cannot find `libxml` gem. Please install it before using it as the XML processor'
5
5
  raise e
6
6
  end
7
7
 
8
8
  module OpenSRS
9
9
  class XmlProcessor
10
+ # Libxml
10
11
  class Libxml < OpenSRS::XmlProcessor
11
12
  include ::LibXML::XML
12
13
 
@@ -14,23 +15,35 @@ module OpenSRS
14
15
  # go ahead and build the entire XML document to send to OpenSRS.
15
16
  def self.build(data)
16
17
  xml = Document.new
17
- xml.root = envelope = Node.new("OPS_envelope")
18
+ xml.root = envelope = Node.new('OPS_envelope')
18
19
 
19
- envelope << header = Node.new("header")
20
- envelope << body = Node.new("body")
21
- header << Node.new("version", "0.9")
22
- body << data_block = Node.new("data_block")
20
+ envelope << header = Node.new('header')
21
+ envelope << body = Node.new('body')
22
+ header << Node.new('version', '0.9')
23
+ body << data_block = Node.new('data_block')
23
24
 
24
25
  data_block << encode_data(data, data_block)
25
26
 
26
- return xml.to_s
27
+ OpenSRS::SanitizableString.new(xml.to_s, sanitize(xml).to_s)
27
28
  end
28
29
 
29
- protected
30
+ def self.sanitize(doc)
31
+ # Before changing the iteration through the nodes, read:
32
+ # https://www.rubydoc.info/gems/libxml-ruby/LibXML/XML/Document#find-instance_method
33
+
34
+ username_nodes = doc.find("//item[@key='reg_username']")
35
+ username_nodes.each { |node| node.content = 'FILTERED' }
36
+
37
+ password_nodes = doc.find("//item[@key='reg_password']")
38
+ password_nodes.each { |node| node.content = 'FILTERED' }
39
+
40
+ doc
41
+ end
42
+ private_class_method :sanitize
30
43
 
31
44
  def self.data_block_element(response)
32
45
  doc = Parser.string(response).parse
33
- return doc.find("//OPS_envelope/body/data_block/*")
46
+ doc.find('//OPS_envelope/body/data_block/*')
34
47
  end
35
48
 
36
49
  def self.decode_dt_array_data(element)
@@ -38,10 +51,11 @@ module OpenSRS
38
51
 
39
52
  element.children.each do |item|
40
53
  next if item.empty?
41
- dt_array[item.attributes["key"].to_i] = decode_data(item)
54
+
55
+ dt_array[item.attributes['key'].to_i] = decode_data(item)
42
56
  end
43
57
 
44
- return dt_array
58
+ dt_array
45
59
  end
46
60
 
47
61
  def self.decode_dt_assoc_data(element)
@@ -49,19 +63,19 @@ module OpenSRS
49
63
 
50
64
  element.children.each do |item|
51
65
  next if item.content.strip.empty?
52
- dt_assoc[item.attributes["key"]] = decode_data(item)
66
+
67
+ dt_assoc[item.attributes['key']] = decode_data(item)
53
68
  end
54
69
 
55
- return dt_assoc
70
+ dt_assoc
56
71
  end
57
72
 
58
73
  # Accepts two parameters but uses only one; to keep the interface same as other xml parser classes
59
74
  # Is that a side effect of Template pattern?
60
75
  #
61
- def self.new_element(element_name, container)
62
- return Node.new(element_name.to_s)
76
+ def self.new_element(element_name, _container)
77
+ Node.new(element_name.to_s)
63
78
  end
64
-
65
79
  end
66
80
  end
67
81
  end
@@ -1,22 +1,22 @@
1
1
  begin
2
2
  require 'nokogiri'
3
3
  rescue LoadError => e
4
- $stderr.puts "Cannot find `nokogiri` gem. Please install it before using it as the XML processor"
4
+ warn 'Cannot find `nokogiri` gem. Please install it before using it as the XML processor'
5
5
  raise e
6
6
  end
7
7
 
8
8
  module OpenSRS
9
9
  class XmlProcessor
10
+ # Nokogiri
10
11
  class Nokogiri < OpenSRS::XmlProcessor
11
-
12
12
  def self.build(data)
13
13
  builder = ::Nokogiri::XML::Builder.new
14
14
 
15
- envelope = ::Nokogiri::XML::Node.new("OPS_envelope", builder.doc)
16
- header = ::Nokogiri::XML::Node.new("header", builder.doc)
17
- version = ::Nokogiri::XML::Node.new("version", builder.doc)
18
- body = ::Nokogiri::XML::Node.new("body", builder.doc)
19
- data_block = ::Nokogiri::XML::Node.new("data_block", builder.doc)
15
+ envelope = ::Nokogiri::XML::Node.new('OPS_envelope', builder.doc)
16
+ header = ::Nokogiri::XML::Node.new('header', builder.doc)
17
+ version = ::Nokogiri::XML::Node.new('version', builder.doc)
18
+ body = ::Nokogiri::XML::Node.new('body', builder.doc)
19
+ data_block = ::Nokogiri::XML::Node.new('data_block', builder.doc)
20
20
  other_data = encode_data(data, builder.doc)
21
21
  version << '0.9'
22
22
  header << version
@@ -25,14 +25,25 @@ module OpenSRS
25
25
  data_block << other_data
26
26
  body << data_block
27
27
  envelope << body
28
- return builder.to_xml
28
+
29
+ OpenSRS::SanitizableString.new(builder.to_xml, sanitize(builder.to_xml))
29
30
  end
30
31
 
31
- protected
32
+ def self.sanitize(xml_string)
33
+ doc = ::Nokogiri::XML(xml_string)
34
+ doc.xpath("//item[@key='reg_username']").each do |node|
35
+ node.content = 'FILTERED'
36
+ end
37
+ doc.xpath("//item[@key='reg_password']").each do |node|
38
+ node.content = 'FILTERED'
39
+ end
40
+ doc.to_xml
41
+ end
42
+ private_class_method :sanitize
32
43
 
33
44
  def self.data_block_element(response)
34
45
  doc = ::Nokogiri::XML(response)
35
- return doc.xpath('//OPS_envelope/body/data_block/*')
46
+ doc.xpath('//OPS_envelope/body/data_block/*')
36
47
  end
37
48
 
38
49
  def self.decode_dt_array_data(element)
@@ -40,10 +51,11 @@ module OpenSRS
40
51
 
41
52
  element.children.each do |item|
42
53
  next if item.content.strip.empty?
43
- dt_array[item.attributes["key"].value.to_i] = decode_data(item.children)
54
+
55
+ dt_array[item.attributes['key'].value.to_i] = decode_data(item.children)
44
56
  end
45
57
 
46
- return dt_array
58
+ dt_array
47
59
  end
48
60
 
49
61
  def self.decode_dt_assoc_data(element)
@@ -51,16 +63,16 @@ module OpenSRS
51
63
 
52
64
  element.children.each do |item|
53
65
  next if item.content.strip.empty?
54
- dt_assoc[item.attributes["key"].value] = decode_data(item.children)
66
+
67
+ dt_assoc[item.attributes['key'].value] = decode_data(item.children)
55
68
  end
56
69
 
57
- return dt_assoc
70
+ dt_assoc
58
71
  end
59
72
 
60
73
  def self.new_element(element_name, container)
61
- return ::Nokogiri::XML::Node.new(element_name.to_s, container)
74
+ ::Nokogiri::XML::Node.new(element_name.to_s, container.document)
62
75
  end
63
-
64
76
  end
65
77
  end
66
78
  end
@@ -1,18 +1,16 @@
1
1
  module OpenSRS
2
+ # XmlProcessor
2
3
  class XmlProcessor
3
-
4
4
  # Parses the main data block from OpenSRS and discards
5
5
  # the rest of the response.
6
6
  def self.parse(response)
7
7
  data_block = data_block_element(response)
8
8
 
9
- raise ArgumentError.new("No data found in document") if !data_block
9
+ raise ArgumentError, 'No data found in document' unless data_block
10
10
 
11
- return decode_data(data_block)
11
+ decode_data(data_block)
12
12
  end
13
13
 
14
- protected
15
-
16
14
  # Encodes individual elements, and their child elements, for the root XML document.
17
15
  def self.encode_data(data, container = nil)
18
16
  case data
@@ -42,11 +40,16 @@ module OpenSRS
42
40
  # if hash, item will be array of the key & value
43
41
  data.each_with_index do |item, index|
44
42
  item_node = new_element(:item, container)
45
- item_node["key"] = item.is_a?(Array) ? item[0].to_s : index.to_s
43
+ item_node['key'] = item.is_a?(Array) ? item[0].to_s : index.to_s
46
44
 
47
45
  value = item.is_a?(Array) ? item[1] : item
48
46
 
49
- item_node << encode_data(value, item_node)
47
+ encoded_data = encode_data(value, item_node)
48
+ if encoded_data.is_a?(String)
49
+ item_node.content = encoded_data
50
+ else
51
+ item_node << encoded_data
52
+ end
50
53
  element << item_node
51
54
  end
52
55
 
@@ -58,16 +61,16 @@ module OpenSRS
58
61
  def self.decode_data(data)
59
62
  data.each do |element|
60
63
  case element.name
61
- when "dt_array"
64
+ when 'dt_array'
62
65
  return decode_dt_array_data(element)
63
- when "dt_assoc"
66
+ when 'dt_assoc'
64
67
  return decode_dt_assoc_data(element)
65
- when "text", "item", "dt_scalar"
68
+ when 'text', 'item', 'dt_scalar'
66
69
  next if element.content.strip.empty?
70
+
67
71
  return element.content.strip
68
72
  end
69
73
  end
70
74
  end
71
-
72
75
  end
73
76
  end
data/lib/opensrs.rb CHANGED
@@ -1,8 +1,9 @@
1
- require "opensrs/xml_processor"
2
- require "opensrs/xml_processor/libxml"
3
- require "opensrs/server"
4
- require "opensrs/response"
5
- require "opensrs/version"
1
+ require 'opensrs/xml_processor'
2
+ require 'opensrs/server'
3
+ require 'opensrs/response'
4
+ require 'opensrs/sanitizable_string'
5
+ require 'opensrs/version'
6
6
 
7
+ # OpenSRS
7
8
  module OpenSRS
8
9
  end
data/opensrs.gemspec CHANGED
@@ -1,31 +1,32 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "opensrs/version"
3
+ require 'opensrs/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
-
8
- spec.name = "opensrs"
6
+ spec.name = 'opensrs'
9
7
  spec.version = OpenSRS::VERSION
10
- spec.authors = [ "Joshua Delsman" ]
11
- spec.email = [ "j@srv.im" ]
12
- spec.summary = "OpenSRS API for Ruby"
13
- spec.description = "Provides support to utilize the OpenSRS API with Ruby."
14
- spec.homepage = "https://github.com/voxxit/opensrs"
15
- spec.license = "MIT"
8
+ spec.authors = ['Joshua Delsman']
9
+ spec.email = ['j@srv.im']
10
+ spec.summary = 'OpenSRS API for Ruby'
11
+ spec.description = 'Provides support to utilize the OpenSRS API with Ruby.'
12
+ spec.homepage = 'https://github.com/voxxit/opensrs'
13
+ spec.license = 'MIT'
14
+ spec.required_ruby_version = '>= 2.5'
16
15
 
17
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "exe"
17
+ spec.bindir = 'exe'
19
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
21
-
22
- spec.add_runtime_dependency "libxml-ruby", "~> 2"
23
-
24
- spec.add_development_dependency "bundler"
25
- spec.add_development_dependency "rake"
26
- spec.add_development_dependency "rspec"
27
- spec.add_development_dependency "shoulda"
28
- spec.add_development_dependency "nokogiri"
29
- spec.add_development_dependency "pry"
19
+ spec.require_paths = ['lib']
30
20
 
21
+ spec.add_development_dependency 'activesupport', '~> 4.2.2'
22
+ spec.add_development_dependency 'bundler'
23
+ spec.add_development_dependency 'code-scanning-rubocop', '~> 0.5'
24
+ spec.add_development_dependency 'libxml-ruby', '~> 3'
25
+ spec.add_development_dependency 'nokogiri', '~> 1.13.4'
26
+ spec.add_development_dependency 'pry'
27
+ spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'rspec'
29
+ spec.add_development_dependency 'rubocop', '~> 1'
30
+ spec.add_development_dependency 'rubocop-rspec'
31
+ spec.add_development_dependency 'shoulda'
31
32
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opensrs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Delsman
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-26 00:00:00.000000000 Z
11
+ date: 2022-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: libxml-ruby
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2'
20
- type: :runtime
19
+ version: 4.2.2
20
+ type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2'
26
+ version: 4.2.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +39,49 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: code-scanning-rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: libxml-ruby
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.13.4
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.13.4
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
43
85
  requirement: !ruby/object:Gem::Requirement
44
86
  requirements:
45
87
  - - ">="
@@ -53,7 +95,7 @@ dependencies:
53
95
  - !ruby/object:Gem::Version
54
96
  version: '0'
55
97
  - !ruby/object:Gem::Dependency
56
- name: rspec
98
+ name: rake
57
99
  requirement: !ruby/object:Gem::Requirement
58
100
  requirements:
59
101
  - - ">="
@@ -67,7 +109,7 @@ dependencies:
67
109
  - !ruby/object:Gem::Version
68
110
  version: '0'
69
111
  - !ruby/object:Gem::Dependency
70
- name: shoulda
112
+ name: rspec
71
113
  requirement: !ruby/object:Gem::Requirement
72
114
  requirements:
73
115
  - - ">="
@@ -81,7 +123,21 @@ dependencies:
81
123
  - !ruby/object:Gem::Version
82
124
  version: '0'
83
125
  - !ruby/object:Gem::Dependency
84
- name: nokogiri
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rspec
85
141
  requirement: !ruby/object:Gem::Requirement
86
142
  requirements:
87
143
  - - ">="
@@ -95,7 +151,7 @@ dependencies:
95
151
  - !ruby/object:Gem::Version
96
152
  version: '0'
97
153
  - !ruby/object:Gem::Dependency
98
- name: pry
154
+ name: shoulda
99
155
  requirement: !ruby/object:Gem::Requirement
100
156
  requirements:
101
157
  - - ">="
@@ -116,17 +172,22 @@ extensions: []
116
172
  extra_rdoc_files: []
117
173
  files:
118
174
  - ".document"
175
+ - ".github/workflows/rubocop-analysis.yml"
176
+ - ".github/workflows/ruby.yml"
119
177
  - ".gitignore"
120
178
  - ".rspec"
179
+ - ".rubocop.yml"
121
180
  - Gemfile
122
181
  - Gemfile.lock
123
182
  - LICENSE.txt
124
183
  - README.md
125
184
  - Rakefile
185
+ - SECURITY.md
126
186
  - bin/console
127
187
  - bin/setup
128
188
  - lib/opensrs.rb
129
189
  - lib/opensrs/response.rb
190
+ - lib/opensrs/sanitizable_string.rb
130
191
  - lib/opensrs/server.rb
131
192
  - lib/opensrs/version.rb
132
193
  - lib/opensrs/xml_processor.rb
@@ -137,7 +198,7 @@ homepage: https://github.com/voxxit/opensrs
137
198
  licenses:
138
199
  - MIT
139
200
  metadata: {}
140
- post_install_message:
201
+ post_install_message:
141
202
  rdoc_options: []
142
203
  require_paths:
143
204
  - lib
@@ -145,16 +206,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
206
  requirements:
146
207
  - - ">="
147
208
  - !ruby/object:Gem::Version
148
- version: '0'
209
+ version: '2.5'
149
210
  required_rubygems_version: !ruby/object:Gem::Requirement
150
211
  requirements:
151
212
  - - ">="
152
213
  - !ruby/object:Gem::Version
153
214
  version: '0'
154
215
  requirements: []
155
- rubyforge_project:
156
- rubygems_version: 2.4.5
157
- signing_key:
216
+ rubygems_version: 3.0.3.1
217
+ signing_key:
158
218
  specification_version: 4
159
219
  summary: OpenSRS API for Ruby
160
220
  test_files: []