paperclip-imgur 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -1
- data/README.md +7 -0
- data/lib/paperclip/storage/imgur.rb +5 -3
- data/paperclip-imgur.gemspec +4 -2
- data/spec/paperclip/storage/imgur_spec.rb +43 -39
- metadata +32 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8877dbb4a1024efedb5aaf05ed464ba3afec1e5
|
4
|
+
data.tar.gz: e42b2eb47c205eb82c9d11fd94051da3dea856a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91805a6e3e48e39cd241229e705ec509858440696459d435cb8d95251c4760b7ee23e1896131e7026c06f013df00192eb6f88af23d22d3f78102d8ae8ab066da
|
7
|
+
data.tar.gz: 101fc71a146559fb2c6a533ab4b6b7bcd83fdc151bcf8e20f35c708f2ac7b196df6029fd44a74d91b7607587f558591c9606d2fab9aa7e3dc8b10f461966734c
|
data/.rspec
CHANGED
@@ -1 +1 @@
|
|
1
|
-
--color
|
1
|
+
--color
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'erb'
|
3
|
-
require '
|
3
|
+
require 'imgurapi'
|
4
4
|
|
5
5
|
module Paperclip
|
6
6
|
module Storage
|
@@ -64,7 +64,7 @@ module Paperclip
|
|
64
64
|
|
65
65
|
return @url_generator.for(size, {}) if image_id.nil? || image_id.empty? # Show Paperclip's default missing image path
|
66
66
|
|
67
|
-
::
|
67
|
+
::Imgurapi::Image.new(id: image_id).url(size)
|
68
68
|
end
|
69
69
|
|
70
70
|
# Returns the path of the attachment.
|
@@ -83,7 +83,7 @@ module Paperclip
|
|
83
83
|
private
|
84
84
|
|
85
85
|
def imgur_session
|
86
|
-
@imgur_session ||= ::
|
86
|
+
@imgur_session ||= ::Imgurapi::Session.instance(@imgur_credentials)
|
87
87
|
end
|
88
88
|
|
89
89
|
def parse_credentials(credentials = nil)
|
@@ -96,6 +96,8 @@ module Paperclip
|
|
96
96
|
YAML.load(ERB.new(File.read(credentials.path)).result)
|
97
97
|
when String, Pathname
|
98
98
|
YAML.load(ERB.new(File.read(credentials)).result)
|
99
|
+
else
|
100
|
+
credentials
|
99
101
|
end
|
100
102
|
|
101
103
|
return credentials.stringify_keys if credentials.respond_to? :stringify_keys
|
data/paperclip-imgur.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = 'paperclip-imgur'
|
7
|
-
gem.version = '0.1.
|
7
|
+
gem.version = '0.1.2'
|
8
8
|
gem.authors = ['Daniel Cruz Horts']
|
9
9
|
gem.description = %q{Extends Paperclip with Imgur storage}
|
10
10
|
gem.summary = gem.description
|
@@ -16,5 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
17
|
gem.require_paths = ['lib']
|
18
18
|
|
19
|
-
gem.add_dependency 'imgurapi', '~>
|
19
|
+
gem.add_dependency 'imgurapi', '~> 3.0.0'
|
20
|
+
gem.add_development_dependency 'byebug'
|
21
|
+
gem.add_development_dependency 'rspec'
|
20
22
|
end
|
@@ -12,84 +12,88 @@ class CreateUsers < ActiveRecord::Migration
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe Paperclip::Storage::Imgur do
|
15
|
-
|
15
|
+
def set_options(options)
|
16
|
+
stub_const(
|
17
|
+
'User',
|
18
|
+
Class.new(ActiveRecord::Base) do
|
19
|
+
has_attached_file :avatar, {storage: :imgur}.merge(options)
|
20
|
+
end
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
before :all do
|
16
25
|
ActiveRecord::Base.send(:include, Paperclip::Glue)
|
17
26
|
|
18
27
|
FileUtils.rm_rf 'tmp'
|
19
28
|
FileUtils.mkdir_p 'tmp'
|
20
29
|
ActiveRecord::Base.establish_connection('sqlite3:///tmp/foo.sqlite3')
|
21
30
|
CreateUsers.migrate(:up)
|
22
|
-
|
23
31
|
Paperclip.options[:log] = false
|
24
32
|
end
|
25
|
-
|
26
|
-
describe '#parse_credentials' do
|
27
|
-
def set_options(options)
|
28
|
-
stub_const('User', Class.new(ActiveRecord::Base) {
|
29
|
-
has_attached_file :avatar, { :storage => :imgur }.merge(options)
|
30
|
-
})
|
31
|
-
end
|
32
33
|
|
34
|
+
after :all do
|
35
|
+
CreateUsers.migrate(:down)
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#parse_credentials' do
|
33
39
|
it 'should complain when providing unsuitable credentials' do
|
34
|
-
set_options(:
|
35
|
-
expect { User.new.avatar }.to raise_error
|
40
|
+
set_options(imgur_credentials: 1)
|
36
41
|
|
37
|
-
|
38
|
-
expect { User.new.avatar }.to raise_error
|
42
|
+
expect { User.new.avatar }.to raise_error ArgumentError
|
39
43
|
end
|
40
|
-
|
44
|
+
|
41
45
|
it 'should accept a properly formed hash' do
|
42
|
-
set_options(:
|
46
|
+
set_options(imgur_credentials: {client_key: '1', client_secret: '2', access_token: '3', refresh_token: '4'})
|
47
|
+
|
43
48
|
expect { User.new.avatar }.to_not raise_error
|
44
49
|
end
|
45
50
|
|
46
51
|
it 'should use config/imgur.yml under a Rails application if we left credentials blank' do
|
47
|
-
stub_const(
|
52
|
+
stub_const(
|
53
|
+
'Rails',
|
54
|
+
Class.new {
|
48
55
|
def self.env
|
49
56
|
'testing'
|
50
57
|
end
|
51
58
|
def self.root
|
52
59
|
Dir.pwd
|
53
60
|
end
|
54
|
-
}
|
55
|
-
|
61
|
+
}
|
62
|
+
)
|
56
63
|
set_options({})
|
64
|
+
|
57
65
|
expect { User.new.avatar }.to_not raise_error
|
58
66
|
end
|
59
|
-
|
67
|
+
|
60
68
|
it 'should accept a file path' do
|
61
|
-
set_options(:
|
69
|
+
set_options(imgur_credentials: "#{Dir.pwd}/config/imgur.yml")
|
70
|
+
|
62
71
|
expect { User.new.avatar }.to_not raise_error
|
63
72
|
end
|
64
|
-
|
73
|
+
|
65
74
|
it 'should accept a file' do
|
66
|
-
set_options(:
|
75
|
+
set_options(imgur_credentials: File.open("#{Dir.pwd}/config/imgur.yml", 'r'))
|
76
|
+
|
67
77
|
expect { User.new.avatar }.to_not raise_error
|
68
78
|
end
|
69
79
|
end
|
70
|
-
|
71
|
-
describe '#url' do
|
72
|
-
before(:each) do
|
73
|
-
stub_const('User', Class.new(ActiveRecord::Base) { has_attached_file :avatar, :storage => :imgur, :imgur_credentials => {:app_key => '1', :app_secret => '2', :access_token => '3', :access_token_secret => '4'} })
|
74
80
|
|
75
|
-
|
76
|
-
|
81
|
+
describe '#url' do
|
82
|
+
before do
|
83
|
+
User = Class.new(ActiveRecord::Base) { has_attached_file :avatar, storage: :imgur, imgur_credentials: {client_key: '1', client_secret: '2', access_token: '3', refresh_token: '4'} }
|
77
84
|
end
|
78
85
|
|
79
86
|
it "should return the missing image path if there's no image" do
|
80
|
-
User.new.avatar.url.
|
81
|
-
User.new.avatar.url(:random_size).
|
87
|
+
expect(User.new.avatar.url).to eq '/avatars/original/missing.png'
|
88
|
+
expect(User.new.avatar.url(:random_size)).to eq '/avatars/random_size/missing.png'
|
82
89
|
end
|
83
90
|
|
84
91
|
it "should return Imgur's image paths if there's an image" do
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
@user.avatar.url(:large_thumbnail).should eq(session.url(@imgur_hash, :large_thumbnail))
|
92
|
+
user = User.create(avatar_file_name: 'random_valid_hash')
|
93
|
+
|
94
|
+
expect(user.avatar.url(:random_size)).to eq "http://i.imgur.com/random_valid_hash.jpg"
|
95
|
+
expect(user.avatar.url(:small_square)).to eq "http://i.imgur.com/random_valid_hashs.jpg"
|
96
|
+
expect(user.avatar.url(:large_thumbnail)).to eq "http://i.imgur.com/random_valid_hashl.jpg"
|
91
97
|
end
|
92
|
-
|
93
98
|
end
|
94
|
-
|
95
|
-
end
|
99
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip-imgur
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Cruz Horts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: imgurapi
|
@@ -16,14 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 3.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: byebug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
description: Extends Paperclip with Imgur storage
|
28
56
|
email:
|
29
57
|
executables: []
|