maxcdn 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
- script: bundle exec ruby ./test/test.rb
2
+ script: bundle exec rake test
3
3
  rvm:
4
4
  - 1.9.2
5
5
  - 1.9.3
@@ -0,0 +1,20 @@
1
+ Running benchmarks as follows in order:
2
+
3
+ maxcdn.get('zones/pull.json')
4
+ maxcdn.get('reports/popularfiles.json')
5
+ maxcdn.post('zones/pull.json', { :name => 'NAM', :url => 'URL' })
6
+ maxcdn.put('account.json', { :name => 'NAME' })
7
+ maxcdn.delete('zones/pull.json/ZONEID')
8
+ maxcdn.purge('ZONEID')
9
+ maxcdn.purge('ZONEID', 'FILE')
10
+ maxcdn.purge('ZONEID', [ 'FILE1','FILE2' ])
11
+
12
+ user system total real
13
+ get : 0.050000 0.070000 0.120000 ( 1.004877)
14
+ get : 0.020000 0.000000 0.020000 ( 0.534179)
15
+ post : 0.020000 0.000000 0.020000 ( 18.060298)
16
+ put : 0.030000 0.010000 0.040000 ( 0.981422)
17
+ delete: 0.020000 0.000000 0.020000 ( 11.770821)
18
+ purge : 0.020000 0.000000 0.020000 ( 13.584882)
19
+ purge : 0.020000 0.000000 0.020000 ( 17.310386)
20
+ purge : 0.030000 0.010000 0.040000 ( 16.446759)
data/Gemfile CHANGED
@@ -5,7 +5,10 @@ gem "curb-fu"
5
5
  gemspec
6
6
 
7
7
  group :development, :test do
8
+ gem "rake"
9
+ gem "pry"
8
10
  gem "minitest"
9
11
  gem "minitest-reporters"
12
+ gem "webmock"
10
13
  end
11
14
 
data/README.md CHANGED
@@ -4,6 +4,8 @@ Do you like building cool stuff? Do APIs keep you up at night? We're looking fo
4
4
 
5
5
  # MaxCDN REST Web Services Ruby Client
6
6
 
7
+ [![Build Status](https://travis-ci.org/MaxCDN/ruby-maxcdn.png?branch=master)](https://travis-ci.org/MaxCDN/ruby-maxcdn)   [![Gem Version](https://badge.fury.io/rb/maxcdn.png)](http://badge.fury.io/rb/maxcdn)
8
+
7
9
  ## Installation
8
10
 
9
11
  ``` bash
@@ -24,6 +26,11 @@ require 'maxcdn'
24
26
 
25
27
  api = MaxCDN::Client.new("myalias", "consumer_key", "consumer_secret")
26
28
 
29
+ ####
30
+ # Turn on debugging for underlying Curl::Easy and CurbFu modules
31
+ #
32
+ # api.debug = true
33
+
27
34
  api.get("/account.json")
28
35
  ```
29
36
 
@@ -58,6 +65,14 @@ api.purge(zone_id, '/some_file')
58
65
  api.purge(zone_id, ['/some_file', '/another_file'])
59
66
  ```
60
67
 
68
+ #### Example: SSL Upload
69
+
70
+ ```
71
+ max = MaxCDN::Client.new(alias, key, secret)
72
+ max.post("zones/pull/12345/ssl.json", {
73
+ :ssl_crt => File.read("/path/to/server.crt").strip,
74
+ :ssl_key => File.read("/path/to/server.key").strip })
75
+ ```
61
76
 
62
77
  ## Development Quick Start
63
78
 
@@ -79,3 +94,17 @@ export SECRET=<your secret>
79
94
  bundle exec ruby ./test/integration.rb # requires host's IP be whitelisted
80
95
  ```
81
96
 
97
+ # Change Log
98
+
99
+ ##### 0.1.1
100
+
101
+ * Fixing POST, DELETE and PUT to send data via request body.
102
+ * Adding debugging for CurbFu and Curl::Easy.
103
+ * Fixing/enhancing unit tests.
104
+ * Removing `secure_connection` handling, as all connections should be secure.
105
+ * Fixing [414 Request-URI Too Large](https://github.com/netdna/netdnarws-ruby/issues/10) from old [netdnarws-ruby](https://github.com/netdna/netdnarws-ruby) client.
106
+
107
+
108
+ ##### 0.1.0
109
+
110
+ * Initial Release
data/Rakefile CHANGED
@@ -1,2 +1,21 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << "test"
7
+ t.test_files = FileList['test/*_test.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ Rake::TestTask.new(:integration) do |t|
12
+ t.libs << "test"
13
+ t.test_files = FileList['test/integration.rb']
14
+ t.verbose = true
15
+ end
16
+
17
+ desc "Run benchmarks"
18
+ task :benchmark do
19
+ require "./test/benchmark"
20
+ end
21
+
@@ -0,0 +1,47 @@
1
+ class Hash
2
+ RESERVED_CHARACTERS = /[^a-zA-Z0-9\-\.\_\~]/
3
+
4
+ def _escape(value)
5
+ URI::escape(value.to_s, RESERVED_CHARACTERS)
6
+ rescue ArgumentError
7
+ URI::escape(value.to_s.force_encoding(Encoding::UTF_8), RESERVED_CHARACTERS)
8
+ end
9
+
10
+ def to_params
11
+ params = ''
12
+ stack = []
13
+
14
+ each do |k, v|
15
+ if v.is_a?(Hash)
16
+ stack << [k,v]
17
+ elsif v.is_a?(Array)
18
+ stack << [k,Hash.from_array(v)]
19
+ else
20
+ params << "#{_escape(k)}=#{_escape(v)}&"
21
+ end
22
+ end
23
+
24
+ stack.each do |parent, hash|
25
+ parent = _escape(parent) if parent.is_a? String
26
+ hash.each do |k, v|
27
+ if v.is_a?(Hash)
28
+ stack << ["#{parent}[#{k}]", v]
29
+ else
30
+ params << "#{parent}[#{k}]=#{_escape(v)}&"
31
+ end
32
+ end
33
+ end
34
+
35
+ params.chop!
36
+ params
37
+ end
38
+
39
+ def self.from_array(array = [])
40
+ h = Hash.new
41
+ array.size.times do |t|
42
+ h[t] = array[t]
43
+ end
44
+ h
45
+ end
46
+ end
47
+
@@ -1,33 +1,19 @@
1
1
  require "signet/oauth_1/client"
2
2
  require "curb-fu"
3
3
  require "json"
4
+ require "./lib/ext/hash"
5
+ require "pp" # for debug
4
6
 
5
7
  module MaxCDN
6
- module Utils
7
- RESERVED_CHARACTERS = /[^a-zA-Z0-9\-\.\_\~]/
8
-
9
- def escape(value)
10
- URI::escape(value.to_s, MaxCDN::Utils::RESERVED_CHARACTERS)
11
- rescue ArgumentError
12
- URI::escape(value.to_s.force_encoding(Encoding::UTF_8), MaxCDN::Utils::RESERVED_CHARACTERS)
13
- end
14
-
15
- def encode_params params={}
16
- Hash[params.map { |k, v| [escape(k), escape(v)] }]
17
- end
18
- end
19
-
20
8
  class APIException < Exception
21
9
  end
22
10
 
23
11
  class Client
24
- include MaxCDN::Utils
25
-
26
- attr_accessor :client
27
- def initialize(company_alias, key, secret, server="rws.maxcdn.com", secure_connection=true)
12
+ attr_accessor :client, :debug
13
+ def initialize(company_alias, key, secret, server="rws.maxcdn.com", _debug=false)
14
+ @debug = _debug
28
15
  @company_alias = company_alias
29
16
  @server = server
30
- @secure_connection = secure_connection
31
17
  @request_signer = Signet::OAuth1::Client.new(
32
18
  :client_credential_key => key,
33
19
  :client_credential_secret => secret,
@@ -36,84 +22,75 @@ module MaxCDN
36
22
  end
37
23
 
38
24
  def _connection_type
39
- return "http" unless @secure_connection
40
25
  "https"
41
26
  end
42
27
 
43
- def _encode_params params={}
44
- encode_params(params).map { |k, v|
45
- "#{k}=#{v}"
46
- }.join "&"
47
- end
48
-
49
28
  def _get_url uri, params={}
50
-
51
29
  url = "#{_connection_type}://#{@server}/#{@company_alias}/#{uri.gsub(/^\//, "")}"
52
- if not params.empty?
53
- url += "?#{_encode_params(params)}"
30
+ if params and not params.empty?
31
+ url += "?#{params.to_params}"
54
32
  end
55
33
 
56
34
  url
57
35
  end
58
36
 
59
- def _response_as_json method, uri, options={}, *attributes
60
- if options.delete(:debug)
61
- puts "Making #{method.upcase} request to #{_get_url uri}"
62
- end
37
+ def _response_as_json method, uri, options={}, data={}
38
+ puts "Making #{method.upcase} request to #{_get_url uri}" if debug
63
39
 
64
- request_options = {
65
- :uri => _get_url(uri, options[:body] ? attributes[0] : {}),
40
+ req_opts = {
66
41
  :method => method
67
42
  }
68
43
 
69
- request_options[:body] = _encode_params(attributes[0]) if options[:body]
70
- request = @request_signer.generate_authenticated_request(request_options)
44
+ req_opts[:uri] = _get_url(uri, (options[:body] ? {} : data))
45
+ req_opts[:body] = data.to_params if options[:body]
46
+
47
+ request = @request_signer.generate_authenticated_request(req_opts)
71
48
  request.headers["User-Agent"] = "Ruby MaxCDN API Client"
72
49
 
73
50
  begin
74
- curb_options = {}
75
- curb_options[:url] = request_options[:uri]
76
- curb_options[:headers] = request.headers
77
-
78
- if not options[:body]
79
- response = CurbFu.send method, curb_options
80
- else
81
- response = CurbFu.send method, curb_options, request.body
51
+ curb_opts = {
52
+ :url => req_opts[:uri],
53
+ :headers => request.headers
54
+ }
55
+
56
+ CurbFu.debug = debug
57
+
58
+ response = CurbFu.send method, curb_opts, request.body do |curb|
59
+ curb.verbose = debug
60
+
61
+ # Because CurbFu overwrite the content-type header passed
62
+ # to it
63
+ curb.headers["Content-Type"] = "application/json" if request.body
82
64
  end
83
65
 
84
- return response if options[:debug_request]
66
+ pp response if debug
85
67
 
86
68
  response_json = JSON.load(response.body)
87
69
 
88
- return response_json if options[:debug_json]
70
+ pp response_json if debug
89
71
 
90
- if not (response.success? or response.redirect?)
72
+ unless response.success? or response.redirect?
91
73
  error_message = response_json["error"]["message"]
92
74
  raise MaxCDN::APIException.new("#{response.status}: #{error_message}")
93
75
  end
94
76
  rescue TypeError
95
- raise MaxCDN::APIException.new(
96
- "#{response.status}: No information supplied by the server"
97
- )
77
+ raise MaxCDN::APIException.new("#{response.status}: No information supplied by the server")
98
78
  end
99
79
 
100
80
  response_json
101
81
  end
102
82
 
103
- [ :get, :post, :put, :delete ].each do |meth|
83
+ [ :post, :get, :put, :delete ].each do |meth|
104
84
  define_method(meth) do |uri, data={}, options={}|
105
- options[:body] = (meth == :post || meth == :put)
85
+ options[:body] ||= true if meth != :get
106
86
  self._response_as_json meth.to_s, uri, options, data
107
87
  end
108
88
  end
109
89
 
110
90
  def purge zone_id, file_or_files=nil, options={}
111
91
  unless file_or_files.nil?
112
- return self.delete(
113
- "/zones/pull.json/#{zone_id}/cache",
114
- {"file" => file_or_files},
115
- options
116
- )
92
+ return self.delete("/zones/pull.json/#{zone_id}/cache",
93
+ { "files" => file_or_files }, options)
117
94
  end
118
95
 
119
96
  self.delete("/zones/pull.json/#{zone_id}/cache", {}, options)
@@ -1,3 +1,3 @@
1
1
  module MaxCDN
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
File without changes
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+ require "minitest/autorun"
3
+ require "minitest/reporters"
4
+
5
+ require "./lib/ext/hash"
6
+
7
+ class Client < Minitest::Test
8
+ def test_to_params_basic
9
+ assert_equal "foo=bar", { "foo" => "bar" }.to_params
10
+ assert_equal "foo=bar&bar=foo", { :foo => "bar", :bar => "foo" }.to_params
11
+ end
12
+
13
+ def test_to_params_escape
14
+ assert_equal "foo%20bar=bar%20boo", { "foo bar" => "bar boo" }.to_params
15
+ end
16
+
17
+ def test_to_params_array
18
+ assert_equal "foo[0]=bar&foo[1]=boo", { "foo" => [ "bar", "boo" ] }.to_params
19
+ assert_equal "foo[0]=bar&foo[1]=boo", { :foo => [ :bar, :boo ] }.to_params
20
+ end
21
+
22
+ def test_to_params_crazy
23
+ assert_equal "a=1&c=%40%24%5E%24%23%25%26%23%26&%3F%21=asdf&1=FDAS&b[0]=a&b[1]=b&b[2]=c", {
24
+ :a => 1,
25
+ :b => [ :a, :b, :c ],
26
+ :c => "@$^$#%&#&",
27
+ "?!" => "asdf",
28
+ 1 => "FDAS"
29
+ }.to_params
30
+ end
31
+
32
+ end
@@ -14,6 +14,8 @@ class Client < Minitest::Test
14
14
 
15
15
  def setup
16
16
  @max = MaxCDN::Client.new(ENV["ALIAS"], ENV["KEY"], ENV["SECRET"])
17
+ @max.debug = true if ENV['DEBUG']
18
+
17
19
  @time = Time.now.to_i.to_s
18
20
  end
19
21
 
@@ -37,7 +39,7 @@ class Client < Minitest::Test
37
39
  }
38
40
 
39
41
  zid = @max.post("zones/pull.json", zone)["data"]["pullzone"]["id"]
40
- assert zid, "post"
42
+ assert zid, "post id"
41
43
 
42
44
  assert_equal 200, @max.delete("zones/pull.json/#{zid}")["code"], "delete (warning: manually delete zone #{zid} at https://cp.maxcdn.com/zones/pull)."
43
45
  end
@@ -0,0 +1,121 @@
1
+ #!/usr/bin/env ruby
2
+ require "minitest/autorun"
3
+ require "minitest/reporters"
4
+
5
+ require "./lib/maxcdn"
6
+
7
+ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
8
+
9
+ require "webmock"
10
+ include WebMock::API
11
+
12
+ host = "https://rws.maxcdn.com/alias"
13
+
14
+ headers = {
15
+ 'Authorization' => /.+/,
16
+ 'Cache-Control' => /.+/,
17
+ 'Content-Type' => /application.+/,
18
+ 'Expect' => /.*/,
19
+ 'User-Agent' => "Ruby MaxCDN API Client"
20
+ }
21
+
22
+ stub_request(:post, host+"/zones/pull.json")
23
+ .with(:body => 'foo=bar&bar=foo', :headers => headers)
24
+ .to_return(:body => '{"foo": "bar"}')
25
+
26
+ stub_request(:post, host+"/zones/pull.json?foo=bar")
27
+ .with(:headers => headers)
28
+ .to_return(:body => '{"foo": "bar"}')
29
+
30
+ stub_request(:put, host+"/account.json")
31
+ .with(:body => "foo=bar", :headers => headers)
32
+ .to_return(:body => '{"foo":"bar"}')
33
+
34
+ stub_request(:delete, host+"/zones/pull.json/12345/cache")
35
+ .with(:body => "files=foo.txt", :headers => headers)
36
+ .to_return(:body => '{"foo":"bar"}')
37
+
38
+ stub_request(:delete, host+"/zones/pull.json/12345/cache")
39
+ .with(:body => "files[0]=foo.txt&files[1]=bar.txt", :headers => headers)
40
+ .to_return(:body => '{"foo":"bar"}')
41
+
42
+ # stubs below this don't send content-type header
43
+ headers.delete('Content-Type')
44
+
45
+ stub_request(:get, host+"/account.json")
46
+ .with(:headers => headers)
47
+ .to_return(:body => '{"foo":"bar"}')
48
+
49
+ stub_request(:delete, host+"/zones/pull.json/12345/cache")
50
+ .with(:headers => headers)
51
+ .to_return(:body => '{"foo":"bar"}')
52
+
53
+ class Client < Minitest::Test
54
+
55
+ def setup
56
+ @max = MaxCDN::Client.new("alias", "key", "secret")
57
+ @max.debug = true if ENV['DEBUG']
58
+ end
59
+
60
+ def test_initialize
61
+ assert_equal "alias", @max.instance_variable_get(:@company_alias)
62
+ end
63
+
64
+ def test__connection_type
65
+ assert_equal "https", @max._connection_type
66
+ end
67
+
68
+ def test__get_url
69
+ assert_equal "https://rws.maxcdn.com/alias/foo",
70
+ @max._get_url("/foo")
71
+ assert_equal "https://rws.maxcdn.com/alias/foo?foo=foo%20bar",
72
+ @max._get_url("/foo", { :foo => "foo bar" })
73
+ end
74
+
75
+ def test__response_as_json_standard
76
+ res = @max._response_as_json("get", "account.json")
77
+ assert_equal({ "foo" => "bar" }, res)
78
+
79
+ res = @max._response_as_json("post", "zones/pull.json?foo=bar")
80
+ assert_equal({ "foo" => "bar" }, res)
81
+ end
82
+
83
+ def test__response_as_json_body
84
+ res = @max._response_as_json("post", "zones/pull.json", { :body => true }, { "foo"=> "bar", "bar" => "foo" })
85
+ assert_equal({ "foo" => "bar" }, res)
86
+ end
87
+
88
+ def test_get
89
+ assert_equal({ "foo" => "bar" }, @max.get("account.json"))
90
+ end
91
+
92
+ def test_post
93
+ assert_equal({ "foo" => "bar" }, @max.post("zones/pull.json", {"foo" => "bar", "bar" => "foo"}))
94
+ assert_equal({ "foo" => "bar" }, @max.post("zones/pull.json?foo=bar"))
95
+ end
96
+
97
+ def test_put
98
+ assert_equal({ "foo" => "bar" }, @max.put("account.json", {"foo"=>"bar"}))
99
+ end
100
+
101
+ def test_delete_cache
102
+ assert_equal({ "foo" => "bar" }, @max.delete("zones/pull.json/12345/cache"))
103
+ end
104
+
105
+ def test_delete_cache_w_files
106
+ assert_equal({ "foo" => "bar" }, @max.delete("zones/pull.json/12345/cache", { :files => "foo.txt" }))
107
+ end
108
+
109
+ def test_purge
110
+ assert_equal({ "foo" => "bar" }, @max.purge(12345))
111
+ end
112
+
113
+ def test_purge_file
114
+ assert_equal({ "foo" => "bar" }, @max.purge(12345, "foo.txt"))
115
+ end
116
+
117
+ def test_purge_files
118
+ assert_equal({ "foo" => "bar" }, @max.purge(12345, [ "foo.txt", "bar.txt" ]))
119
+ end
120
+ end
121
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maxcdn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-10 00:00:00.000000000 Z
12
+ date: 2014-02-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: signet
@@ -51,6 +51,7 @@ extra_rdoc_files: []
51
51
  files:
52
52
  - .gitignore
53
53
  - .travis.yml
54
+ - BENCHMARKS.md
54
55
  - Gemfile
55
56
  - LICENSE
56
57
  - README.md
@@ -59,12 +60,14 @@ files:
59
60
  - examples/cache.rb
60
61
  - examples/report.rb
61
62
  - examples/simple.rb
63
+ - lib/ext/hash.rb
62
64
  - lib/maxcdn.rb
63
65
  - lib/maxcdn/version.rb
64
66
  - maxcdn.gemspec
65
67
  - test/benchmark.rb
68
+ - test/ext_hash_test.rb
66
69
  - test/integration.rb
67
- - test/test.rb
70
+ - test/maxcdn_test.rb
68
71
  homepage: http://www.maxcdn.com
69
72
  licenses:
70
73
  - MIT
@@ -78,12 +81,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
81
  - - ! '>='
79
82
  - !ruby/object:Gem::Version
80
83
  version: '0'
84
+ segments:
85
+ - 0
86
+ hash: -4596852110847613603
81
87
  required_rubygems_version: !ruby/object:Gem::Requirement
82
88
  none: false
83
89
  requirements:
84
90
  - - ! '>='
85
91
  - !ruby/object:Gem::Version
86
92
  version: '0'
93
+ segments:
94
+ - 0
95
+ hash: -4596852110847613603
87
96
  requirements: []
88
97
  rubyforge_project:
89
98
  rubygems_version: 1.8.23
@@ -91,4 +100,3 @@ signing_key:
91
100
  specification_version: 3
92
101
  summary: A Rest Client For MaxCDN Rest Web Services
93
102
  test_files: []
94
- has_rdoc:
@@ -1,130 +0,0 @@
1
- require "curb-fu"
2
-
3
- require "minitest/autorun"
4
- require "minitest/mock"
5
- require "minitest/reporters"
6
-
7
- #require "signet/oauth_1/client"
8
- require "./lib/maxcdn"
9
-
10
- Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
11
-
12
- class Client < Minitest::Test
13
-
14
- def new_response
15
- response = Minitest::Mock.new
16
- response.expect(:body, '{ "foo": "bar" }')
17
- response.expect(:success?, true)
18
- response
19
- end
20
-
21
- def setup
22
- @max = MaxCDN::Client.new("alias", "key", "secret")
23
- end
24
-
25
- def test_initialize
26
- assert_equal "alias", @max.instance_variable_get(:@company_alias)
27
- end
28
-
29
- def test__connection_type
30
- assert_equal "https", @max._connection_type
31
-
32
- m = MaxCDN::Client.new("alias", "key", "secret", "foo", false)
33
- assert_equal "http", m._connection_type
34
- end
35
-
36
- def test__encode_params
37
- assert_equal "foo=foo%20bar&bah=boo",
38
- @max._encode_params({ :foo => "foo bar", :bah => "boo" })
39
- end
40
-
41
- def test__get_url
42
- assert_equal "https://rws.maxcdn.com/alias/foo",
43
- @max._get_url("/foo")
44
- assert_equal "https://rws.maxcdn.com/alias/foo?foo=foo%20bar",
45
- @max._get_url("/foo", { :foo => "foo bar" })
46
- end
47
-
48
- def test__response_as_json_standard
49
- response = new_response
50
- CurbFu::Request.stub :get, response do
51
- res = @max._response_as_json("get", "http://example.com")
52
- assert res
53
- assert response.verify
54
- end
55
- end
56
-
57
- def test__response_as_json_standard
58
- response = new_response
59
- CurbFu::Request.stub :get, response do
60
- res = @max._response_as_json("get", "http://example.com",
61
- { :debug_request => true })
62
- assert res.body
63
- end
64
- end
65
-
66
- def test_get
67
- response = new_response
68
- CurbFu::Request.stub :get, response do
69
- assert_equal({ "foo" => "bar" }, @max.get("/account.json"))
70
- end
71
- assert response.verify
72
- end
73
-
74
- def test_post
75
- response = new_response
76
- CurbFu::Request.stub :post, response do
77
- assert_equal({ "foo" => "bar" }, @max.post("/zones/pull.json", {'name' => 'test_zone', 'url' => 'http://my-test-site.com'}))
78
- end
79
- assert response.verify
80
- end
81
-
82
- def test_put
83
- response = new_response
84
- CurbFu::Request.stub :put, response do
85
- assert_equal({ "foo" => "bar" }, @max.put("/zones/pull.json/1234", {'name' => 'i_didnt_like_test'}))
86
- end
87
- assert response.verify
88
- end
89
-
90
- def test_delete
91
- response = new_response
92
- CurbFu::Request.stub :delete, response do
93
- assert_equal({ "foo" => "bar" }, @max.delete("/zones/pull.json/1234"))
94
- end
95
- assert response.verify
96
- end
97
-
98
- def test_delete_file
99
- response = new_response
100
- CurbFu::Request.stub :delete, response do
101
- assert_equal({ "foo" => "bar" }, @max.delete("/zones/pull.json/1234/cache", {"file" => "/robots.txt"}))
102
- end
103
- assert response.verify
104
- end
105
-
106
- def test_purge
107
- response = new_response
108
- CurbFu::Request.stub :delete, response do
109
- assert_equal({ "foo" => "bar" }, @max.purge(12345))
110
- end
111
- assert response.verify
112
- end
113
-
114
- def test_purge_file
115
- response = new_response
116
- CurbFu::Request.stub :delete, response do
117
- assert_equal({ "foo" => "bar" }, @max.purge(12345, "/foo.txt"))
118
- end
119
- assert response.verify
120
- end
121
-
122
- def test_purge_files
123
- response = new_response
124
- CurbFu::Request.stub :delete, response do
125
- assert_equal({ "foo" => "bar" }, @max.purge(12345, [ "/foo.txt", "/bar.txt" ]))
126
- end
127
- assert response.verify
128
- end
129
- end
130
-