httply 0.1.7 → 0.1.8

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
  SHA256:
3
- metadata.gz: d8cfc1983c2022c04c4b4354d0c37d0bf1ddffc114a1d3b9be9c0e06d5e49d14
4
- data.tar.gz: 90f0a8b0bcf41924d7fc0307550fe4dcde510d5084eb3caca6957b56bbd490d1
3
+ metadata.gz: 897b5428ff155316657fd49bde52bcbd96872ad66d8608bd6536829c6e1378a5
4
+ data.tar.gz: dc73c1e39caef1c6b6015fe25d1848a3abf807e98d2f61a9a7a4fd4ac152e09d
5
5
  SHA512:
6
- metadata.gz: 1bf8075fe0134ab33af9e7b22e459c6fe2872311080a7ab51e5c9efad693a3dfa4ef44eb49e352f6543fb36b279d81dc984bc298e28a040a3c7a8dd3e0d80f37
7
- data.tar.gz: 02abcff2fe710ba2114738b08432a71897d68df871becaabfa3c91ad078e402819e4aa07621579611e67caabc1bcb0e902d073b5539fb3dc97342b39585912a8
6
+ metadata.gz: 1c95df2a649f13688efcd859e6d651efc6f0709a9f1a115491e2a7cf685a8cb5e2a5ad7e86fe9db863eaa5debcd11a533611f48ae887b2299693bfaa096166ab
7
+ data.tar.gz: e5d28e96750e945e6338a15d0617751e3bc260907a01c4b69eac5c5d9dba06158a59c90115a5ba59d5e036a469f228c7e0d32768069aa401a8e554d2ce86917b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- httply (0.1.6)
4
+ httply (0.1.7)
5
5
  agents (>= 0.1.4)
6
6
  faraday (>= 0.15.4)
7
7
  faraday_middleware (>= 0.13.1)
@@ -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 : nil
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
 
@@ -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, content_type: /\bxml$/
91
- builder.response :json, content_type: /\bjson$/
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
@@ -0,0 +1,11 @@
1
+ module Httply
2
+ class Response
3
+ attr_accessor :response, :body
4
+
5
+ def initialize(response)
6
+ self.response = response
7
+ self.body = response.body
8
+ end
9
+
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Httply
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
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.7
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-18 00:00:00.000000000 Z
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