tweakphoeus 0.2.5 → 0.3.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: a0d00e51c1f23ccb8e4a7b63c95eeda5d0856351
4
- data.tar.gz: 94851c8ea6f3cc3cb05c8063a94aef03175c9104
3
+ metadata.gz: cc7932bfc55944db175b78337a59df4b85cc72a9
4
+ data.tar.gz: d0653d3ba555dc2350566feb180bab522454d412
5
5
  SHA512:
6
- metadata.gz: fc5ab5a5d781d861fcef932054258a73d956fe81b457e577a96ffef678c12742657ccc76611a75fe081da12114b3093cdd55c262e086359a6e090a88bb1bc047
7
- data.tar.gz: f31f18ebe3129cd53b0f9b6ab099da3b3d2c0a7aec0e91a335571729705ddd98f53dd1ca844ab794d5f13e0a26de47a9eb3748e90d51aab84a7583b44c5b1f7e
6
+ metadata.gz: 265cb93e198231d4da9d1b225b38cda425182d509d687873078e82fcdceb3b871e08218408b569fb0b532788237515771fa4b56935cde0346b1bdb11e851c359
7
+ data.tar.gz: 05c35d848ea2cc788e88ad03065fa197b8e929272e079639c1ebc450ff3de5b40a36e7b15b52640e9b0b072e26cc31354e3b7a8b58ed644bebc2689ad263473a
data/CHANGELOG.md CHANGED
@@ -5,3 +5,4 @@
5
5
  -- v0.2.3 - adding parameter params in order to handle in_url parameters
6
6
  -- v0.2.4 - adding parametes to post requests
7
7
  -- v0.2.5 - adding public method cookie_string
8
+ -- v0.3.0 - adding HTTP proxy management and fixing circular reference
data/README.md CHANGED
@@ -36,6 +36,9 @@ Tweakphoeus.get(url, headers: hash, body: hash)
36
36
 
37
37
  TODO: Write usage instructions here
38
38
 
39
+ ### Using proxies
40
+ To use HTTP proxies with optional basic authorization, use `set_proxy(url[, user: <user>, password: <pass>])`. Proxy can be disabled with `unset_proxy`.
41
+
39
42
  ## Development
40
43
 
41
44
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -1,3 +1,3 @@
1
1
  module Tweakphoeus
2
- VERSION = "0.2.5"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/tweakphoeus.rb CHANGED
@@ -15,6 +15,8 @@ module Tweakphoeus
15
15
  "Accept-Encoding" => "",
16
16
  "Connection" => "keep-alive"
17
17
  }
18
+ @proxy = nil
19
+ @proxyuserpwd = nil
18
20
  end
19
21
 
20
22
  def get(url, body: nil, params: nil, headers: nil, redirect: true)
@@ -76,13 +78,23 @@ module Tweakphoeus
76
78
  cookies.map{ |key, value| "#{key}=#{value}" }.join('; ')
77
79
  end
78
80
 
81
+ def set_proxy(url, auth = nil)
82
+ @proxyuserpwd = "#{auth[:user]}:#{auth[:password]}" if auth.is_a?(Hash)
83
+ @proxy = url
84
+ end
85
+
86
+ def unset_proxy
87
+ @proxyuserpwd = nil
88
+ @proxy = nil
89
+ end
90
+
79
91
  private
80
92
 
81
- def http_request(url, body: nil, params: nil, headers: nil, redirect: false, method: method)
93
+ def http_request(url, body: nil, params: nil, headers: nil, redirect: false, method: :get)
82
94
  request_headers = merge_default_headers(headers)
83
95
  request_headers["Cookie"] = cookie_string(url, headers)
84
96
  request_headers["Referer"] = get_referer
85
- response = Typhoeus.send(method, url, body: body, params: params, headers: request_headers)
97
+ response = Typhoeus.send(method, url, body: body, params: params, headers: request_headers, proxy: @proxy, proxyuserpwd: @proxyuserpwd)
86
98
  obtain_cookies(response)
87
99
  set_referer(url) if method != :post
88
100
  if redirect && has_redirect?(response)
@@ -166,6 +178,5 @@ module Tweakphoeus
166
178
  def set_referer url
167
179
  @referer.last.replace url
168
180
  end
169
-
170
181
  end
171
182
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tweakphoeus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Martin Garcia
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-13 00:00:00.000000000 Z
11
+ date: 2017-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  requirements: []
122
122
  rubyforge_project:
123
- rubygems_version: 2.6.8
123
+ rubygems_version: 2.6.11
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: Typhoeus on steroids.