what3words 3.2.0 → 3.3.0

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
  SHA256:
3
- metadata.gz: 22479c5ad9842970d932052a565ee1b4bfd98c14a05d279297d6ba964d95a902
4
- data.tar.gz: bb498f8b643e541acfb83f1925ec9d30e67df710994561cad2629cc73e2b7230
3
+ metadata.gz: f248d7e71dde2539d4ff68361b8560a14d751f708f94dfa8764fbe7d049204c2
4
+ data.tar.gz: 60bc224aa58cfc974cb13398bfe350183f08c7e1b6975ed8358285a165bcf342
5
5
  SHA512:
6
- metadata.gz: 2ea16a0b86a7f4348b9c07661365f4bc58197b78f969e0b834686d4b117cd826978e76f20f802a1091d4b95c6ecf06979613d97b8ae9d81c85d6096d03521857
7
- data.tar.gz: 206f017da8d6ffa7d1b323479b948552cc830ee523e4781309f4a47b2eed25b271bfeeed824fc3600d663d7a53f8dbf4673f694baf25e130b492909b73199bb6
6
+ metadata.gz: 88a70bb9e8776928983187642b612cccde290e09605d23ad9e56d448cc75fa980f53fbb97bf9a69b9785ce293a35fe07a789842279110a17532210e7a3010ca6
7
+ data.tar.gz: 737b661041690c70ee27dc19a9f7e5096f6440577ca36a0a618d97459e183d411019d85a18608c5ca2f71af73a91bc7cc966a1fe88261b67522de246c02f79d2
data/README.md CHANGED
@@ -15,7 +15,7 @@ The library is available through [RubyGems](https://rubygems.org/gems/what3words
15
15
  You can simply add this line to your application's Gemfile:
16
16
 
17
17
  ```
18
- gem 'what3words', '~> 3.2'
18
+ gem 'what3words', '~> 3.3'
19
19
  ```
20
20
 
21
21
  And then execute:
@@ -438,6 +438,7 @@ Anyone and everyone is welcome to contribute.
438
438
 
439
439
  # Revision History
440
440
 
441
+ * `v3.3.0` 12/08/24 - Update error message to handle c2c calls and dependencies
441
442
  * `v3.2.0` 17/07/24 - Update regex patterns
442
443
  * `v3.1.0` 16/07/24 - Update tests and code to host the regex functions
443
444
  * `v3.0.0` 12/05/22 - Update endpoints and tests to API v3, added HTTP headers
@@ -9,7 +9,8 @@ module What3Words
9
9
  # What3Words v3 API wrapper
10
10
  class API
11
11
  class Error < RuntimeError; end
12
- class ResponseError < Error; end
12
+ # class ResponseError < Error; end
13
+ class ResponseError < StandardError; end
13
14
  class WordError < Error; end
14
15
 
15
16
  REGEX_3_WORD_ADDRESS = /^\/*(?:[^0-9`~!@#$%^&*()+\-_=\[\{\]}\\|'<>.,?\/\";:£§º©®\s]{1,}[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=\[\{\]}\\|'<>.,?\/\";:£§º©®\s]{1,}[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=\[\{\]}\\|'<>.,?\/\";:£§º©®\s]{1,}|[<.,>?\/\";:£§º©®\s]+[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=\[\{\]}\\|'<>.,?\/\";:£§º©®\s]+|[^0-9`~!@#$%^&*()+\-_=\[\{\]}\\|'<>.,?\/\";:£§º©®\s]+([\u0020\u00A0][^0-9`~!@#$%^&*()+\-_=\[\{\]}\\|'<>.,?\/\";:£§º©®\s]+){1,3}[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=\[\{\]}\\|'<>.,?\/\";:£§º©®\s]+([\u0020\u00A0][^0-9`~!@#$%^&*()+\-_=\[\{\]}\\|'<>.,?\/\";:£§º©®\s]+){1,3}[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=\[\{\]}\\|'<>.,?\/\";:£§º©®\s]+([\u0020\u00A0][^0-9`~!@#$%^&*()+\-_=\[\{\]}\\|'<>.,?\/\";:£§º©®\s]+){1,3})$/u.freeze
@@ -177,17 +178,34 @@ module What3Words
177
178
  response = RestClient.get(endpoint(endpoint_name), params: params, headers: headers)
178
179
  parsed_response = JSON.parse(response.body)
179
180
 
180
- raise ResponseError, "#{parsed_response['code']}: #{parsed_response['message']}" if parsed_response['error'].to_s.strip != ''
181
+ if parsed_response['error']
182
+ error_code = parsed_response['error']['code']
183
+ error_message = parsed_response['error']['message']
184
+ raise ResponseError, "#{error_code}: #{error_message}"
185
+ end
181
186
 
182
187
  deep_symbolize_keys(parsed_response)
183
188
  rescue RestClient::ExceptionWithResponse => e
184
189
  handle_rest_client_error(e)
190
+ rescue RestClient::Exception => e
191
+ raise ResponseError, "RestClient error: #{e.message}"
185
192
  end
186
193
 
187
194
  def handle_rest_client_error(error)
188
- parsed_response = JSON.parse(error.response)
189
- raise ResponseError, "#{parsed_response['code']}: #{parsed_response['message']}" if parsed_response['error']
190
- raise error
195
+ response = error.response
196
+ begin
197
+ parsed_response = JSON.parse(response.body)
198
+ rescue JSON::ParserError
199
+ raise ResponseError, "Invalid JSON response: #{response}"
200
+ end
201
+
202
+ if parsed_response['error']
203
+ error_code = parsed_response['error']['code']
204
+ error_message = parsed_response['error']['message']
205
+ raise ResponseError, "#{error_code}: #{error_message}"
206
+ else
207
+ raise ResponseError, "Unknown error: #{response}"
208
+ end
191
209
  end
192
210
 
193
211
  def get_words_string(words)
@@ -2,5 +2,5 @@
2
2
 
3
3
  # What3Words v3 API wrapper
4
4
  module What3Words
5
- VERSION = '3.2.0' unless defined?(::What3Words::VERSION)
5
+ VERSION = '3.3.0' unless defined?(::What3Words::VERSION)
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: what3words
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - what3words
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-17 00:00:00.000000000 Z
11
+ date: 2024-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -50,14 +50,14 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '11.1'
53
+ version: '12.3'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '11.1'
60
+ version: '12.3'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rspec
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -78,14 +78,14 @@ dependencies:
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: 0.48.1
81
+ version: 0.49.0
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: 0.48.1
88
+ version: 0.49.0
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: webmock
91
91
  requirement: !ruby/object:Gem::Requirement