lucid_http 0.3.0 → 0.4.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: be0e793b7ce8495a0e165b229f5f4246b4ff48a2
4
- data.tar.gz: c261f9dc1d2d20897efaadfd02f9ebc084267f2b
3
+ metadata.gz: 5e2386e3100f49d2886427f819681bd053554a26
4
+ data.tar.gz: 3b59805eb3c441d48987cf84de7b41f4de136217
5
5
  SHA512:
6
- metadata.gz: 2c8abae5e0e936d1bfc7f32af89d5217487075bd66d64c90f2b875a8da446b328c0dd5c15656dc10886f6d1012a60953fb6b87e352433c53666414c6471a6826
7
- data.tar.gz: 6af8a873924f40290be8ee19bc8c0d5184847482940dc6ceaf6f05ca73137f240d5285964d7d02922f10e0ae77c53096f748fb31aaba9e325186f39791e5a4d0
6
+ metadata.gz: 79d21ac7923d93c5a8bc57dc8882112c87b5a02fdc937d40bae3682bedf138e6842b17f5ab2fb1aa01dbb51175b8d7d2995146996ebc14717ad88d236f3eb3ef
7
+ data.tar.gz: 06dc752f2a8fba0f0cb091c381b051fe142b031d1183551bd94cf463c4fbb0b963eaf29f08e4aa70155c3270d35f5b7ff6543d9a9b7130e6e231bf0abf91f82e
@@ -1,3 +1,3 @@
1
1
  module LucidHttp
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/lucid_http.rb CHANGED
@@ -1,22 +1,36 @@
1
1
  require "lucid_http/version"
2
2
  require "http"
3
+ require "delegate"
3
4
 
4
5
  module LucidHttp
6
+ def self.target_url(url="http://localhost:9292")
7
+ @target_url ||= url
8
+ end
9
+
10
+ def self.target_url=(url="http://localhost:9292")
11
+ @target_url = url
12
+ end
13
+
14
+ class PrettyStatus < SimpleDelegator
15
+ def inspect
16
+ to_s
17
+ end
18
+ end
5
19
  end
6
20
 
7
21
  def response
8
22
  @__lucid_http__res
9
23
  end
10
24
 
11
- def _clean
25
+ def __lucid_http__clean
12
26
  instance_variables.grep(/@__lucid_http__/).each do |v|
13
27
  remove_instance_variable(v.to_sym)
14
28
  end
15
29
  end
16
30
 
17
- def _setup(url, action: :get, follow: false, form: nil, **opts)
18
- _clean
19
- @__lucid_http__client = HTTP.persistent("http://localhost:9292")
31
+ def __lucid_http__setup(url, action: :get, follow: false, form: nil, **opts)
32
+ __lucid_http__clean
33
+ @__lucid_http__client = HTTP.persistent(LucidHttp.target_url)
20
34
  if follow
21
35
  @__lucid_http__client = @__lucid_http__client.follow
22
36
  end
@@ -29,7 +43,7 @@ def body
29
43
  end
30
44
 
31
45
  def status
32
- @__lucid_http__status = response.status
46
+ @__lucid_http__status = LucidHttp::PrettyStatus.new(response.status)
33
47
  end
34
48
 
35
49
  def content_type
@@ -41,14 +55,14 @@ def path
41
55
  end
42
56
 
43
57
  def GET(url, **opts)
44
- _setup(url, **opts)
58
+ __lucid_http__setup(url, **opts)
45
59
  new_body = case status.to_i
46
60
  when 200
47
61
  body
48
62
  when 500
49
63
  body.each_line.first
50
64
  else
51
- "ERROR: #{status.to_s}"
65
+ "STATUS: #{status}"
52
66
  end
53
67
 
54
68
  # puts new_body
@@ -56,6 +70,6 @@ def GET(url, **opts)
56
70
  end
57
71
 
58
72
  def POST(url, **opts)
59
- _setup(url, action: :post, **opts)
73
+ __lucid_http__setup(url, action: :post, **opts)
60
74
  body
61
75
  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.3.0
4
+ version: 0.4.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-15 00:00:00.000000000 Z
11
+ date: 2016-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http