maxcdn 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -17,3 +17,4 @@ pkg
17
17
  *.gem
18
18
  *.lock
19
19
  .DS_Store
20
+ npm-debug.log
@@ -10,11 +10,11 @@ Running benchmarks as follows in order:
10
10
  maxcdn.purge('ZONEID', [ 'FILE1','FILE2' ])
11
11
 
12
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)
13
+ get : 0.050000 0.070000 0.120000 ( 1.026412)
14
+ get : 0.010000 0.000000 0.010000 ( 0.636914)
15
+ post : 0.020000 0.010000 0.030000 ( 11.083888)
16
+ put : 0.010000 0.000000 0.010000 ( 1.240014)
17
+ delete: 0.020000 0.000000 0.020000 ( 6.846295)
18
+ purge : 0.010000 0.010000 0.020000 ( 11.578944)
19
+ purge : 0.020000 0.000000 0.020000 ( 0.956149)
20
+ purge : 0.030000 0.000000 0.030000 ( 1.870104)
data/README.md CHANGED
@@ -12,6 +12,8 @@ Do you like building cool stuff? Do APIs keep you up at night? We're looking fo
12
12
  gem install maxcdn
13
13
  ```
14
14
 
15
+ > Requires Ruby 1.9.2+ (see: [Travis](https://travis-ci.org/MaxCDN/ruby-maxcdn) for passing Ruby versions.)
16
+
15
17
  #### With Bundler
16
18
 
17
19
  ```
@@ -96,6 +98,10 @@ bundle exec ruby ./test/integration.rb # requires host's IP be whitelisted
96
98
 
97
99
  # Change Log
98
100
 
101
+ ##### 0.1.4
102
+
103
+ * Fixing bug where purging files purges entire zone.
104
+
99
105
  ##### 0.1.3
100
106
 
101
107
  * Requested changes for debugging and development support. (See issue #2).
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.4
@@ -99,20 +99,40 @@ module MaxCDN
99
99
  response_json
100
100
  end
101
101
 
102
- [ :post, :get, :put, :delete ].each do |method|
102
+ [ :post, :put ].each do |method|
103
103
  define_method(method) do |uri, data={}, options={}|
104
- options[:body] ||= true if method != :get
104
+ options[:body] ||= true
105
+ self._response_as_json method.to_s, uri, options, data
106
+ end
107
+ end
108
+
109
+ [ :get, :delete ].each do |method|
110
+ define_method(method) do |uri, data={}, options={}|
111
+ options[:body] = false
105
112
  self._response_as_json method.to_s, uri, options, data
106
113
  end
107
114
  end
108
115
 
109
116
  def purge zone_id, file_or_files=nil, options={}
110
- unless file_or_files.nil?
111
- return self.delete("/zones/pull.json/#{zone_id}/cache",
112
- { "files" => file_or_files }, options)
117
+ if file_or_files.nil?
118
+ return self.delete("/zones/pull.json/#{zone_id}/cache", {}, options)
119
+ end
120
+
121
+ if file_or_files.is_a?(String)
122
+ return self.delete("/zones/pull.json/#{zone_id}/cache", { "files" => file_or_files }, options)
123
+ end
124
+
125
+ if file_or_files.is_a?(Array)
126
+ return file_or_files.map do |file|
127
+ self.delete("/zones/pull.json/#{zone_id}/cache", { "files" => file }, options)
128
+ end
129
+ end
130
+
131
+ if file_or_files.is_a?(Hash) and (file_or_files.has_key(:files) or file_or_files.has_key("files"))
132
+ return self.delete("/zones/pull.json/#{zone_id}/cache", { "files" => file_or_files }, options)
113
133
  end
114
134
 
115
- self.delete("/zones/pull.json/#{zone_id}/cache", {}, options)
135
+ raise MaxCDN::APIException.new("Invalid file_or_files argument for delete method.")
116
136
  end
117
137
  end
118
138
  end
@@ -1,3 +1,3 @@
1
1
  module MaxCDN
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -56,7 +56,8 @@ class Client < Minitest::Test
56
56
  popularfiles = @max.get("reports/popularfiles.json")["data"]["popularfiles"]
57
57
  assert_equal 200, @max.purge(zone, popularfiles[0]["uri"])["code"], "purge file"
58
58
 
59
- assert_equal 200, @max.purge(zone, [ popularfiles[0]["uri"], popularfiles[1]["uri"]])["code"], "purge files"
59
+ files = [popularfiles[0]["uri"], popularfiles[1]["uri"]]
60
+ assert_equal [{"code"=>200},{"code"=>200}], @max.purge(zone, files), "purge files"
60
61
  end
61
62
  end
62
63
 
@@ -28,21 +28,21 @@ stub_request(:put, host+"/account.json")
28
28
  .with(:body => "foo=bar", :headers => expected_headers)
29
29
  .to_return(:body => '{"foo":"bar"}')
30
30
 
31
- stub_request(:delete, host+"/zones/pull.json/12345/cache")
32
- .with(:body => "files=foo.txt", :headers => expected_headers)
31
+ # requests without :body
32
+ expected_headers['Content-Type'] = "application/x-www-form-urlencoded"
33
+ stub_request(:get, host+"/account.json")
34
+ .with(:headers => expected_headers)
33
35
  .to_return(:body => '{"foo":"bar"}')
34
36
 
35
- stub_request(:delete, host+"/zones/pull.json/12345/cache")
36
- .with(:body => "files[0]=foo.txt&files[1]=bar.txt", :headers => expected_headers)
37
+ stub_request(:delete, host+"/zones/pull.json/12345/cache?files=foo.txt")
38
+ .with(:headers => expected_headers)
37
39
  .to_return(:body => '{"foo":"bar"}')
38
40
 
39
- stub_request(:delete, host+"/zones/pull.json/12345/cache")
41
+ stub_request(:delete, host+"/zones/pull.json/12345/cache?files=bar.txt")
40
42
  .with(:headers => expected_headers)
41
43
  .to_return(:body => '{"foo":"bar"}')
42
44
 
43
- # requests without :body
44
- expected_headers['Content-Type'] = "application/x-www-form-urlencoded"
45
- stub_request(:get, host+"/account.json")
45
+ stub_request(:delete, host+"/zones/pull.json/12345/cache")
46
46
  .with(:headers => expected_headers)
47
47
  .to_return(:body => '{"foo":"bar"}')
48
48
 
@@ -138,7 +138,7 @@ class Client < Minitest::Test
138
138
  end
139
139
 
140
140
  def test_purge_files
141
- assert_equal({ "foo" => "bar" }, @max.purge(12345, [ "foo.txt", "bar.txt" ]))
141
+ assert_equal([{ "foo" => "bar" },{ "foo" => "bar" }], @max.purge(12345, [ "foo.txt", "bar.txt" ]))
142
142
  end
143
143
  end
144
144
 
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.3
4
+ version: 0.1.4
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-16 00:00:00.000000000 Z
12
+ date: 2014-02-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: signet
@@ -83,7 +83,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
83
83
  version: '0'
84
84
  segments:
85
85
  - 0
86
- hash: -4324918256587917915
86
+ hash: 545417652511611192
87
87
  required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  none: false
89
89
  requirements:
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  version: '0'
93
93
  segments:
94
94
  - 0
95
- hash: -4324918256587917915
95
+ hash: 545417652511611192
96
96
  requirements: []
97
97
  rubyforge_project:
98
98
  rubygems_version: 1.8.23