lucid_http 0.6.0 → 0.7.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 +4 -4
- data/lib/lucid_http/version.rb +1 -1
- data/lib/lucid_http.rb +21 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5d86973cae62ca4a685484c705ec3f58ce000d0
|
4
|
+
data.tar.gz: 563095d22df080dfdebe8e86225b4e12c49c9c05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e74b1e6371a0b1fc7a91815cd51f4d11a95cfc11f3002152f4bd1e968938476e2845d7bcecc7003d9b582167a91c024d818859c4f73d024fc507fb78b0b7914
|
7
|
+
data.tar.gz: 9ed3e9e3af04da7b38ea1f2f97aa872303678b2185799309f52c52753a94dfb5c3a1e45bb30961cbf9adf00037d9371b4c5c20a8a2b5a8c5f3e1888d07ae4cc1
|
data/lib/lucid_http/version.rb
CHANGED
data/lib/lucid_http.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "lucid_http/version"
|
2
2
|
require "http"
|
3
3
|
require "delegate"
|
4
|
+
require "json"
|
4
5
|
|
5
6
|
module LucidHttp
|
6
7
|
def self.target_url(url="http://localhost:9292")
|
@@ -28,7 +29,7 @@ def __lucid_http__clean
|
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
31
|
-
def __lucid_http__setup(url, action: :get, follow: false, form: nil, **opts)
|
32
|
+
def __lucid_http__setup(url, action: :get, follow: false, form: nil, json: false, **opts)
|
32
33
|
__lucid_http__clean
|
33
34
|
@__lucid_http__client = HTTP.persistent(LucidHttp.target_url)
|
34
35
|
if follow
|
@@ -36,10 +37,20 @@ def __lucid_http__setup(url, action: :get, follow: false, form: nil, **opts)
|
|
36
37
|
end
|
37
38
|
@__lucid_http__path = @__lucid_http__client.default_options.persistent + url
|
38
39
|
@__lucid_http__res = @__lucid_http__client.send(action.to_sym, url, form: form)
|
40
|
+
@__lucid_http__json = json
|
39
41
|
end
|
40
42
|
|
41
43
|
def body
|
42
|
-
@__lucid_http__body ||=
|
44
|
+
@__lucid_http__body ||= __lucid_http__get_body
|
45
|
+
end
|
46
|
+
|
47
|
+
def __lucid_http__get_body
|
48
|
+
original_body = response.body.to_s
|
49
|
+
if !json
|
50
|
+
original_body
|
51
|
+
else
|
52
|
+
JSON.parse(original_body)
|
53
|
+
end
|
43
54
|
end
|
44
55
|
|
45
56
|
def status
|
@@ -67,17 +78,21 @@ def GET(url, **opts)
|
|
67
78
|
new_body = case status.to_i
|
68
79
|
when 200
|
69
80
|
body
|
70
|
-
when 500
|
71
|
-
body.each_line.first
|
72
81
|
else
|
73
82
|
"STATUS: #{status}"
|
74
83
|
end
|
75
84
|
|
76
|
-
# puts new_body
|
77
85
|
new_body
|
78
86
|
end
|
79
87
|
|
80
88
|
def POST(url, **opts)
|
81
89
|
__lucid_http__setup(url, action: :post, **opts)
|
82
|
-
|
90
|
+
new_body = case status.to_i
|
91
|
+
when 200
|
92
|
+
body
|
93
|
+
else
|
94
|
+
"STATUS: #{status}"
|
95
|
+
end
|
96
|
+
|
97
|
+
new_body
|
83
98
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lucid_http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Federico Iachetti
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|