flickrpu 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ .DS_Store
@@ -0,0 +1,26 @@
1
+ Installation
2
+ ------------
3
+ * gem install flickrpu
4
+
5
+ Initialization
6
+ --------------
7
+ * require 'flickrpu'
8
+
9
+ Usage
10
+ -----
11
+ class Photo
12
+ attr_accessor :some_arbitrary_thing, :amazon_file
13
+ def save
14
+ your_s3_magic
15
+ end
16
+ def valid?; true; end
17
+ end
18
+
19
+ flickr = Flickrpu::Base.new("photo", num_photos, {:key => 'your key', :secret => 'your secret'}) do |photo|
20
+ photo.some_arbitrary_thing = thing
21
+ end
22
+ flickr.search
23
+
24
+ Notes
25
+ -----
26
+ Flickrpu saves an "amazon_file" field into your object and calls the "save" method on it. Your S3 magic should take these jams into account.
@@ -0,0 +1,40 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
3
+ require 'flickrpu/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = %q{flickrpu}
7
+ s.version = Flickrpu::VERSION
8
+ s.date = %q{2012-03-06}
9
+
10
+ s.summary = %q{Make S3 objects from Flickr photos.}
11
+ s.description = %q{Make S3 objects from Flickr photos. N.B. S3 not included.}
12
+ s.homepage = %q{http://github.com/poeks/flickrpu}
13
+
14
+ s.authors = ["Jen Oslislo"]
15
+ s.email = %q{twitterpoeks@gmail.com}
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test/*`.split("\n")
19
+
20
+ s.require_paths = ["lib"]
21
+
22
+ s.rubygems_version = %q{1.4.2}
23
+
24
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
25
+
26
+ if s.respond_to? :specification_version then
27
+ s.specification_version = 3
28
+
29
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
30
+ s.add_runtime_dependency(%q<flickr_fu>, ["~> 0.3.1"])
31
+ s.add_runtime_dependency(%q<extlib>, ["~> 0.9.15"])
32
+ else
33
+ s.add_dependency(%q<flickr_fu>, ["~> 0.3.1"])
34
+ s.add_dependency(%q<extlib>, ["~> 0.9.15"])
35
+ end
36
+ else
37
+ s.add_dependency(%q<flickr_fu>, ["~> 0.3.1"])
38
+ s.add_dependency(%q<extlib>, ["~> 0.9.15"])
39
+ end
40
+ end
@@ -0,0 +1,9 @@
1
+ require 'ostruct'
2
+ require 'rubygems'
3
+ require 'extlib'
4
+ require 'flickr_fu'
5
+
6
+ module Flickrpu
7
+ require 'flickrpu/base'
8
+ require 'flickrpu/version'
9
+ end
@@ -0,0 +1,90 @@
1
+ #require 'rubygems'
2
+ #require 'flickr_fu'
3
+
4
+ module Flickrpu
5
+
6
+ class Base
7
+
8
+ attr_accessor :photo_class_name, :config, :num_photos, :opts, :klass_opts, :flickr
9
+
10
+ def initialize(photo_class_name = "Photo", num_photos = 10, opts = {}, &klass_opts)
11
+
12
+ self.photo_class_name = photo_class_name
13
+ self.num_photos = num_photos
14
+ self.opts = opts
15
+ self.klass_opts = klass_opts
16
+ self.config = {
17
+ 'key' => opts[:key],
18
+ 'secret' => opts[:secret]
19
+ }
20
+ self
21
+ end
22
+
23
+ def klass
24
+ Kernel.const_get(self.photo_class_name.capitalize)
25
+ end
26
+
27
+ def save(flickr_photo)
28
+ flickr_url = flickr_photo.url
29
+ puts "Saving #{flickr_url}"
30
+
31
+ photo = self.klass.new
32
+ self.klass_opts.call(photo) if self.klass_opts
33
+ filename = rand(36**12).to_s(36)+'.jpg'
34
+ amazon_file = {
35
+ :filename => filename,
36
+ :type => 'image/jpeg',
37
+ :tempfile => open(flickr_url)
38
+ }
39
+ photo.amazon_file = amazon_file
40
+
41
+ if photo.valid?
42
+ photo.save
43
+ else
44
+ puts "Couldn't save photo #{photo.inspect} :("
45
+ photo.errors.each do |e|
46
+ puts e
47
+ end
48
+ end
49
+ 1
50
+ rescue NoMethodError => e
51
+ puts e.to_s
52
+ 0
53
+ rescue TypeError => e
54
+ puts "Couldn't retrieve Flickr url: #{e.to_s}"
55
+ exit
56
+ end
57
+
58
+ def self.from_file(dir, filename)
59
+ temp_file = copy_to_tempfile(dir, filename)
60
+ opt_obj = OpenStruct.new
61
+ opt_obj.url = temp_file
62
+ self.save(opt_obj)
63
+ File.safe_unlink(temp_file)
64
+ end
65
+
66
+ def from_file(dir, filename)
67
+ self.class.from_file(dir, filename)
68
+ end
69
+
70
+ def self.copy_to_tempfile(dir, filename)
71
+ tmp_dir = File.join('.', 'tmp')
72
+ Dir.mkdir(tmp_dir) if not File.directory?(tmp_dir)
73
+ File.copy(File.join(dir, filename), File.join(tmp_dir, filename), verbose = true)
74
+ temp_file
75
+ end
76
+
77
+ def search
78
+ puts self.config.inspect
79
+ self.flickr = ::Flickr.new(self.config)
80
+ this_photo = 0
81
+ flickr_photos = self.flickr.photos.get_recent({:per_page=>self.num_photos})
82
+ flickr_photos.each do |photo|
83
+ return if this_photo >= self.num_photos
84
+ this_photo += self.save(photo)
85
+ end
86
+ end
87
+
88
+
89
+ end
90
+ end
@@ -0,0 +1,3 @@
1
+ module Flickrpu
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,11 @@
1
+ require File.join(File.expand_path(File.join(File.dirname(__FILE__))), '..', 'lib', 'flickrpu')
2
+
3
+ require 'test/unit'
4
+
5
+ class ConfitTest < Test::Unit::TestCase
6
+
7
+ def test_true
8
+ assert true
9
+ end
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flickrpu
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jen Oslislo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-06 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: flickr_fu
16
+ requirement: &70275736534380 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.3.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70275736534380
25
+ - !ruby/object:Gem::Dependency
26
+ name: extlib
27
+ requirement: &70275736533740 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.9.15
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70275736533740
36
+ description: Make S3 objects from Flickr photos. N.B. S3 not included.
37
+ email: twitterpoeks@gmail.com
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - .gitignore
43
+ - README.md
44
+ - flickrpu.gemspec
45
+ - lib/flickrpu.rb
46
+ - lib/flickrpu/base.rb
47
+ - lib/flickrpu/version.rb
48
+ - test/flickrpu_test.rb
49
+ homepage: http://github.com/poeks/flickrpu
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '1.2'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.6
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Make S3 objects from Flickr photos.
73
+ test_files: []