lucid_http 0.6.0 → 0.7.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: 135f19c630aa5461c1b46280775b9d914974b5ad
4
- data.tar.gz: 44ed6d30236e59082d5b4b46535da7e9a015bfdf
3
+ metadata.gz: b5d86973cae62ca4a685484c705ec3f58ce000d0
4
+ data.tar.gz: 563095d22df080dfdebe8e86225b4e12c49c9c05
5
5
  SHA512:
6
- metadata.gz: c331c1a90c2c58b650b779284ef65f44d4cad61d396f766dd9f125be283f5c9ff767fbbc32b6f072cc84b212315291300b62eea014094fad177a634afd596824
7
- data.tar.gz: 8d1144e98984773ef96803439433a463905cc5ca71e9103ed697b4c0c60719c8cd82295ecd7747245075bcb5d28ec00e27064947c0d49cf6eaaa7d338520759d
6
+ metadata.gz: 1e74b1e6371a0b1fc7a91815cd51f4d11a95cfc11f3002152f4bd1e968938476e2845d7bcecc7003d9b582167a91c024d818859c4f73d024fc507fb78b0b7914
7
+ data.tar.gz: 9ed3e9e3af04da7b38ea1f2f97aa872303678b2185799309f52c52753a94dfb5c3a1e45bb30961cbf9adf00037d9371b4c5c20a8a2b5a8c5f3e1888d07ae4cc1
@@ -1,3 +1,3 @@
1
1
  module LucidHttp
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
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 ||= response.body.to_s
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
- body
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.6.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-29 00:00:00.000000000 Z
11
+ date: 2016-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http