chuckle 1.0.5 → 1.0.6

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: 370d11531835cb5e2c6a06e947f0e7270195c2d2
4
- data.tar.gz: 49457ddedf721927e9cdce13c96b6ab311356a60
3
+ metadata.gz: 5bec6990bc8d2c6749e8f14ecc609ed1fff3356d
4
+ data.tar.gz: c0ce0de38ab143ba264b935418056ea33f7e2d84
5
5
  SHA512:
6
- metadata.gz: 9ba2f917cde22f73987f312c98ddc619eade4e2d265cfe10dda2a1a184519d36eafe1b21d7c150cd850108330df2bc7786a7661661d80c905653efba7009c45d
7
- data.tar.gz: 40b4f8ad2c3d918fd5fbaee7ec31a494d394dd2c4118ce51e35f787f6dc7d8f822e152b719228ba0e95868dd191fc5cc26a61910ccaa29465914ce65c11fcf01
6
+ metadata.gz: 2866b58b2815ebe262f41537627db7828ff195f9c49f5a92b3b16efc939685aa7fc07b62380fc212ee7324e4186e10943cda36c7a0daf3cc7fbbcab0e14fdd9a
7
+ data.tar.gz: fc35467053e1203c3ee31e50e7b134e6a6110297bd919b04e519948332fac57f91ffe5f536b80aa1bb6abddbe81ec2015b248149b1b872b6b8455ce315582a7b
data/README.md CHANGED
@@ -48,8 +48,10 @@ Pass these `Chuckle::Client.new`:
48
48
  * **cacert** (nil) - cacert option to pass to curl
49
49
  * **capath** (nil) - capath option to pass to curl
50
50
  * **cookies** (false) - true to turn on cookie support
51
+ * **content_type** (application/x-www-form-urlencoded) - default content type for POST
51
52
  * **expires_in** (:never) - time in seconds after which cache files should expire, or `:never` to never expire
52
53
  * **insecure** (false) - true to allow insecure SSL connections
54
+ * **headers** (nil) - optional hash of headers to include for all requests. Content-Type is overwritten by the :content_type option. example: {"Referer" => "http://foo.com"}
53
55
  * **nretries** (2) - number of times to retry a failing request
54
56
  * **rate_limit** (1) - number of seconds between requests
55
57
  * **timeout** (30) - timeout per request. Note that if `nretries` is 2 and `timeout` is 30, a failing request could take 90 seconds to truly fail.
@@ -58,6 +60,8 @@ Pass these `Chuckle::Client.new`:
58
60
 
59
61
  ## Changelog
60
62
 
63
+ * 1.0.6 (May 15, 2015) - added support for setting arbitrary headers (@pattymac)
64
+ * 1.0.5 (Jan 30, 2015) - added support for setting content type (@pattymac)
61
65
  * 1.0.4 (Dec 6, 2014) - added support for --cacert, --capath and --insecure (@nkriege)
62
66
 
63
67
 
@@ -70,7 +70,15 @@ module Chuckle
70
70
 
71
71
  if request.body
72
72
  command += ["--data-binary", request.body]
73
- command += ["--header", "Content-Type: #{client.content_type}"]
73
+ end
74
+
75
+ # maintain backwards compatibility for content type
76
+ client.headers.each do |key,value|
77
+ if key == "Content-Type"
78
+ command += ["--header", "#{key}: #{value}"] if request.body
79
+ else
80
+ command += ["--header", "#{key}: #{value}"]
81
+ end
74
82
  end
75
83
 
76
84
  if client.cookies?
@@ -8,6 +8,7 @@ module Chuckle
8
8
  content_type: "application/x-www-form-urlencoded",
9
9
  cookies: false,
10
10
  expires_in: :never,
11
+ headers: nil,
11
12
  insecure: false,
12
13
  nretries: 2,
13
14
  rate_limit: 1,
@@ -61,6 +62,15 @@ module Chuckle
61
62
  options[:expires_in]
62
63
  end
63
64
 
65
+ # maintain backwards compatibility for content_type
66
+ def headers
67
+ @headers ||= begin
68
+ headers = options[:headers] || {}
69
+ headers["Content-Type"] = options[:content_type] if options[:content_type]
70
+ headers
71
+ end
72
+ end
73
+
64
74
  # allow insecure SSL connections?
65
75
  def insecure?
66
76
  options[:insecure]
@@ -1,4 +1,4 @@
1
1
  module Chuckle
2
2
  # Gem version
3
- VERSION = "1.0.5"
3
+ VERSION = "1.0.6"
4
4
  end
@@ -0,0 +1,74 @@
1
+ require "helper"
2
+
3
+ # these actually use the network, and get skipped unless ENV["NETWORK"].
4
+ class TestHeaders < Minitest::Test
5
+ include Helper
6
+
7
+ def test_default_headers
8
+ test_client = client(verbose: true)
9
+ assert_equal({"Content-Type"=>"application/x-www-form-urlencoded"}, test_client.headers)
10
+ end
11
+
12
+ def test_content_type
13
+ test_client = client(content_type: "text/json")
14
+ assert_equal({"Content-Type"=>"text/json"}, test_client.headers)
15
+ end
16
+
17
+ def test_arbitrary_headers
18
+ test_client = client(headers: {"Referer" => "http://foo.com"})
19
+ assert_equal test_client.headers["Referer"], "http://foo.com"
20
+ assert_equal test_client.headers["Content-Type"], "application/x-www-form-urlencoded"
21
+
22
+ end
23
+
24
+ def test_basic_get
25
+ test_client = client(verbose: true)
26
+ request = test_client.create_request("http://httpbin.org/get")
27
+ headers = command_headers(request)
28
+ assert_equal headers, []
29
+ end
30
+
31
+
32
+ def test_basic_post
33
+ request = client(verbose: true).create_request("http://httpbin.org/post", "foo")
34
+ headers = command_headers(request)
35
+ assert_equal headers, ["Content-Type: application/x-www-form-urlencoded"]
36
+ end
37
+
38
+ def test_get_headers
39
+ request = client(headers: {"Referer" => "http://foo.com"}).create_request("http://httpbin.org/get")
40
+ headers = command_headers(request)
41
+ assert_equal headers, ["Referer: http://foo.com"]
42
+ end
43
+
44
+ def test_post_headers
45
+ request = client(headers: {"Referer" => "http://foo.com"}).create_request("http://httpbin.org/post", "foo")
46
+ headers = command_headers(request)
47
+ assert_equal headers.sort, ["Content-Type: application/x-www-form-urlencoded", "Referer: http://foo.com"]
48
+ end
49
+
50
+ private
51
+
52
+ def command(request)
53
+ curler = CurlStub.new(request)
54
+ curler.test_command
55
+ end
56
+
57
+ def command_headers(request)
58
+ headers = []
59
+ test_command = command(request)
60
+ test_command.each_with_index do |item, i|
61
+ if item == "--header"
62
+ headers << test_command[i+1]
63
+ end
64
+ end
65
+ headers
66
+ end
67
+
68
+ class CurlStub < Chuckle::Curl
69
+ def test_command
70
+ command(@request)
71
+ end
72
+ end
73
+
74
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chuckle
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Doppelt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-30 00:00:00.000000000 Z
11
+ date: 2015-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trollop
@@ -123,6 +123,7 @@ files:
123
123
  - lib/chuckle/version.rb
124
124
  - test/helper.rb
125
125
  - test/test_cache.rb
126
+ - test/test_headers.rb
126
127
  - test/test_network.rb
127
128
  - test/test_requests.rb
128
129
  - test/url_file.txt
@@ -145,13 +146,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
146
  version: '0'
146
147
  requirements: []
147
148
  rubyforge_project: chuckle
148
- rubygems_version: 2.4.1
149
+ rubygems_version: 2.4.5
149
150
  signing_key:
150
151
  specification_version: 4
151
152
  summary: Chuckle - an http client that caches on disk.
152
153
  test_files:
153
154
  - test/helper.rb
154
155
  - test/test_cache.rb
156
+ - test/test_headers.rb
155
157
  - test/test_network.rb
156
158
  - test/test_requests.rb
157
159
  - test/url_file.txt