httply 0.1.7 → 0.1.8
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/Gemfile.lock +1 -1
- data/lib/httply.rb +3 -2
- data/lib/httply/client.rb +31 -15
- data/lib/httply/response.rb +11 -0
- data/lib/httply/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 897b5428ff155316657fd49bde52bcbd96872ad66d8608bd6536829c6e1378a5
|
4
|
+
data.tar.gz: dc73c1e39caef1c6b6015fe25d1848a3abf807e98d2f61a9a7a4fd4ac152e09d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c95df2a649f13688efcd859e6d651efc6f0709a9f1a115491e2a7cf685a8cb5e2a5ad7e86fe9db863eaa5debcd11a533611f48ae887b2299693bfaa096166ab
|
7
|
+
data.tar.gz: e5d28e96750e945e6338a15d0617751e3bc260907a01c4b69eac5c5d9dba06158a59c90115a5ba59d5e036a469f228c7e0d32768069aa401a8e554d2ce86917b
|
data/Gemfile.lock
CHANGED
data/lib/httply.rb
CHANGED
@@ -11,6 +11,7 @@ require "httply/middlewares/html"
|
|
11
11
|
|
12
12
|
require "httply/utilities/uri"
|
13
13
|
|
14
|
+
require "httply/response"
|
14
15
|
require "httply/proxies"
|
15
16
|
require "httply/client"
|
16
17
|
|
@@ -34,8 +35,8 @@ module Httply
|
|
34
35
|
|
35
36
|
[:get, :head, :post, :put, :patch, :delete].each do |http_verb|
|
36
37
|
define_method(http_verb) do |path, *args|
|
37
|
-
args = args.any? ? args.flatten.first :
|
38
|
-
::Httply::Client.new.send(http_verb, path)
|
38
|
+
args = args.any? ? args.flatten.first : {}
|
39
|
+
::Httply::Client.new.send(http_verb, path, args)
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
data/lib/httply/client.rb
CHANGED
@@ -16,31 +16,31 @@ module Httply
|
|
16
16
|
self.connection ||= configure(host: host, headers: headers, options: options)
|
17
17
|
end
|
18
18
|
|
19
|
-
def get(path, parameters: {}, headers: {}, options: {})
|
20
|
-
request path, method: :get, parameters: parameters, headers: headers, options: options
|
19
|
+
def get(path, parameters: {}, headers: {}, options: {}, format: nil)
|
20
|
+
request path, method: :get, parameters: parameters, headers: headers, options: options, format: format
|
21
21
|
end
|
22
22
|
|
23
|
-
def head(path, parameters: {}, headers: {}, options: {})
|
24
|
-
request path, method: :head, parameters: parameters, headers: headers, options: options
|
23
|
+
def head(path, parameters: {}, headers: {}, options: {}, format: nil)
|
24
|
+
request path, method: :head, parameters: parameters, headers: headers, options: options, format: format
|
25
25
|
end
|
26
26
|
|
27
|
-
def post(path, parameters: {}, data: {}, headers: {}, options: {})
|
28
|
-
request path, method: :post, parameters: parameters, data: data, headers: headers, options: options
|
27
|
+
def post(path, parameters: {}, data: {}, headers: {}, options: {}, format: nil)
|
28
|
+
request path, method: :post, parameters: parameters, data: data, headers: headers, options: options, format: format
|
29
29
|
end
|
30
30
|
|
31
|
-
def put(path, parameters: {}, data: {}, headers: {}, options: {})
|
32
|
-
request path, method: :put, parameters: parameters, data: data, headers: headers, options: options
|
31
|
+
def put(path, parameters: {}, data: {}, headers: {}, options: {}, format: nil)
|
32
|
+
request path, method: :put, parameters: parameters, data: data, headers: headers, options: options, format: format
|
33
33
|
end
|
34
34
|
|
35
|
-
def patch(path, parameters: {}, data: {}, headers: {}, options: {})
|
36
|
-
request path, method: :patch, parameters: parameters, data: data, headers: headers, options: options
|
35
|
+
def patch(path, parameters: {}, data: {}, headers: {}, options: {}, format: nil)
|
36
|
+
request path, method: :patch, parameters: parameters, data: data, headers: headers, options: options, format: format
|
37
37
|
end
|
38
38
|
|
39
|
-
def delete(path, parameters: {}, data: {}, headers: {}, options: {})
|
40
|
-
request path, method: :delete, parameters: parameters, data: data, headers: headers, options: options
|
39
|
+
def delete(path, parameters: {}, data: {}, headers: {}, options: {}, format: nil)
|
40
|
+
request path, method: :delete, parameters: parameters, data: data, headers: headers, options: options, format: format
|
41
41
|
end
|
42
42
|
|
43
|
-
def request(path, method: :get, parameters: {}, data: {}, headers: {}, options: {})
|
43
|
+
def request(path, method: :get, parameters: {}, data: {}, headers: {}, options: {}, format: nil)
|
44
44
|
host = !self.host.to_s.empty? ? self.host : ::Httply::Utilities::Uri.parse_host(path)
|
45
45
|
path = ::Httply::Utilities::Uri.to_path(path)
|
46
46
|
connection = self.memoize ? setup(host: host, headers: headers, options: options) : configure(host: host, headers: headers, options: options)
|
@@ -64,6 +64,22 @@ module Httply
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
+
response = ::Httply::Response.new(response)
|
68
|
+
response = force_format(response, format) unless format.to_s.empty?
|
69
|
+
|
70
|
+
return response
|
71
|
+
end
|
72
|
+
|
73
|
+
def force_format(response, format)
|
74
|
+
case format.to_sym
|
75
|
+
when :json
|
76
|
+
response.body = ::JSON.parse(response.body)
|
77
|
+
when :xml
|
78
|
+
response.body = ::MultiXml.parse(response.body)
|
79
|
+
when :html
|
80
|
+
response.body = ::Nokogiri::HTML(response.body, nil, "utf-8")
|
81
|
+
end
|
82
|
+
|
67
83
|
return response
|
68
84
|
end
|
69
85
|
|
@@ -87,8 +103,8 @@ module Httply
|
|
87
103
|
builder.request :json if request_options.fetch(:json, false)
|
88
104
|
|
89
105
|
builder.response :logger if self.configuration.verbose
|
90
|
-
builder.response :xml,
|
91
|
-
builder.response :json,
|
106
|
+
builder.response :xml, content_type: /\bxml$/
|
107
|
+
builder.response :json, content_type: /\bjson$/
|
92
108
|
builder.use ::Httply::Middlewares::ParseHtml, content_type: /\btext\/html$/
|
93
109
|
|
94
110
|
builder.use ::FaradayMiddleware::FollowRedirects, limit: redirects if redirects && redirects > 0
|
data/lib/httply/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httply
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Johnsson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -162,6 +162,7 @@ files:
|
|
162
162
|
- lib/httply/configuration.rb
|
163
163
|
- lib/httply/middlewares/html.rb
|
164
164
|
- lib/httply/proxies.rb
|
165
|
+
- lib/httply/response.rb
|
165
166
|
- lib/httply/utilities/uri.rb
|
166
167
|
- lib/httply/version.rb
|
167
168
|
homepage: https://github.com/SebastianJ/httply
|