httply 0.1.5 → 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
  SHA256:
3
- metadata.gz: 1a9a2b6ebd2873064c17ff349e01c280258cf3672aa3efa9fc4d9552d4d64852
4
- data.tar.gz: 304af45cd9cf5870fb14e1883d44fb8306cd01cb28b397f456a35d52736767f6
3
+ metadata.gz: 3b2dced2e5c3b300465476bf4949695bd38df27ab1bbef68af874e2ee9aeecf3
4
+ data.tar.gz: ceecd02689a32bcd6691f0bfd1a0da986076425cbc5bdc2b73c59c03dae481d9
5
5
  SHA512:
6
- metadata.gz: 2276fbddf8538d72109e60498cdac15f6e3ce0a595b1a37a126b19965d2e1b244965c8a86df0f2c78196c68a267dc3d14dbebfac1bf01e6e91935e19003a8bdd
7
- data.tar.gz: bdfad9a05aa7b634193faf62f3768e80414591719bf0a7a06f9e8449378ca4d378e9684146672ae9550f58ba022fc9294148ede57570989f917065029fc478a2
6
+ metadata.gz: 98ec1ac47349f35f2243c2cbe9cf6c103f73b7e34547a8b8984574291663959fb03c1d8328df865ae6622f46c8c8afdffb35ae7bd14d758fc7e7eb88112adc16
7
+ data.tar.gz: 157483ba68c30fe7475076e4de37ddeb62ce1b5c3f06d0d87669d5dc5310cb72833011bbb8faadf34b287edf055c227ca81e9c1c6cf8aa1354da064097f5e299
data/.gitignore CHANGED
@@ -9,6 +9,8 @@
9
9
 
10
10
  /spec/data/
11
11
 
12
+ .ruby-version
13
+
12
14
  /bin/.pry_history
13
15
  .pry_history
14
16
 
@@ -1,56 +1,56 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- httply (0.1.4)
5
- agents (>= 0.1.4)
6
- faraday (>= 0.15.4)
7
- faraday_middleware (>= 0.13.1)
4
+ httply (0.1.9)
5
+ agents (~> 0.1.4)
6
+ faraday (~> 1.0, >= 1.0.1)
7
+ faraday_middleware (~> 1.0)
8
+ multi_xml (~> 0.6.0)
8
9
 
9
10
  GEM
10
11
  remote: https://rubygems.org/
11
12
  specs:
12
13
  agents (0.1.4)
13
- coderay (1.1.2)
14
- diff-lcs (1.3)
15
- faraday (0.15.4)
14
+ coderay (1.1.3)
15
+ diff-lcs (1.4.4)
16
+ faraday (1.0.1)
16
17
  multipart-post (>= 1.2, < 3)
17
- faraday_middleware (0.13.1)
18
- faraday (>= 0.7.4, < 1.0)
19
- method_source (0.9.2)
18
+ faraday_middleware (1.0.0)
19
+ faraday (~> 1.0)
20
+ method_source (1.0.0)
20
21
  mini_portile2 (2.4.0)
21
22
  multi_xml (0.6.0)
22
23
  multipart-post (2.1.1)
23
- nokogiri (1.10.3)
24
+ nokogiri (1.10.10)
24
25
  mini_portile2 (~> 2.4.0)
25
- pry (0.12.2)
26
- coderay (~> 1.1.0)
27
- method_source (~> 0.9.0)
28
- rake (10.5.0)
29
- rspec (3.8.0)
30
- rspec-core (~> 3.8.0)
31
- rspec-expectations (~> 3.8.0)
32
- rspec-mocks (~> 3.8.0)
33
- rspec-core (3.8.0)
34
- rspec-support (~> 3.8.0)
35
- rspec-expectations (3.8.3)
26
+ pry (0.13.1)
27
+ coderay (~> 1.1)
28
+ method_source (~> 1.0)
29
+ rake (13.0.1)
30
+ rspec (3.9.0)
31
+ rspec-core (~> 3.9.0)
32
+ rspec-expectations (~> 3.9.0)
33
+ rspec-mocks (~> 3.9.0)
34
+ rspec-core (3.9.2)
35
+ rspec-support (~> 3.9.3)
36
+ rspec-expectations (3.9.2)
36
37
  diff-lcs (>= 1.2.0, < 2.0)
37
- rspec-support (~> 3.8.0)
38
- rspec-mocks (3.8.0)
38
+ rspec-support (~> 3.9.0)
39
+ rspec-mocks (3.9.1)
39
40
  diff-lcs (>= 1.2.0, < 2.0)
40
- rspec-support (~> 3.8.0)
41
- rspec-support (3.8.0)
41
+ rspec-support (~> 3.9.0)
42
+ rspec-support (3.9.3)
42
43
 
43
44
  PLATFORMS
44
45
  ruby
45
46
 
46
47
  DEPENDENCIES
47
- bundler (~> 1.17)
48
+ bundler (~> 2.1, >= 2.1.4)
48
49
  httply!
49
- multi_xml (~> 0.6.0)
50
- nokogiri (~> 1.10)
51
- pry (~> 0.12.2)
52
- rake (~> 10.0)
53
- rspec (~> 3.0)
50
+ nokogiri (~> 1.10, >= 1.10.10)
51
+ pry (~> 0.13.1)
52
+ rake (~> 13.0, >= 13.0.1)
53
+ rspec (~> 3.9)
54
54
 
55
55
  BUNDLED WITH
56
- 1.17.2
56
+ 2.1.4
@@ -23,16 +23,16 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ["lib"]
25
25
 
26
- spec.add_dependency "faraday", ">= 0.15.4"
27
- spec.add_dependency "faraday_middleware", ">= 0.13.1"
28
- spec.add_dependency "agents", ">= 0.1.4"
26
+ spec.add_dependency 'faraday', '~> 1.0', '>= 1.0.1'
27
+ spec.add_dependency 'faraday_middleware', '~> 1.0'
28
+ spec.add_dependency 'agents', '~> 0.1.4'
29
+ spec.add_dependency 'multi_xml', '~> 0.6.0'
29
30
 
30
- spec.add_development_dependency "bundler", "~> 1.17"
31
- spec.add_development_dependency "rake", "~> 10.0"
32
- spec.add_development_dependency "rspec", "~> 3.0"
31
+ spec.add_development_dependency 'bundler', '~> 2.1', '>= 2.1.4'
32
+ spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.1'
33
+ spec.add_development_dependency 'rspec', '~> 3.9'
33
34
 
34
- spec.add_development_dependency "pry", "~> 0.12.2"
35
+ spec.add_development_dependency 'pry', '~> 0.13.1'
35
36
 
36
- spec.add_development_dependency "nokogiri", "~> 1.10"
37
- spec.add_development_dependency "multi_xml", "~> 0.6.0"
37
+ spec.add_development_dependency 'nokogiri', '~> 1.10', '>= 1.10.10'
38
38
  end
@@ -33,8 +33,9 @@ module Httply
33
33
  end
34
34
 
35
35
  [:get, :head, :post, :put, :patch, :delete].each do |http_verb|
36
- define_method(http_verb) do |path, args|
37
- ::Httply::Client.new.send(http_verb, path, **args)
36
+ define_method(http_verb) do |path, *args|
37
+ args = args.any? ? args.flatten.first : {}
38
+ ::Httply::Client.new.send(http_verb, path, args)
38
39
  end
39
40
  end
40
41
 
@@ -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,21 @@ module Httply
64
64
  end
65
65
  end
66
66
 
67
+ response = force_format(response, format) unless format.to_s.empty?
68
+
69
+ return response
70
+ end
71
+
72
+ def force_format(response, format)
73
+ case format.to_sym
74
+ when :json
75
+ response.body = ::JSON.parse(response.body)
76
+ when :xml
77
+ response.body = ::MultiXml.parse(response.body)
78
+ when :html
79
+ response.body = ::Nokogiri::HTML(response.body, nil, "utf-8")
80
+ end
81
+
67
82
  return response
68
83
  end
69
84
 
@@ -87,14 +102,14 @@ module Httply
87
102
  builder.request :json if request_options.fetch(:json, false)
88
103
 
89
104
  builder.response :logger if self.configuration.verbose
90
- builder.response :xml, content_type: /\bxml$/
91
- builder.response :json, content_type: /\bjson$/
105
+ builder.response :xml, content_type: /\bxml$/
106
+ builder.response :json, content_type: /\bjson$/
92
107
  builder.use ::Httply::Middlewares::ParseHtml, content_type: /\btext\/html$/
93
108
 
94
109
  builder.use ::FaradayMiddleware::FollowRedirects, limit: redirects if redirects && redirects > 0
95
110
 
96
- if proxy
97
- builder.proxy = generate_faraday_proxy(proxy)
111
+ if proxy && !proxy.empty?
112
+ builder.proxy = proxy
98
113
  log("Will use proxy: #{builder.proxy.inspect}")
99
114
  end
100
115
 
@@ -19,6 +19,10 @@ module Httply
19
19
  elsif proxy_model_defined? && options.is_a?(::Proxy)
20
20
  proxy = proxy_from_object(options, proxy)
21
21
  end
22
+
23
+ if proxy && !proxy.empty?
24
+ proxy = proxy.has_key?(:uri) ? proxy : generate_faraday_proxy(proxy)
25
+ end
22
26
  end
23
27
 
24
28
  return proxy
@@ -37,25 +41,28 @@ module Httply
37
41
  end
38
42
 
39
43
  def proxy_from_hash(options, proxy)
40
- host = options.fetch(:host, nil)
41
- port = options.fetch(:port, nil)
42
-
43
- username = options.fetch(:username, nil)
44
- password = options.fetch(:password, nil)
45
-
46
- randomize = options.fetch(:randomize, true)
44
+ randomize = options.fetch(:randomize, false)
47
45
  type = options.fetch(:type, :all)
48
- protocol = options.fetch(:protocol, :all)
46
+ protocol = options.fetch(:protocol, :http)
49
47
 
50
48
  if randomize && proxy_model_defined?
51
49
  proxy_object = ::Proxy.get_random_proxy(protocol: protocol, proxy_type: type)
52
50
  proxy = proxy_from_object(proxy_object, proxy)
53
51
  else
54
- if host && port
55
- proxy[:host] = host
56
- proxy[:port] = port
52
+ uri = options.fetch(:uri, nil)
53
+
54
+ if uri.to_s.empty?
55
+ host = options.fetch(:host, nil)
56
+ port = options.fetch(:port, nil)
57
+
58
+ username = options.fetch(:username, nil)
59
+ password = options.fetch(:password, nil)
57
60
 
58
- proxy = set_credentials(username, password, proxy)
61
+ if !host.to_s.empty? && !port.to_s.empty?
62
+ proxy[:host] = host
63
+ proxy[:port] = port
64
+ proxy = set_credentials(username, password, proxy)
65
+ end
59
66
  end
60
67
  end
61
68
 
@@ -1,3 +1,3 @@
1
1
  module Httply
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,141 +1,165 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httply
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
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-06-24 00:00:00.000000000 Z
11
+ date: 2020-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
17
20
  - - ">="
18
21
  - !ruby/object:Gem::Version
19
- version: 0.15.4
22
+ version: 1.0.1
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
24
30
  - - ">="
25
31
  - !ruby/object:Gem::Version
26
- version: 0.15.4
32
+ version: 1.0.1
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: faraday_middleware
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - ">="
37
+ - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: 0.13.1
39
+ version: '1.0'
34
40
  type: :runtime
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
- - - ">="
44
+ - - "~>"
39
45
  - !ruby/object:Gem::Version
40
- version: 0.13.1
46
+ version: '1.0'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: agents
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
- - - ">="
51
+ - - "~>"
46
52
  - !ruby/object:Gem::Version
47
53
  version: 0.1.4
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
- - - ">="
58
+ - - "~>"
53
59
  - !ruby/object:Gem::Version
54
60
  version: 0.1.4
55
61
  - !ruby/object:Gem::Dependency
56
- name: bundler
62
+ name: multi_xml
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: '1.17'
62
- type: :development
67
+ version: 0.6.0
68
+ type: :runtime
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
- version: '1.17'
74
+ version: 0.6.0
69
75
  - !ruby/object:Gem::Dependency
70
- name: rake
76
+ name: bundler
71
77
  requirement: !ruby/object:Gem::Requirement
72
78
  requirements:
73
79
  - - "~>"
74
80
  - !ruby/object:Gem::Version
75
- version: '10.0'
81
+ version: '2.1'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 2.1.4
76
85
  type: :development
77
86
  prerelease: false
78
87
  version_requirements: !ruby/object:Gem::Requirement
79
88
  requirements:
80
89
  - - "~>"
81
90
  - !ruby/object:Gem::Version
82
- version: '10.0'
91
+ version: '2.1'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 2.1.4
83
95
  - !ruby/object:Gem::Dependency
84
- name: rspec
96
+ name: rake
85
97
  requirement: !ruby/object:Gem::Requirement
86
98
  requirements:
87
99
  - - "~>"
88
100
  - !ruby/object:Gem::Version
89
- version: '3.0'
101
+ version: '13.0'
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 13.0.1
90
105
  type: :development
91
106
  prerelease: false
92
107
  version_requirements: !ruby/object:Gem::Requirement
93
108
  requirements:
94
109
  - - "~>"
95
110
  - !ruby/object:Gem::Version
96
- version: '3.0'
111
+ version: '13.0'
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: 13.0.1
97
115
  - !ruby/object:Gem::Dependency
98
- name: pry
116
+ name: rspec
99
117
  requirement: !ruby/object:Gem::Requirement
100
118
  requirements:
101
119
  - - "~>"
102
120
  - !ruby/object:Gem::Version
103
- version: 0.12.2
121
+ version: '3.9'
104
122
  type: :development
105
123
  prerelease: false
106
124
  version_requirements: !ruby/object:Gem::Requirement
107
125
  requirements:
108
126
  - - "~>"
109
127
  - !ruby/object:Gem::Version
110
- version: 0.12.2
128
+ version: '3.9'
111
129
  - !ruby/object:Gem::Dependency
112
- name: nokogiri
130
+ name: pry
113
131
  requirement: !ruby/object:Gem::Requirement
114
132
  requirements:
115
133
  - - "~>"
116
134
  - !ruby/object:Gem::Version
117
- version: '1.10'
135
+ version: 0.13.1
118
136
  type: :development
119
137
  prerelease: false
120
138
  version_requirements: !ruby/object:Gem::Requirement
121
139
  requirements:
122
140
  - - "~>"
123
141
  - !ruby/object:Gem::Version
124
- version: '1.10'
142
+ version: 0.13.1
125
143
  - !ruby/object:Gem::Dependency
126
- name: multi_xml
144
+ name: nokogiri
127
145
  requirement: !ruby/object:Gem::Requirement
128
146
  requirements:
129
147
  - - "~>"
130
148
  - !ruby/object:Gem::Version
131
- version: 0.6.0
149
+ version: '1.10'
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 1.10.10
132
153
  type: :development
133
154
  prerelease: false
134
155
  version_requirements: !ruby/object:Gem::Requirement
135
156
  requirements:
136
157
  - - "~>"
137
158
  - !ruby/object:Gem::Version
138
- version: 0.6.0
159
+ version: '1.10'
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: 1.10.10
139
163
  description: Httply is a lightweight wrapper around Faraday to support automatic randomization
140
164
  of proxies and user agents, amongst other things.
141
165
  email:
@@ -146,7 +170,6 @@ extra_rdoc_files: []
146
170
  files:
147
171
  - ".gitignore"
148
172
  - ".rspec"
149
- - ".ruby-version"
150
173
  - ".travis.yml"
151
174
  - CODE_OF_CONDUCT.md
152
175
  - Gemfile
@@ -183,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
206
  - !ruby/object:Gem::Version
184
207
  version: '0'
185
208
  requirements: []
186
- rubygems_version: 3.0.3
209
+ rubygems_version: 3.1.2
187
210
  signing_key:
188
211
  specification_version: 4
189
212
  summary: Httply - lightweight Faraday wrapper
@@ -1 +0,0 @@
1
- 2.6.3