lucid_http 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -1
- data/lib/lucid_http/version.rb +1 -1
- data/lib/lucid_http.rb +46 -46
- 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: 835095e25fd401116f612af0cbea73e1b558b2a4
|
4
|
+
data.tar.gz: f4dccac3c87f199d7b9dc92bc7ab922f8a85f390
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db7baf83eb336ab40f82cff3292cad614c1b71158648006052b09f2542f5734de7f6eb1ad4308067129f46d76fec00a69cf159aabbe79515d594b15df648e6db
|
7
|
+
data.tar.gz: 68b9d93e0b513cbcdfcd619977e010f0d9c5c12d2695af730610a69dff5b0f68f05b70c62abed1137a5d4fed18684d0ccbc096a6cac48166364571d0040d80d5
|
data/README.md
CHANGED
@@ -6,7 +6,17 @@ TODO: Delete this and the text above, and describe your gem
|
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'lucid_http'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
10
20
|
|
11
21
|
$ gem install lucid_http
|
12
22
|
|
data/lib/lucid_http/version.rb
CHANGED
data/lib/lucid_http.rb
CHANGED
@@ -2,60 +2,60 @@ require "lucid_http/version"
|
|
2
2
|
require "http"
|
3
3
|
|
4
4
|
module LucidHttp
|
5
|
-
|
6
|
-
@res
|
7
|
-
end
|
5
|
+
end
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@body = nil
|
13
|
-
@path = nil
|
14
|
-
end
|
7
|
+
def response
|
8
|
+
@__lucid_http__res
|
9
|
+
end
|
15
10
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
if follow
|
20
|
-
@client = @client.follow
|
21
|
-
end
|
22
|
-
@path = @client.default_options.persistent + url
|
23
|
-
@res = @client.send(action.to_sym, url, form: form)
|
11
|
+
def _clean
|
12
|
+
instance_variables.grep(/@_lucid_http_/).each do |v|
|
13
|
+
remove_instance_variable(v)
|
24
14
|
end
|
15
|
+
end
|
25
16
|
|
26
|
-
|
27
|
-
|
17
|
+
def _setup(url, action: :get, follow: false, form: nil, **opts)
|
18
|
+
_clean
|
19
|
+
@__lucid_http__client = HTTP.persistent("http://localhost:9292")
|
20
|
+
if follow
|
21
|
+
@__lucid_http__client = @__lucid_http__client.follow
|
28
22
|
end
|
23
|
+
@__lucid_http__path = @__lucid_http__client.default_options.persistent + url
|
24
|
+
@__lucid_http__res = @__lucid_http__client.send(action.to_sym, url, form: form)
|
25
|
+
end
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
def body
|
28
|
+
@__lucid_http__body ||= response.body.to_s
|
29
|
+
end
|
33
30
|
|
34
|
-
|
35
|
-
|
36
|
-
|
31
|
+
def status
|
32
|
+
@__lucid_http__status = response.status
|
33
|
+
end
|
37
34
|
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
def content_type
|
36
|
+
response.content_type.mime_type
|
37
|
+
end
|
41
38
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
when 200
|
46
|
-
body
|
47
|
-
when 500
|
48
|
-
body.each_line.first
|
49
|
-
else
|
50
|
-
"ERROR: #{status.to_s}"
|
51
|
-
end
|
52
|
-
|
53
|
-
# puts new_body
|
54
|
-
new_body
|
55
|
-
end
|
39
|
+
def path
|
40
|
+
@__lucid_http__path
|
41
|
+
end
|
56
42
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
43
|
+
def GET(url, **opts)
|
44
|
+
_setup(url, **opts)
|
45
|
+
new_body = case status.to_i
|
46
|
+
when 200
|
47
|
+
body
|
48
|
+
when 500
|
49
|
+
body.each_line.first
|
50
|
+
else
|
51
|
+
"ERROR: #{status.to_s}"
|
52
|
+
end
|
53
|
+
|
54
|
+
# puts new_body
|
55
|
+
new_body
|
56
|
+
end
|
57
|
+
|
58
|
+
def POST(url, **opts)
|
59
|
+
_setup(url, action: :post, **opts)
|
60
|
+
body
|
61
61
|
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.2.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-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|