npo_assets 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -1,7 +1,8 @@
1
1
  class NpoAssetsGenerator < Rails::Generator::Base
2
2
  def manifest
3
3
  record do |m|
4
- m.migration_template('npo_assets.rb', 'db/migrate', :migration_file_name => 'create_assets')
4
+ m.migration_template('migration.rb', 'db/migrate', :migration_file_name => 'create_assets')
5
+ m.file('initializer.rb', 'config/initializers/npo_assets.rb')
5
6
  end
6
7
  end
7
8
  end
@@ -0,0 +1,2 @@
1
+ NPO::Assets.base_url = 'http://media.omroep.nl'
2
+ NPO::Assets.account_name = ''
@@ -11,7 +11,7 @@ module NPO
11
11
 
12
12
  class << self
13
13
  def list(account_name=nil, options={})
14
- url = "#{ NPO::Assets::BASE_URL }.xml#{ extract_list_options(options) }"
14
+ url = "#{ NPO::Assets.base_url }.xml#{ extract_list_options(options) }"
15
15
  res = get(url, :headers => headers(account_name))
16
16
 
17
17
  if res && res['assets']
@@ -24,7 +24,7 @@ module NPO
24
24
  end
25
25
 
26
26
  def headers(account_name=nil)
27
- {'X-Account' => account_name || NPO::Assets::ACCOUNT_NAME}
27
+ {'X-Account' => account_name || NPO::Assets.account_name}
28
28
  end
29
29
 
30
30
  private
@@ -37,7 +37,7 @@ module NPO
37
37
  end
38
38
 
39
39
  def url(size='')
40
- File.join(NPO::Assets::BASE_URL, size, attributes['url'])
40
+ File.join(NPO::Assets.base_url, size, attributes['url'])
41
41
  end
42
42
 
43
43
  private
@@ -46,7 +46,7 @@ module NPO
46
46
  # run due to saving an imported asset
47
47
  return true if self.remote_id && new_record?
48
48
 
49
- url = [NPO::Assets::BASE_URL]
49
+ url = [NPO::Assets.base_url]
50
50
  url << self.remote_id unless new_record?
51
51
 
52
52
  response = self.class.send(new_record? ? :post : :put,
@@ -63,7 +63,7 @@ module NPO
63
63
  end
64
64
 
65
65
  def delete_from_media_server
66
- HTTParty.delete("#{NPO::Assets::BASE_URL}/#{self.remote_id}", :headers => self.class.headers)
66
+ HTTParty.delete("#{NPO::Assets.base_url}/#{self.remote_id}", :headers => self.class.headers)
67
67
  end
68
68
  end
69
69
  end
data/lib/npo_assets.rb CHANGED
@@ -3,7 +3,6 @@ require 'npo_assets/asset'
3
3
 
4
4
  module NPO
5
5
  module Assets
6
- BASE_URL = 'http://media.omroep.nl/assets'
7
- ACCOUNT_NAME = "omroep_nl"
6
+ mattr_accessor :base_url, :account_name
8
7
  end
9
8
  end
data/npo_assets.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{npo_assets}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
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"]
@@ -24,7 +24,8 @@ Gem::Specification.new do |s|
24
24
  "Rakefile",
25
25
  "VERSION",
26
26
  "generators/npo_assets/npo_assets_generator.rb",
27
- "generators/npo_assets/templates/npo_assets.rb",
27
+ "generators/npo_assets/templates/initializer.rb",
28
+ "generators/npo_assets/templates/migration.rb",
28
29
  "lib/npo_assets.rb",
29
30
  "lib/npo_assets/asset.rb",
30
31
  "npo_assets.gemspec",
@@ -3,6 +3,8 @@ require File.dirname(__FILE__) + '/../spec_helper'
3
3
  describe NPO::Assets::Asset do
4
4
  before(:all) do
5
5
  setup_db
6
+ NPO::Assets.base_url = 'http://test.com/assets'
7
+ NPO::Assets.account_name = 'account'
6
8
  end
7
9
 
8
10
  after(:all) do
@@ -23,9 +25,9 @@ describe NPO::Assets::Asset do
23
25
  end
24
26
 
25
27
  it "should send the correct vars" do
26
- NPO::Assets::Asset.should_receive(:post).with("http://media.omroep.nl/assets",
28
+ NPO::Assets::Asset.should_receive(:post).with("http://test.com/assets",
27
29
  :query => {:asset => {:file => "file"}},
28
- :headers => {'X-Account' => 'omroep_nl'})
30
+ :headers => {'X-Account' => 'account'})
29
31
  do_create
30
32
  end
31
33
 
@@ -92,9 +94,9 @@ describe NPO::Assets::Asset do
92
94
  end
93
95
 
94
96
  it "should send the correct vars" do
95
- NPO::Assets::Asset.should_receive(:put).with("http://media.omroep.nl/assets/2",
97
+ NPO::Assets::Asset.should_receive(:put).with("http://test.com/assets/2",
96
98
  :query => {:asset => {:file => "new_file"}},
97
- :headers => {'X-Account' => 'omroep_nl'})
99
+ :headers => {'X-Account' => 'account'})
98
100
  do_update
99
101
  end
100
102
 
@@ -146,7 +148,7 @@ describe NPO::Assets::Asset do
146
148
  end
147
149
 
148
150
  it "should send the correct vars" do
149
- HTTParty.should_receive(:delete).with("http://media.omroep.nl/assets/2", :headers => {'X-Account' => 'omroep_nl'})
151
+ HTTParty.should_receive(:delete).with("http://test.com/assets/2", :headers => {'X-Account' => 'account'})
150
152
  @asset.destroy
151
153
  end
152
154
  end
@@ -162,11 +164,11 @@ describe NPO::Assets::Asset do
162
164
  end
163
165
 
164
166
  it "should return the correct url without a size" do
165
- @asset.url.should == "http://media.omroep.nl/assets/1.jpg"
167
+ @asset.url.should == "http://test.com/assets/1.jpg"
166
168
  end
167
169
 
168
170
  it "should return the correct url with a size" do
169
- @asset.url('100x200').should == "http://media.omroep.nl/assets/100x200/1.jpg"
171
+ @asset.url('100x200').should == "http://test.com/assets/100x200/1.jpg"
170
172
  end
171
173
  end
172
174
 
@@ -185,28 +187,28 @@ describe NPO::Assets::Asset do
185
187
  end
186
188
 
187
189
  it "should call the correct url with an explicit account name" do
188
- should_get('http://media.omroep.nl/assets.xml', :headers => {'X-Account' => 'foo'})
190
+ should_get('http://test.com/assets.xml', :headers => {'X-Account' => 'foo'})
189
191
  do_list('foo')
190
192
  end
191
193
 
192
194
  it "should call the correct url without an explicit account name" do
193
- should_get('http://media.omroep.nl/assets.xml', :headers => {'X-Account' => 'omroep_nl'})
195
+ should_get('http://test.com/assets.xml', :headers => {'X-Account' => 'account'})
194
196
  NPO::Assets::Asset.list
195
197
  end
196
198
 
197
199
  describe "with options" do
198
200
  it "should use :per_page" do
199
- should_get('http://media.omroep.nl/assets.xml?per_page=10', :headers => {'X-Account' => 'foo'})
201
+ should_get('http://test.com/assets.xml?per_page=10', :headers => {'X-Account' => 'foo'})
200
202
  do_list('foo', :per_page => 10)
201
203
  end
202
204
 
203
205
  it "should use :page" do
204
- should_get('http://media.omroep.nl/assets.xml?page=2', :headers => {'X-Account' => 'foo'})
206
+ should_get('http://test.com/assets.xml?page=2', :headers => {'X-Account' => 'foo'})
205
207
  do_list('foo', :page => 2)
206
208
  end
207
209
 
208
210
  it "should use :page and :per_page" do
209
- should_get('http://media.omroep.nl/assets.xml?page=2&per_page=10', :headers => {'X-Account' => 'foo'})
211
+ should_get('http://test.com/assets.xml?page=2&per_page=10', :headers => {'X-Account' => 'foo'})
210
212
  do_list('foo', :page => 2, :per_page => 10)
211
213
  end
212
214
  end
@@ -1,11 +1,4 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe NPO::Assets do
4
- it "should set the correct BASE_URL" do
5
- NPO::Assets::BASE_URL.should == 'http://media.omroep.nl/assets'
6
- end
7
-
8
- it "should set an empty account name" do
9
- NPO::Assets::ACCOUNT_NAME.should == "omroep_nl"
10
- end
11
4
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Bart Zonneveld
@@ -48,7 +48,8 @@ files:
48
48
  - Rakefile
49
49
  - VERSION
50
50
  - generators/npo_assets/npo_assets_generator.rb
51
- - generators/npo_assets/templates/npo_assets.rb
51
+ - generators/npo_assets/templates/initializer.rb
52
+ - generators/npo_assets/templates/migration.rb
52
53
  - lib/npo_assets.rb
53
54
  - lib/npo_assets/asset.rb
54
55
  - npo_assets.gemspec