npo_assets 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/npo_assets/asset.rb +20 -13
- data/lib/npo_assets.rb +2 -1
- data/npo_assets.gemspec +22 -25
- data/spec/npo_assets/asset_spec.rb +34 -30
- metadata +17 -9
- data/.gitignore +0 -21
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/npo_assets/asset.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
module NPO
|
2
2
|
module Assets
|
3
3
|
class Asset < ActiveRecord::Base
|
4
|
-
include HTTParty
|
5
|
-
format :xml
|
6
|
-
|
7
4
|
attr_accessor :file, :remote_url
|
8
5
|
|
9
6
|
before_save :post_to_media_server
|
@@ -11,8 +8,9 @@ module NPO
|
|
11
8
|
|
12
9
|
class << self
|
13
10
|
def list(account_name=nil, options={})
|
14
|
-
url
|
15
|
-
res
|
11
|
+
url = "#{ NPO::Assets.base_url }/assets.xml#{ extract_list_options(options) }"
|
12
|
+
res = RestClient.get(url, :headers => headers(account_name))
|
13
|
+
res = Crack::XML.parse(res)
|
16
14
|
|
17
15
|
if res && res['assets']
|
18
16
|
res['assets']['asset'].map do |vars|
|
@@ -49,23 +47,32 @@ module NPO
|
|
49
47
|
url = [NPO::Assets.base_url, 'assets']
|
50
48
|
url << self.remote_id unless new_record?
|
51
49
|
|
52
|
-
|
53
|
-
|
50
|
+
if @file
|
51
|
+
attrs = {:file => @file}
|
52
|
+
else
|
53
|
+
attrs = {:url => @remote_url}
|
54
|
+
end
|
55
|
+
|
56
|
+
response = RestClient.send(new_record? ? :post : :put,
|
54
57
|
url.join('/'),
|
55
|
-
|
56
|
-
|
58
|
+
{ :asset => attrs },
|
59
|
+
self.class.headers)
|
60
|
+
puts response
|
61
|
+
vars = Crack::XML.parse(response)
|
62
|
+
|
57
63
|
if response.code == 422
|
58
|
-
|
64
|
+
vars['errors']['error'].each { |msg| errors.add_to_base(msg) }
|
59
65
|
false
|
60
66
|
else
|
61
|
-
self.url =
|
62
|
-
self.remote_id =
|
67
|
+
self.url = vars['asset']['url']
|
68
|
+
self.remote_id = vars['asset']['id']
|
63
69
|
true
|
64
70
|
end
|
65
71
|
end
|
66
72
|
|
67
73
|
def delete_from_media_server
|
68
|
-
|
74
|
+
RestClient.delete("#{NPO::Assets.base_url}/assets/#{self.remote_id}", self.class.headers)
|
75
|
+
rescue RestClient::ResourceNotFound
|
69
76
|
end
|
70
77
|
end
|
71
78
|
end
|
data/lib/npo_assets.rb
CHANGED
data/npo_assets.gemspec
CHANGED
@@ -1,55 +1,52 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{npo_assets}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Bart Zonneveld"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-04-12}
|
13
13
|
s.description = %q{Wrapper for media db}
|
14
14
|
s.email = %q{loop@superinfinite.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
|
17
|
+
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
"spec/spec_helper.rb"
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"generators/npo_assets/npo_assets_generator.rb",
|
26
|
+
"generators/npo_assets/templates/initializer.rb",
|
27
|
+
"generators/npo_assets/templates/migration.rb",
|
28
|
+
"lib/npo_assets.rb",
|
29
|
+
"lib/npo_assets/asset.rb",
|
30
|
+
"npo_assets.gemspec",
|
31
|
+
"spec/npo_assets/asset_spec.rb",
|
32
|
+
"spec/npo_assets_spec.rb",
|
33
|
+
"spec/spec.opts",
|
34
|
+
"spec/spec_helper.rb"
|
36
35
|
]
|
37
36
|
s.homepage = %q{http://github.com/bartzon/npo_assets}
|
38
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
39
37
|
s.require_paths = ["lib"]
|
40
|
-
s.rubygems_version = %q{1.
|
38
|
+
s.rubygems_version = %q{1.6.2}
|
41
39
|
s.summary = %q{Wrapper for media db}
|
42
40
|
s.test_files = [
|
43
41
|
"spec/npo_assets/asset_spec.rb",
|
44
|
-
|
45
|
-
|
42
|
+
"spec/npo_assets_spec.rb",
|
43
|
+
"spec/spec_helper.rb"
|
46
44
|
]
|
47
45
|
|
48
46
|
if s.respond_to? :specification_version then
|
49
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
50
47
|
s.specification_version = 3
|
51
48
|
|
52
|
-
if Gem::Version.new(Gem::
|
49
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
53
50
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
54
51
|
s.add_development_dependency(%q<httparty>, [">= 0"])
|
55
52
|
else
|
@@ -14,8 +14,8 @@ describe NPO::Assets::Asset do
|
|
14
14
|
describe "posting to the server" do
|
15
15
|
before(:each) do
|
16
16
|
hash = {"asset" => {"url" => "url", "remote_id" => "2"}}
|
17
|
-
|
18
|
-
|
17
|
+
Crack::XML.stub!(:parse).and_return hash
|
18
|
+
RestClient.stub!(:post).and_return mock("Response", :code => 200)
|
19
19
|
@asset = NPO::Assets::Asset.new(:file => "file")
|
20
20
|
end
|
21
21
|
|
@@ -25,17 +25,17 @@ describe NPO::Assets::Asset do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should send the correct vars with a file upload" do
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
RestClient.should_receive(:post).with("http://test.com/assets",
|
29
|
+
{:asset => {:file => "file"}},
|
30
|
+
{'X-Account' => 'account'})
|
31
31
|
do_create
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should send the correct vars with a remote url" do
|
35
35
|
asset = NPO::Assets::Asset.new(:remote_url => "remote_url")
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
RestClient.should_receive(:post).with("http://test.com/assets",
|
37
|
+
{:asset => {:url => "remote_url"}},
|
38
|
+
{'X-Account' => 'account'})
|
39
39
|
asset.save
|
40
40
|
end
|
41
41
|
|
@@ -47,8 +47,8 @@ describe NPO::Assets::Asset do
|
|
47
47
|
"updated_at" => "2010-03-03T12:42:47Z",
|
48
48
|
"url" => "000/000/000.jpg",
|
49
49
|
"file_size" => "12645"} }
|
50
|
-
|
51
|
-
|
50
|
+
Crack::XML.stub!(:parse).and_return hash
|
51
|
+
RestClient.stub!(:post).and_return mock("Response", :code => 200)
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should return true" do
|
@@ -74,8 +74,8 @@ describe NPO::Assets::Asset do
|
|
74
74
|
describe "with failed save" do
|
75
75
|
before(:each) do
|
76
76
|
hash = {"errors"=>{"error"=>"File must be set."}}
|
77
|
-
|
78
|
-
|
77
|
+
Crack::XML.stub!(:parse).and_return hash
|
78
|
+
RestClient.stub!(:post).and_return mock("Response", :code => 422)
|
79
79
|
end
|
80
80
|
|
81
81
|
it "should return false" do
|
@@ -99,7 +99,9 @@ describe NPO::Assets::Asset do
|
|
99
99
|
@asset.remote_id = 2
|
100
100
|
@asset.save
|
101
101
|
@asset.file = "new_file"
|
102
|
-
|
102
|
+
Crack::XML.stub!(:parse).and_return({'asset' => {'url' => '', 'id' => ''}})
|
103
|
+
RestClient.stub!(:put).and_return mock("Response", :code => 200)
|
104
|
+
File.stub!(:new).and_return 'file'
|
103
105
|
end
|
104
106
|
|
105
107
|
def do_update
|
@@ -107,9 +109,9 @@ describe NPO::Assets::Asset do
|
|
107
109
|
end
|
108
110
|
|
109
111
|
it "should send the correct vars" do
|
110
|
-
|
111
|
-
|
112
|
-
|
112
|
+
RestClient.should_receive(:put).with("http://test.com/assets/2",
|
113
|
+
{:asset => {:file => 'new_file'}},
|
114
|
+
{'X-Account' => 'account'})
|
113
115
|
do_update
|
114
116
|
end
|
115
117
|
|
@@ -121,8 +123,8 @@ describe NPO::Assets::Asset do
|
|
121
123
|
"updated_at" => "2010-03-03T12:42:47Z",
|
122
124
|
"url" => "000/000/000.jpg",
|
123
125
|
"file_size" => "12645"} }
|
124
|
-
|
125
|
-
|
126
|
+
Crack::XML.stub!(:parse).and_return hash
|
127
|
+
RestClient.stub!(:put).and_return mock("Response", :code => 200)
|
126
128
|
end
|
127
129
|
|
128
130
|
it "should return true" do
|
@@ -138,8 +140,8 @@ describe NPO::Assets::Asset do
|
|
138
140
|
describe "with failed save" do
|
139
141
|
before(:each) do
|
140
142
|
hash = {"errors"=>{"error"=>"File must be set."}}
|
141
|
-
|
142
|
-
|
143
|
+
Crack::XML.stub!(:parse).and_return hash
|
144
|
+
RestClient.stub!(:put).and_return mock("Response", :code => 422)
|
143
145
|
end
|
144
146
|
|
145
147
|
it "should return false" do
|
@@ -157,11 +159,11 @@ describe NPO::Assets::Asset do
|
|
157
159
|
before(:each) do
|
158
160
|
@asset.remote_id = 2
|
159
161
|
@asset.save
|
160
|
-
|
162
|
+
RestClient.stub!(:delete).and_return @response
|
161
163
|
end
|
162
164
|
|
163
165
|
it "should send the correct vars" do
|
164
|
-
|
166
|
+
RestClient.should_receive(:delete).with("http://test.com/assets/2", {'X-Account' => 'account'})
|
165
167
|
@asset.destroy
|
166
168
|
end
|
167
169
|
end
|
@@ -170,8 +172,8 @@ describe NPO::Assets::Asset do
|
|
170
172
|
describe "when generating an url" do
|
171
173
|
before(:each) do
|
172
174
|
hash = {"asset" => {"url" => "1.jpg"}}
|
173
|
-
|
174
|
-
|
175
|
+
Crack::XML.stub!(:parse).and_return hash
|
176
|
+
RestClient.stub!(:post).and_return mock("Response", :code => 200)
|
175
177
|
|
176
178
|
@asset = NPO::Assets::Asset.create!
|
177
179
|
end
|
@@ -188,7 +190,8 @@ describe NPO::Assets::Asset do
|
|
188
190
|
describe "when listing the assets" do
|
189
191
|
describe "request" do
|
190
192
|
before(:each) do
|
191
|
-
|
193
|
+
Crack::XML.stub!(:parse)
|
194
|
+
RestClient.stub!(:get).and_return mock("Response", :code => 200)
|
192
195
|
end
|
193
196
|
|
194
197
|
def do_list(account='omroep_nl', options={})
|
@@ -196,7 +199,7 @@ describe NPO::Assets::Asset do
|
|
196
199
|
end
|
197
200
|
|
198
201
|
def should_get(url, options)
|
199
|
-
|
202
|
+
RestClient.should_receive(:get).with(url, options)
|
200
203
|
end
|
201
204
|
|
202
205
|
it "should call the correct url with an explicit account name" do
|
@@ -233,7 +236,8 @@ describe NPO::Assets::Asset do
|
|
233
236
|
"asset"=>[{"name"=>"bach", "url"=>"000/000/001.jpg", "id"=>"10"},
|
234
237
|
{"name"=>"bach", "url"=>"000/000/002.jpg", "id"=>"20"}]}}
|
235
238
|
|
236
|
-
|
239
|
+
Crack::XML.stub!(:parse).and_return @response
|
240
|
+
RestClient.stub!(:get).and_return mock("Response")
|
237
241
|
end
|
238
242
|
|
239
243
|
def do_list
|
@@ -241,7 +245,7 @@ describe NPO::Assets::Asset do
|
|
241
245
|
end
|
242
246
|
|
243
247
|
it "should return [] if there are no items" do
|
244
|
-
|
248
|
+
Crack::XML.stub!(:parse).and_return("nil_classes" => nil)
|
245
249
|
do_list.should == []
|
246
250
|
end
|
247
251
|
|
@@ -252,8 +256,8 @@ describe NPO::Assets::Asset do
|
|
252
256
|
end
|
253
257
|
|
254
258
|
it "should not post to the server *again*" do
|
255
|
-
|
256
|
-
|
259
|
+
RestClient.should_not_receive(:post)
|
260
|
+
RestClient.should_not_receive(:put)
|
257
261
|
do_list
|
258
262
|
end
|
259
263
|
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: npo_assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Bart Zonneveld
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
+
date: 2011-04-12 00:00:00 +02:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: rspec
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
27
30
|
segments:
|
28
31
|
- 1
|
29
32
|
- 2
|
@@ -35,9 +38,11 @@ dependencies:
|
|
35
38
|
name: httparty
|
36
39
|
prerelease: false
|
37
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
38
42
|
requirements:
|
39
43
|
- - ">="
|
40
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
41
46
|
segments:
|
42
47
|
- 0
|
43
48
|
version: "0"
|
@@ -54,7 +59,6 @@ extra_rdoc_files:
|
|
54
59
|
- README.rdoc
|
55
60
|
files:
|
56
61
|
- .document
|
57
|
-
- .gitignore
|
58
62
|
- LICENSE
|
59
63
|
- README.rdoc
|
60
64
|
- Rakefile
|
@@ -74,28 +78,32 @@ homepage: http://github.com/bartzon/npo_assets
|
|
74
78
|
licenses: []
|
75
79
|
|
76
80
|
post_install_message:
|
77
|
-
rdoc_options:
|
78
|
-
|
81
|
+
rdoc_options: []
|
82
|
+
|
79
83
|
require_paths:
|
80
84
|
- lib
|
81
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
82
87
|
requirements:
|
83
88
|
- - ">="
|
84
89
|
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
85
91
|
segments:
|
86
92
|
- 0
|
87
93
|
version: "0"
|
88
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
89
96
|
requirements:
|
90
97
|
- - ">="
|
91
98
|
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
92
100
|
segments:
|
93
101
|
- 0
|
94
102
|
version: "0"
|
95
103
|
requirements: []
|
96
104
|
|
97
105
|
rubyforge_project:
|
98
|
-
rubygems_version: 1.
|
106
|
+
rubygems_version: 1.6.2
|
99
107
|
signing_key:
|
100
108
|
specification_version: 3
|
101
109
|
summary: Wrapper for media db
|