carrierwave-flickr 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 982fc91dac7e6c2422ed8c056e0e32a804d5481b
4
+ data.tar.gz: ffa3179a70a6d7d939f8e2ec27063682aaefac13
5
+ SHA512:
6
+ metadata.gz: 0d6158cf5609f9be035092f7a7bef38eef362f5dd17ec184c3dbea93081658f389effae7c7179fe61d8cffaf3a71aad2bc874b1065c2f84ef8eb92c5b509f4c6
7
+ data.tar.gz: 3fc9e1dab54fda42a60166f05d5c542d6c4a8439a3321e5db06de3992ad3b9d23a13d1d21705e547f4c2f7db693024cbe28e132be537e80b8e232a08975b4bfa
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /uploads
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in carrierwave-flickr.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'rspec-mocks', git: 'git@github.com:rspec/rspec-mocks.git'
8
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Dzmitry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # Carrierwave::Flickr
2
+
3
+ ## Why do you need this library?
4
+
5
+ * You want to store images in a fast and highly available storage
6
+ * You want photos to be publicly available in the Internet
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'carrierwave-flickr'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install carrierwave-flickr
23
+
24
+ ## Usage
25
+
26
+ Put these lines in your carriervawe initializer
27
+
28
+ ```ruby
29
+ CarrierWave.configure do |config|
30
+ config.flickr_credentials = {
31
+ key: 'YOUR_API_KEY',
32
+ secret: 'YOUR_SECRET',
33
+ oauth_token: 'YOUR_TOKEN',
34
+ oauth_token_secret: 'YOUR_TOKEN_SECRET'
35
+ }
36
+ end
37
+ ```
38
+
39
+ If you want all photos to be stored in a specific album you can specify it
40
+
41
+ ```ruby
42
+ CarrierWave.configure do |config|
43
+ config.flickr_credentials = {
44
+ ...
45
+ album: 'YOUR_ALBUM_ID'
46
+ }
47
+ end
48
+ ```
49
+
50
+ If you want to store photo sizes configure the column where to put them
51
+
52
+ ```ruby
53
+ CarrierWave.configure do |config|
54
+ config.store_flickr_photo_sizes = :sizes
55
+ end
56
+ ```
57
+
58
+ ## Contributing
59
+
60
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hirurg103/carrierwave-flickr.
61
+
62
+
63
+ ## License
64
+
65
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
66
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "carrierwave/flickr"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'carrierwave/flickr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "carrierwave-flickr"
8
+ spec.version = Carrierwave::Flickr::VERSION
9
+ spec.authors = ["Dzmitry Kavalionak"]
10
+ spec.email = ["dzm.kov@gmail.com"]
11
+
12
+ spec.summary = %q{Save your image attachments in http://flickr.com/ using Carrierwave}
13
+ spec.homepage = "https://github.com/Hirurg103/carrierwave-flickr"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency 'carrierwave', '~> 1.0'
30
+ spec.add_dependency 'flickraw', '~> 0.9'
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.11"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "3.6.0.beta2"
35
+ spec.add_development_dependency "activerecord", '~> 5.0'
36
+ spec.add_development_dependency "sqlite3", '~> 1.3'
37
+ spec.add_development_dependency "pry", '~> 0.2.3'
38
+ end
@@ -0,0 +1,21 @@
1
+ module CarrierWave
2
+ module Flickr
3
+ module ActiveRecord
4
+ private
5
+
6
+ def mount_base(column, uploader=nil, options={}, &block)
7
+ super
8
+
9
+ after_save :"store_flickr_#{column}_identifier"
10
+ class_eval <<-RUBY, __FILE__, __LINE__+1
11
+ def store_flickr_#{column}_identifier
12
+ update_column :"#{column}", read_attribute(:"#{column}")
13
+ end
14
+ RUBY
15
+ end
16
+
17
+ end
18
+ end
19
+ end
20
+
21
+ ActiveRecord::Base.extend CarrierWave::Flickr::ActiveRecord
@@ -0,0 +1,31 @@
1
+ module CarrierWave
2
+ module Flickr
3
+ module Configuration
4
+
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ add_config :flickr_credentials
9
+ add_config :store_flickr_photo_sizes
10
+
11
+ class << self
12
+ alias_method :flickr_without_configuration=, :flickr_credentials=
13
+ alias_method :flickr_credentials=, :flickr_with_configuration=
14
+ end
15
+ end
16
+
17
+ module ClassMethods
18
+
19
+ def flickr_with_configuration=(credentials)
20
+ self.flickr_without_configuration = credentials
21
+
22
+ FlickRaw.api_key = credentials[:key]
23
+ FlickRaw.shared_secret = credentials[:secret]
24
+
25
+ flickr.access_token = credentials[:oauth_token]
26
+ flickr.access_secret = credentials[:oauth_token_secret]
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ module Carrierwave
2
+ module Flickr
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ require "carrierwave/flickr/version"
2
+ require "carrierwave/storage/flickr"
3
+
4
+ module CarrierWave
5
+ module Flickr
6
+ end
7
+ end
8
+
9
+ require 'carrierwave'
10
+ CarrierWave.configure do |config|
11
+ config.storage_engines[:flickr] = 'CarrierWave::Storage::Flickr'
12
+ end
13
+
14
+ require 'carrierwave/flickr/configuration'
15
+ CarrierWave::Uploader::Base.include(CarrierWave::Flickr::Configuration)
16
+
17
+ if defined?(Rails)
18
+ module CarrierWave
19
+ module Flickr
20
+ class Railtie < Rails::Railtie
21
+ initializer "carrierwave-flickr.active_record" do
22
+ ActiveSupport.on_load :active_record do
23
+ require 'carrierwave/flickr/active_record'
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,135 @@
1
+ require 'carrierwave/storage/abstract'
2
+ require 'flickraw'
3
+
4
+ module CarrierWave
5
+ module Storage
6
+ class Flickr < Abstract
7
+
8
+ def store!(file)
9
+ f = CarrierWave::Storage::Flickr::File.new(uploader, self)
10
+ @info = f.store(file)
11
+ store_identifier
12
+ store_sizes if store_sizes?
13
+ f
14
+ end
15
+
16
+ def retrieve!(identifier)
17
+ info = JSON.parse(identifier)
18
+ CarrierWave::Storage::Flickr::File.new(uploader, self, info)
19
+ end
20
+
21
+ def identifier
22
+ (@info.as_json || {}).slice(
23
+ 'id',
24
+ 'secret',
25
+ 'server',
26
+ 'farm',
27
+ 'originalsecret',
28
+ 'originalformat').to_json
29
+ end
30
+
31
+ private
32
+
33
+ def store_identifier
34
+ column = @uploader.mounted_as
35
+ model = @uploader.model
36
+
37
+ model.public_send(:"write_#{column}_identifier")
38
+ end
39
+
40
+ def store_sizes
41
+ photo_sizes = flickr.photos.getSizes 'photo_id' => @info['id']
42
+
43
+ model = @uploader.model
44
+
45
+ model.update_column uploader.store_flickr_photo_sizes, prepare_sizes(photo_sizes)
46
+ end
47
+
48
+ def prepare_sizes(raw_sizes)
49
+ raw_sizes.each_with_object({}) do |raw_size, sizes|
50
+ key = raw_size['label'].downcase.gsub(/ /, '_').to_sym
51
+
52
+ sizes[key] = {
53
+ height: raw_size['height'].to_i,
54
+ width: raw_size['width'].to_i
55
+ }
56
+ end
57
+ end
58
+
59
+ def store_sizes?
60
+ uploader.store_flickr_photo_sizes.present?
61
+ end
62
+
63
+ class File
64
+ def initialize(uploader, base, info = nil)
65
+ @uploader = uploader
66
+ @base = base
67
+ @info = FlickRaw::Response.build(info, 'photo') if info
68
+ end
69
+
70
+ def url(format: :original)
71
+ FlickRaw.public_send(format_getter(format), @info) if @info
72
+ end
73
+
74
+ def path
75
+ url
76
+ end
77
+
78
+ def store(new_file)
79
+ file = new_file.to_file
80
+
81
+ photo_id = flickr.upload_photo file, **store_options
82
+
83
+ add_to_album(photo_id) if album.present?
84
+
85
+ file.close if file && !file.closed?
86
+
87
+ @info = flickr.photos.getInfo('photo_id' => photo_id)
88
+ end
89
+
90
+ def delete
91
+ flickr.photos.delete 'photo_id' => @info['id']
92
+ end
93
+
94
+ def add_to_album(photo_id)
95
+ flickr.photosets.addPhoto(
96
+ 'photo_id' => photo_id,
97
+ 'photoset_id' => album)
98
+ end
99
+
100
+ def album
101
+ @uploader.flickr_credentials[:album]
102
+ end
103
+
104
+ private
105
+
106
+ def store_options
107
+ {}.tap do |options|
108
+ options[:title] = model.title if model.respond_to?(:title)
109
+ options[:description] = model.description if model.respond_to?(:description)
110
+ end.reject { |k, v| v.blank? }
111
+ end
112
+
113
+ def model
114
+ @uploader.model
115
+ end
116
+
117
+ def format_getter(format)
118
+ {
119
+ square: :url_s,
120
+ large_square: :url_q,
121
+ thumbnail: :url_t,
122
+ small: :url_m,
123
+ small_320: :url_n,
124
+ medium: :url,
125
+ medium_640: :url_z,
126
+ medium_800: :url_c,
127
+ large: :url_b,
128
+ original: :url_o
129
+ }.fetch(format)
130
+ end
131
+ end
132
+
133
+ end
134
+ end
135
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carrierwave-flickr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dzmitry Kavalionak
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-04-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: carrierwave
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: flickraw
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 3.6.0.beta2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 3.6.0.beta2
83
+ - !ruby/object:Gem::Dependency
84
+ name: activerecord
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '5.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '5.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.2.3
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.2.3
125
+ description:
126
+ email:
127
+ - dzm.kov@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".travis.yml"
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - bin/console
140
+ - bin/setup
141
+ - carrierwave-flickr.gemspec
142
+ - lib/carrierwave/flickr.rb
143
+ - lib/carrierwave/flickr/activerecord.rb
144
+ - lib/carrierwave/flickr/configuration.rb
145
+ - lib/carrierwave/flickr/version.rb
146
+ - lib/carrierwave/storage/flickr.rb
147
+ homepage: https://github.com/Hirurg103/carrierwave-flickr
148
+ licenses:
149
+ - MIT
150
+ metadata:
151
+ allowed_push_host: https://rubygems.org
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 2.4.8
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: Save your image attachments in http://flickr.com/ using Carrierwave
172
+ test_files: []