patentscope 0.0.4 → 0.1.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
- SHA1:
3
- metadata.gz: 8c3ff619f0ad1778c36dbb2d04a945ad4c3e3cce
4
- data.tar.gz: 5736b0e818ed2823b0dd5e3d6f180902c9e25796
2
+ SHA256:
3
+ metadata.gz: 56467a752fa6f75a07f027d64ed5a72b74b9f2bdf82788e663912db497ed5d04
4
+ data.tar.gz: b1ded97d783ff2bcb84ce8bf57579e435ef9491b0000f094da5f53351cd2523e
5
5
  SHA512:
6
- metadata.gz: 77ca863b3c8b598318503938c7d4596b1836585d353adee688452cd4a9dce669c41cbb7adb799bc9608876323e8735989fe780d5a7bb9ef8a5e032924b44717d
7
- data.tar.gz: fd374c7216250fe7b8f37ac998188be5b9c32290351e70aff277fd31f7eed3861716720ca3c8c86529b07aae142110651471876d0da40f1aef140f0a50665000
6
+ metadata.gz: e1aab43b44f90067aa5fbfd1a69e9d8cb65388dbfaacacbe27472b87b38c68f6beed3c9765865fc7d4717bb0a4acf44c1c548c517f56e7f650c615ac3693bec0
7
+ data.tar.gz: 0f08bdc948ac997d4820d6d0a730b1fd8f96c058b093303d7aa41e45ab783fa3febfc64a0c3d4e78656d7a269039970e9ef4a0594e6c066ef9b4b6fc842fea34
@@ -0,0 +1,16 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ jobs:
8
+ test:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+ - uses: ruby/setup-ruby@v1
13
+ with:
14
+ ruby-version: "4.0.5"
15
+ bundler-cache: true
16
+ - run: bundle exec rake spec:core
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.4.2
1
+ 4.0.5
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- ruby '2.4.2'
3
+ ruby '4.0.5'
4
4
 
5
5
  # Specify your gem's dependencies in patentscope.gemspec
6
6
  gemspec
data/README.md CHANGED
@@ -182,9 +182,10 @@ The `wsdl` method returns a WSDL document for the PATENTSCOPE Web Service
182
182
 
183
183
  * NoCredentialsError - attempting to use the client when no credentials were entered
184
184
  * WrongCredentialsError - attempting to access the PATENTSCOPE Webservice with incorrect credentials
185
- * NoAppNumberError - no application numbere was entered, or unable to convert number
185
+ * NoAppNumberError - no application number was entered
186
186
  * NoDocIDError - no document id was entered
187
187
  * NoPageIDError - no page id was entered
188
+ * WrongNumberFormatError - unable to convert an application or publication number
188
189
  * BusinessError - PATENTSCOPE Webservice returned a "business error"
189
190
 
190
191
  ## Disclaimer
@@ -222,6 +223,21 @@ For support on the PATENTSCOPE Web Service, please see the resources in the sect
222
223
  * [Webinars](http://www.wipo.int/patentscope/en/webinar/)
223
224
  * [Forum](http://wipo-patentscope-forum.2944828.n2.nabble.com)
224
225
 
226
+ ## Testing
227
+
228
+ Run the credential-free core suite with:
229
+
230
+ $ bundle exec rake spec:core
231
+
232
+ The default `rake`, `rake test`, and `rspec spec` commands also run the core
233
+ suite. Live PATENTSCOPE Web Service examples require valid credentials and can
234
+ be run separately with:
235
+
236
+ $ bundle exec rake spec:more
237
+
238
+ If the PATENTSCOPE credential environment variables are not set, the live
239
+ examples are skipped.
240
+
225
241
  ## Contact
226
242
  Comments and bug reports are welcome.
227
243
 
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ namespace :spec do
12
12
 
13
13
  RSpec::Core::RakeTask.new(:core) do |task|
14
14
  task.pattern = "./spec/**/*_spec.rb"
15
- task.rspec_opts = '--tag core'
15
+ task.rspec_opts = '--tag core --tag ~more'
16
16
  end
17
17
 
18
18
  desc 'Run additional RSpec examples (e.g., integration specs)'
@@ -32,5 +32,5 @@ task console: :dotenv do
32
32
  IRB.start
33
33
  end
34
34
 
35
- task default: :spec
36
- task test: :spec
35
+ task default: 'spec:core'
36
+ task test: 'spec:core'
@@ -1,5 +1,6 @@
1
1
  require 'net/http'
2
- require 'nokogiri'
2
+ require 'open-uri'
3
+ require 'uri'
3
4
 
4
5
  module Patentscope
5
6
 
@@ -7,6 +8,8 @@ module Patentscope
7
8
  attr_reader :username, :password
8
9
 
9
10
  USER_AGENT_STRING = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5 Safari/536.30.1"
11
+ OPEN_TIMEOUT = 10
12
+ READ_TIMEOUT = 60
10
13
 
11
14
  def initialize(args = {})
12
15
  @username = args[:username]
@@ -14,7 +17,7 @@ module Patentscope
14
17
  end
15
18
 
16
19
  def get_url(url)
17
- open(url, "User-Agent" => USER_AGENT_STRING, http_basic_authentication: [username, password]).read
20
+ URI.open(url, "User-Agent" => USER_AGENT_STRING, http_basic_authentication: [username, password]).read
18
21
  end
19
22
 
20
23
  def post_url(url, content_type = 'text/html', body = '')
@@ -25,14 +28,31 @@ module Patentscope
25
28
  request["Content-Type"] = content_type
26
29
  request.body = body
27
30
 
28
- Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
31
+ Net::HTTP.start(uri.host, uri.port,
32
+ use_ssl: uri.scheme == 'https',
33
+ open_timeout: OPEN_TIMEOUT,
34
+ read_timeout: READ_TIMEOUT) do |http|
29
35
  response = http.request(request)
30
- if response.header["Content-Type"].include? "text/html"
31
- response.body
32
- elsif response.header["Content-Type"].include? "multipart/related"
33
- response.body.split("\r\n\r\n")[1].split("\r\n")[0]
36
+ raise WrongCredentialsError if response.is_a?(Net::HTTPUnauthorized)
37
+
38
+ body = response.body.to_s.force_encoding("ISO-8859-1").encode("UTF-8")
39
+ content_type = response.header["Content-Type"].to_s
40
+
41
+ if content_type.include?("multipart/related")
42
+ multipart_xml_body(body)
43
+ else
44
+ body
34
45
  end
35
46
  end
36
47
  end
48
+
49
+ private
50
+
51
+ def multipart_xml_body(body)
52
+ parts = body.split("\r\n\r\n", 2)
53
+ return body unless parts.length == 2
54
+
55
+ parts.last.split("\r\n").first.to_s
56
+ end
37
57
  end
38
58
  end
@@ -20,12 +20,20 @@ module Patentscope
20
20
  end
21
21
 
22
22
  def configured?
23
- (configuration && configuration.username && configuration.password)? true : false
23
+ !!(configuration &&
24
+ present?(configuration.username) &&
25
+ present?(configuration.password))
24
26
  end
25
27
 
26
28
  def reset_configuration
27
29
  self.configuration = nil
28
30
  end
31
+
32
+ private
33
+
34
+ def present?(value)
35
+ !value.to_s.strip.empty?
36
+ end
29
37
  end
30
38
 
31
39
  class Configuration
@@ -3,7 +3,7 @@ module Patentscope
3
3
  class PctAppNumber < String
4
4
 
5
5
  def initialize(number = "")
6
- raise NoNumberError,
6
+ raise NoAppNumberError,
7
7
  "Patent application number was not entered" if number.nil?
8
8
  super(number.strip)
9
9
  end
@@ -15,20 +15,19 @@ module Patentscope
15
15
  def validate
16
16
  raise WrongNumberFormatError,
17
17
  "PCT application number is not in correct format (PCT/CCYYYY/NNNNNN)" unless valid?
18
+ true
18
19
  end
19
20
 
20
21
  def to_ia_number
21
- self.upcase!
22
- self.gsub!('/', '')
23
- self.gsub!('PCT', '')
24
- self
22
+ validate
23
+ upcase.gsub('/', '').sub(/\APCT/, '')
25
24
  end
26
25
  end
27
26
 
28
27
  class PctPubNumber < String
29
28
 
30
29
  def initialize(number = "")
31
- raise NoNumberError,
30
+ raise NoAppNumberError,
32
31
  "Patent publication number was not entered" if number.nil?
33
32
  super(number.strip)
34
33
  end
@@ -40,6 +39,7 @@ module Patentscope
40
39
  def validate
41
40
  raise WrongNumberFormatError,
42
41
  "PCT publication number is not in correct format (WO/YYYY/NNNNNN)" unless valid?
42
+ true
43
43
  end
44
44
  end
45
45
  end
@@ -1,5 +1,5 @@
1
1
  module Patentscope
2
2
 
3
- VERSION = "0.0.4"
3
+ VERSION = "0.1.0"
4
4
 
5
5
  end
@@ -9,33 +9,33 @@ module Patentscope
9
9
  end
10
10
 
11
11
  def get_available_documents(args = {})
12
- ia_number = PctAppNumber.new(args[:ia_number]).to_ia_number
12
+ ia_number = normalized_ia_number(args[:ia_number])
13
13
  perform_operation(:getAvailableDocuments, { iaNumber: ia_number })
14
14
  end
15
15
 
16
16
  def get_document_content(args = {})
17
- doc_id = args[:doc_id]
17
+ doc_id = required_value(args[:doc_id], NoDocIDError, "Document id was not entered")
18
18
  perform_operation(:getDocumentContent, { docId: doc_id })
19
19
  end
20
20
 
21
21
  def get_document_ocr_content(args = {})
22
- doc_id = args[:doc_id]
22
+ doc_id = required_value(args[:doc_id], NoDocIDError, "Document id was not entered")
23
23
  perform_operation(:getDocumentOcrContent, { docId: doc_id })
24
24
  end
25
25
 
26
26
  def get_iasr(args = {})
27
- ia_number = PctAppNumber.new(args[:ia_number]).to_ia_number
27
+ ia_number = normalized_ia_number(args[:ia_number])
28
28
  perform_operation(:getIASR, { iaNumber: ia_number })
29
29
  end
30
30
 
31
31
  def get_document_table_of_contents(args = {})
32
- doc_id = args[:doc_id]
32
+ doc_id = required_value(args[:doc_id], NoDocIDError, "Document id was not entered")
33
33
  perform_operation(:getDocumentTableOfContents, { docId: doc_id })
34
34
  end
35
35
 
36
36
  def get_document_content_page(args = {})
37
- doc_id = args[:doc_id]
38
- page_id = args[:page_id]
37
+ doc_id = required_value(args[:doc_id], NoDocIDError, "Document id was not entered")
38
+ page_id = required_value(args[:page_id], NoPageIDError, "Page id was not entered")
39
39
  perform_operation(:getDocumentContentPage, { docId: doc_id, pageId: page_id })
40
40
  end
41
41
 
@@ -43,7 +43,7 @@ module Patentscope
43
43
 
44
44
  def perform_operation(operation, options_hash)
45
45
  soap_envelope = soapbuilder.build_envelope(operation, options_hash)
46
- response = send_soap_request(soap_envelope)
46
+ response = send_soap_request(soap_envelope).to_s
47
47
  if response.include?('Error') && response.include?('Unauthorized')
48
48
  raise WrongCredentialsError
49
49
  elsif response.include?('Business error during the execution of service')
@@ -61,6 +61,16 @@ module Patentscope
61
61
  client.get_url(PATENTSCOPE_WEBSERVICE_LOCATION + '?wsdl')
62
62
  end
63
63
 
64
+ def normalized_ia_number(number)
65
+ PctAppNumber.new(number).to_ia_number
66
+ end
67
+
68
+ def required_value(value, error_class, message)
69
+ value = value.to_s.strip
70
+ raise error_class, message if value.empty?
71
+ value
72
+ end
73
+
64
74
  def client
65
75
  raise NoCredentialsError unless Patentscope.configured?
66
76
  Client.new(username: Patentscope.configuration.username,
@@ -1,3 +1,5 @@
1
+ require 'nokogiri'
2
+
1
3
  module Patentscope
2
4
 
3
5
  class WebserviceSoapBuilder
@@ -1,3 +1,5 @@
1
+ require 'nokogiri'
2
+
1
3
  module Patentscope
2
4
 
3
5
  class WebserviceSoapStripper
data/lib/patentscope.rb CHANGED
@@ -12,6 +12,10 @@ module Patentscope
12
12
  class WrongCredentialsError < StandardError; end
13
13
  class BusinessError < StandardError; end
14
14
  class WrongNumberFormatError < StandardError; end
15
+ class NoAppNumberError < WrongNumberFormatError; end
16
+ class NoDocIDError < WrongNumberFormatError; end
17
+ class NoPageIDError < WrongNumberFormatError; end
18
+ NoNumberError = NoAppNumberError
15
19
 
16
20
  class << self
17
21
 
@@ -50,4 +54,3 @@ module Patentscope
50
54
  end
51
55
  end
52
56
  end
53
-
data/patentscope.gemspec CHANGED
@@ -13,6 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.summary = %q{Ruby interface with WIPO PATENTSCOPE Web Service}
14
14
  spec.description = %q{Ruby interface to the PATENTSCOPE Web Service provided by the World Intellectual Property Organisation. Requires a subscription to the Patentscope Web Service}
15
15
  spec.homepage = "http://www.cantab-ip.com"
16
+ spec.required_ruby_version = ">= 4.0.5"
16
17
 
17
18
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
19
  f.match(%r{^(test|spec|features)/})
@@ -21,12 +22,11 @@ Gem::Specification.new do |spec|
21
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
23
  spec.require_paths = ["lib"]
23
24
 
24
- spec.add_development_dependency 'dotenv', '~> 2.2'
25
- spec.add_development_dependency 'rake', '~> 12.2'
26
- spec.add_development_dependency 'rspec', '~> 3.7'
27
- spec.add_development_dependency 'vcr', '~> 3.0'
28
- spec.add_development_dependency 'webmock', '~> 3.1'
25
+ spec.add_development_dependency 'dotenv', '>= 3.0'
26
+ spec.add_development_dependency 'rake', '>= 13.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.13'
28
+ spec.add_development_dependency 'vcr', '~> 6.0'
29
+ spec.add_development_dependency 'webmock', '~> 3.0'
29
30
 
30
- spec.add_runtime_dependency 'nokogiri', '~> 1.8'
31
- spec.add_runtime_dependency 'unicode_titlecase', '~> 0'
31
+ spec.add_runtime_dependency 'nokogiri', '>= 1.15'
32
32
  end
metadata CHANGED
@@ -1,113 +1,98 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: patentscope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chong-Yee Khoo
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2017-11-08 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: dotenv
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - "~>"
16
+ - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '2.2'
18
+ version: '3.0'
20
19
  type: :development
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - "~>"
23
+ - - ">="
25
24
  - !ruby/object:Gem::Version
26
- version: '2.2'
25
+ version: '3.0'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: rake
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
- - - "~>"
30
+ - - ">="
32
31
  - !ruby/object:Gem::Version
33
- version: '12.2'
32
+ version: '13.0'
34
33
  type: :development
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
- - - "~>"
37
+ - - ">="
39
38
  - !ruby/object:Gem::Version
40
- version: '12.2'
39
+ version: '13.0'
41
40
  - !ruby/object:Gem::Dependency
42
41
  name: rspec
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
44
  - - "~>"
46
45
  - !ruby/object:Gem::Version
47
- version: '3.7'
46
+ version: '3.13'
48
47
  type: :development
49
48
  prerelease: false
50
49
  version_requirements: !ruby/object:Gem::Requirement
51
50
  requirements:
52
51
  - - "~>"
53
52
  - !ruby/object:Gem::Version
54
- version: '3.7'
53
+ version: '3.13'
55
54
  - !ruby/object:Gem::Dependency
56
55
  name: vcr
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - "~>"
60
59
  - !ruby/object:Gem::Version
61
- version: '3.0'
60
+ version: '6.0'
62
61
  type: :development
63
62
  prerelease: false
64
63
  version_requirements: !ruby/object:Gem::Requirement
65
64
  requirements:
66
65
  - - "~>"
67
66
  - !ruby/object:Gem::Version
68
- version: '3.0'
67
+ version: '6.0'
69
68
  - !ruby/object:Gem::Dependency
70
69
  name: webmock
71
70
  requirement: !ruby/object:Gem::Requirement
72
71
  requirements:
73
72
  - - "~>"
74
73
  - !ruby/object:Gem::Version
75
- version: '3.1'
74
+ version: '3.0'
76
75
  type: :development
77
76
  prerelease: false
78
77
  version_requirements: !ruby/object:Gem::Requirement
79
78
  requirements:
80
79
  - - "~>"
81
80
  - !ruby/object:Gem::Version
82
- version: '3.1'
81
+ version: '3.0'
83
82
  - !ruby/object:Gem::Dependency
84
83
  name: nokogiri
85
84
  requirement: !ruby/object:Gem::Requirement
86
85
  requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '1.8'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '1.8'
97
- - !ruby/object:Gem::Dependency
98
- name: unicode_titlecase
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
86
+ - - ">="
102
87
  - !ruby/object:Gem::Version
103
- version: '0'
88
+ version: '1.15'
104
89
  type: :runtime
105
90
  prerelease: false
106
91
  version_requirements: !ruby/object:Gem::Requirement
107
92
  requirements:
108
- - - "~>"
93
+ - - ">="
109
94
  - !ruby/object:Gem::Version
110
- version: '0'
95
+ version: '1.15'
111
96
  description: Ruby interface to the PATENTSCOPE Web Service provided by the World Intellectual
112
97
  Property Organisation. Requires a subscription to the Patentscope Web Service
113
98
  email:
@@ -116,10 +101,10 @@ executables: []
116
101
  extensions: []
117
102
  extra_rdoc_files: []
118
103
  files:
104
+ - ".github/workflows/ci.yml"
119
105
  - ".gitignore"
120
106
  - ".rspec"
121
107
  - ".ruby-version"
122
- - ".travis.yml"
123
108
  - Gemfile
124
109
  - License.txt
125
110
  - README.md
@@ -137,7 +122,6 @@ homepage: http://www.cantab-ip.com
137
122
  licenses:
138
123
  - MIT
139
124
  metadata: {}
140
- post_install_message:
141
125
  rdoc_options: []
142
126
  require_paths:
143
127
  - lib
@@ -145,16 +129,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
129
  requirements:
146
130
  - - ">="
147
131
  - !ruby/object:Gem::Version
148
- version: '0'
132
+ version: 4.0.5
149
133
  required_rubygems_version: !ruby/object:Gem::Requirement
150
134
  requirements:
151
135
  - - ">="
152
136
  - !ruby/object:Gem::Version
153
137
  version: '0'
154
138
  requirements: []
155
- rubyforge_project:
156
- rubygems_version: 2.6.13
157
- signing_key:
139
+ rubygems_version: 4.0.10
158
140
  specification_version: 4
159
141
  summary: Ruby interface with WIPO PATENTSCOPE Web Service
160
142
  test_files: []
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.0
6
- - 2.1.2