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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7780ec860038b7b01cec8f12707a7b77913e184d
4
- data.tar.gz: 6053e7298617e301274a0600a7dc9f161c2d8909
3
+ metadata.gz: 835095e25fd401116f612af0cbea73e1b558b2a4
4
+ data.tar.gz: f4dccac3c87f199d7b9dc92bc7ab922f8a85f390
5
5
  SHA512:
6
- metadata.gz: 1ccb094f1d185cc033a2936455d1ae139ba0a93cf61cba83241c4cf1c9c5eb85f5fcdeb336f2741445af452d16c266419451729601fc2a3a167e9ce23b910af7
7
- data.tar.gz: 51caa17e58e2949b74560fc9c7c7ae6897d964835e76629728414e2ccad09c52a47a7549359b3ab4b5d1611902b4f829be547f540c2b51b09bc95020c138c154
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
- `lucid_http` was created to be used in a standalone maner. So the recommended way to install it is:
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
 
@@ -1,3 +1,3 @@
1
1
  module LucidHttp
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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
- def response
6
- @res
7
- end
5
+ end
8
6
 
9
- def _clean
10
- @client = nil
11
- @res = nil
12
- @body = nil
13
- @path = nil
14
- end
7
+ def response
8
+ @__lucid_http__res
9
+ end
15
10
 
16
- def _setup(url, action: :get, follow: false, form: nil, **opts)
17
- _clean
18
- @client = HTTP.persistent("http://localhost:9292")
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
- def body
27
- @body ||= response.body.to_s
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
- def status
31
- @status = response.status
32
- end
27
+ def body
28
+ @__lucid_http__body ||= response.body.to_s
29
+ end
33
30
 
34
- def content_type
35
- response.content_type.mime_type
36
- end
31
+ def status
32
+ @__lucid_http__status = response.status
33
+ end
37
34
 
38
- def path
39
- @path
40
- end
35
+ def content_type
36
+ response.content_type.mime_type
37
+ end
41
38
 
42
- def GET(url, **opts)
43
- _setup(url, **opts)
44
- new_body = case status.to_i
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
- def POST(url, **opts)
58
- _setup(url, action: :post, **opts)
59
- body
60
- end
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.1.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-09 00:00:00.000000000 Z
11
+ date: 2016-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http