decathlon-https 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/decathlon/https.rb +24 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75ced51ca25387dd63aab7ead0962a4a5e76021e6eedc86600c77fdb324cd35d
|
4
|
+
data.tar.gz: 1d634bc7f46c7c3451e4a8a6044f0c3aeb59845c43db66aed68f83ab5df96594
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de58b4bddd8439180b7020385379d7187e9873a931f09f5d5ff9eff21ab0973847cf0ab0b0cb0df43cea68a18698740da737bf9e7d3a6adba7ce8a8bb98576c7
|
7
|
+
data.tar.gz: a278eed529f22f7c95f30a373f0ca692158cb31e5dbfe4d5af60af42d63d8187dcf841c3f35b66cbd4005758543cbd77d845009c4b98b163aefceb729611732a
|
data/lib/decathlon/https.rb
CHANGED
@@ -9,17 +9,26 @@ module Decathlon
|
|
9
9
|
#
|
10
10
|
module HTTPS
|
11
11
|
|
12
|
-
VERSION = '0.1.
|
12
|
+
VERSION = '0.1.3'
|
13
13
|
|
14
14
|
def self.json_api_request(base_url: '', params: {}, verb: :get, headers: {}, return_http_status_code: false)
|
15
15
|
|
16
|
-
# Parse URI and build a new
|
16
|
+
# Parse URI and build a new HTTP(S) client
|
17
17
|
#
|
18
18
|
uri = URI.parse(base_url)
|
19
|
-
raise 'InsecureRequestURL' unless uri.scheme == 'https'
|
20
19
|
http = ::Net::HTTP.new(uri.host, uri.port)
|
21
|
-
|
22
|
-
|
20
|
+
|
21
|
+
# Sometimes, there might be reasons to call a non-https API
|
22
|
+
#
|
23
|
+
if uri.scheme == 'https'
|
24
|
+
http.use_ssl = true
|
25
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
26
|
+
|
27
|
+
# Prevent calls to non HTTP based schemes
|
28
|
+
#
|
29
|
+
elsif uri.scheme != 'http'
|
30
|
+
raise 'InsecureRequestURL'
|
31
|
+
end
|
23
32
|
|
24
33
|
# Don't include empty params
|
25
34
|
#
|
@@ -61,13 +70,20 @@ module Decathlon
|
|
61
70
|
#
|
62
71
|
response = http.request(request)
|
63
72
|
code = response.code.to_i
|
64
|
-
|
73
|
+
|
74
|
+
# Parse the response body based on response content header
|
75
|
+
#
|
76
|
+
if response['content-type'].match(/application\/json/)
|
77
|
+
JSON.parse(response.body.to_s, symbolize_names: true)
|
78
|
+
else
|
79
|
+
body = response.body.to_s
|
80
|
+
end
|
65
81
|
|
66
82
|
# Return parsed body content, and status code if requested
|
67
83
|
#
|
68
|
-
return { body:
|
84
|
+
return { body: body, code: code } if return_http_status_code == true
|
69
85
|
return {} if code == 204 || (body.empty? && code < 400)
|
70
|
-
return
|
86
|
+
return body
|
71
87
|
|
72
88
|
end
|
73
89
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decathlon-https
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jack Hayter
|
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
requirements: []
|
77
|
-
rubygems_version: 3.0.
|
77
|
+
rubygems_version: 3.0.6
|
78
78
|
signing_key:
|
79
79
|
specification_version: 4
|
80
80
|
summary: Simple abstraction library for making HTTPS JSON calls
|