moonrope-client 1.0.4 → 1.0.5

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
2
  SHA256:
3
- metadata.gz: 715eb9deabcf5fa5b513b07b25bd56622ee65f875e91c90e0213c5c3367af6c3
4
- data.tar.gz: 2ffd7298b3c239781aab0466be505aee305e6606b393f989d6a7b2764e5653fd
3
+ metadata.gz: e354b83a2648af524ba82261be24f4eade87122b4bd042c2b13d81638105d505
4
+ data.tar.gz: 0a2fef71abb2c870938b97ce60e241fb39ef1b66990be7889a938afd0059c39d
5
5
  SHA512:
6
- metadata.gz: ffbaa74e05ae1d9089c95d1abc9bd764b07df63989628d8c65c9de517860f6305216be46be8cd1798aa176827793287173c09c734f85080eda98af51e431b6c5
7
- data.tar.gz: cfd048af82d5e94625b7011d9cb2e2f1e0017974110bf1aaa7c6a0be2f79d5b779878defc2a649fe0f37a7b5c6850d9f1dc825078790bb5c73c75916994720a4
6
+ metadata.gz: 77438b37bc152c59ecdb5a7e4325aa33688ee2f28383fc65c538d51c798e98a00c9b8013041d5a6536f89814c49945461d0fa9e101b1c1551e61703fae509474
7
+ data.tar.gz: 5e793e6c03c223f0bec41ea11c212edf1fe7b2d938fc392a4c3c80a9cfb293b87391353b4294f775819e8a04bc1b8dabf22924798c0d8c2cbf40fb6b4c3ea694
@@ -96,6 +96,7 @@ module MoonropeClient
96
96
  request.add_field 'User-Agent', self.user_agent
97
97
  headers.each { |k,v| request.add_field k, v }
98
98
  connection = Net::HTTP.new(self.host, self.port)
99
+ connection.open_timeout = @options[:connect_timeout] || 10
99
100
  if ssl
100
101
  connection.use_ssl = true
101
102
  connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
@@ -103,12 +104,21 @@ module MoonropeClient
103
104
  result = connection.request(request)
104
105
  case result.code.to_i
105
106
  when 200 then result.body
106
- when 400 then raise Error, "Bad request (400)"
107
- when 403 then raise Error, "Access denied (403)"
108
- when 404 then raise Error, "Page not found (404)"
109
- when 500 then raise Error, "Internal server error (500)"
110
- else raise Error, "Unexpected status code #{result.code.to_i}"
107
+ when 400
108
+ raise Error.new("Bad request (400)", body: result.body)
109
+ when 403
110
+ raise Error.new("Access denied (403)", body: result.body)
111
+ when 404
112
+ raise Error.new("Page not found (404)", body: result.body)
113
+ when 301..309
114
+ raise Error.new("Redirect (#{result.code})", body: result.body, location: result['Location'])
115
+ when 500
116
+ raise Error.new("Internal server error (500)", body: result.body)
117
+ else
118
+ raise Error.new("Error (#{result.code.to_i})", body: result.body)
111
119
  end
120
+ rescue Net::OpenTimeout
121
+ raise Error.new("Connection timeout to #{self.host}:#{self.port}")
112
122
  end
113
123
 
114
124
  end
@@ -1,4 +1,16 @@
1
1
  module MoonropeClient
2
2
  class Error < StandardError
3
+ def initialize(message, options = {})
4
+ @message = message
5
+ @options = options
6
+ end
7
+
8
+ def to_s
9
+ @message
10
+ end
11
+
12
+ def options
13
+ @options
14
+ end
3
15
  end
4
16
  end
@@ -1,3 +1,3 @@
1
1
  module MoonropeClient
2
- VERSION = '1.0.4'
2
+ VERSION = '1.0.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moonrope-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-30 00:00:00.000000000 Z
11
+ date: 2020-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -16,20 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.8.0
20
- - - "~>"
21
- - !ruby/object:Gem::Version
22
- version: '1.8'
19
+ version: '0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: 1.8.0
30
- - - "~>"
31
- - !ruby/object:Gem::Version
32
- version: '1.8'
26
+ version: '0'
33
27
  description: A full client library allows requests to made to Moonrope-enabled API
34
28
  endpoints.
35
29
  email:
@@ -70,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
64
  - !ruby/object:Gem::Version
71
65
  version: '0'
72
66
  requirements: []
73
- rubygems_version: 3.0.6
67
+ rubygems_version: 3.0.3
74
68
  signing_key:
75
69
  specification_version: 4
76
70
  summary: A client library for the the Moonrope API server.