flickr-store 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .flickr-*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in flickr-store.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Ryan LeFevre
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # flickr-store
2
+
3
+ Store arbitrary data with your 1TB Flickr cloud drive by encoding any file as a PNG. This is mostly a proof of concept right now. Don't do anything beyond tinkering with it yet.
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ $ gem install flickr-store
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ First, you will need to register a Flickr application [through their dev site](http://www.flickr.com/services/apps/create/). Once that is done, you can login by running:
14
+
15
+ ```
16
+ flickr-authenticate
17
+ ```
18
+
19
+ Once you complete authentication, you can now use flickr-store:
20
+
21
+ ```
22
+ flickr-store put [file]
23
+ flickr-store get [file] [output path]
24
+ ```
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require './lib/flickr-store'
4
+
5
+ CREDS_FILE = './.flickr-credentials'
6
+ if File.exists?(CREDS_FILE)
7
+ creds = Marshal.load(File.read(CREDS_FILE))
8
+ print "Credentials: "
9
+ pp creds
10
+ puts "Delete #{CREDS_FILE} if you would like to reauthenticate"
11
+ exit
12
+ end
13
+
14
+ print "API Key: "
15
+ api_key = gets.strip
16
+
17
+ print "API Secret: "
18
+ secret = gets.strip
19
+
20
+ f = Flickr::Store.authenticate(api_key, secret)
21
+ creds = {
22
+ api_key: api_key,
23
+ shared_secret: secret,
24
+ access_token: f.access_token,
25
+ access_secret: f.access_secret
26
+ }
27
+
28
+ creds_file = File.new(CREDS_FILE, 'w')
29
+ creds_file.write Marshal.dump(creds)
30
+
31
+ puts "Credentials saved!"
32
+ pp creds
data/bin/flickr-store ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require './lib/flickr-store'
4
+
5
+ CREDS_FILE = './.flickr-credentials'
6
+ if !File.exists?(CREDS_FILE)
7
+ puts "Please login using flickr-authenticate first!"
8
+ exit
9
+ elsif ARGV.size < 2
10
+ puts "Please specify an action and file to store"
11
+ exit
12
+ end
13
+
14
+ creds = Marshal.load(File.read(CREDS_FILE))
15
+ f = Flickr::Store.new(creds[:api_key], creds[:shared_secret], creds[:access_token], creds[:access_secret])
16
+
17
+ if ARGV[0].downcase == "put"
18
+ f.upload ARGV[1]
19
+ elsif ARGV[0].downcase == "get"
20
+ f.fetch ARGV[1], ARGV[2]
21
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'flickr-store/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "flickr-store"
8
+ gem.version = Flickr::Store::VERSION
9
+ gem.authors = ["Ryan LeFevre"]
10
+ gem.email = ["meltingice8917@gmail.com"]
11
+ gem.description = %q{Store arbitrary data with your 1TB Flickr cloud drive.}
12
+ gem.summary = %q{Store arbitrary data with your 1TB Flickr cloud drive by encoding any file as a PNG. This is mostly a proof of concept right now. Don't do anything beyond tinkering with it yet.}
13
+ gem.homepage = "http://github.com/meltingice/flickr-store"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "png-encode"
21
+ gem.add_dependency "flickraw"
22
+ end
@@ -0,0 +1,5 @@
1
+ module Flickr
2
+ class Store
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,102 @@
1
+ ROOT = File.dirname(File.absolute_path(__FILE__))
2
+
3
+ require ROOT + "/flickr-store/version"
4
+
5
+ require 'securerandom'
6
+ require 'tempfile'
7
+ require 'open-uri'
8
+ require 'fileutils'
9
+ require "png-encode"
10
+ require "flickraw"
11
+
12
+ FlickRaw.secure = true
13
+
14
+ module Flickr
15
+ class Store
16
+ def self.authenticate(key, secret)
17
+ FlickRaw.api_key = key
18
+ FlickRaw.shared_secret = secret
19
+
20
+ token = flickr.get_request_token
21
+ auth_url = flickr.get_authorize_url(token['oauth_token'], perms: 'delete')
22
+
23
+ `open #{auth_url}`
24
+ puts "Visit this URL in your browser: #{auth_url}"
25
+ puts "Paste the number given after logging in:"
26
+ verify = gets.strip
27
+
28
+ begin
29
+ flickr.get_access_token(token['oauth_token'], token['oauth_token_secret'], verify)
30
+ login = flickr.test.login
31
+
32
+ puts "Authentication complete! Logged in as #{login.username}."
33
+ rescue FlickRaw::FailedRepsonse => e
34
+ puts "Authentication failed: #{e.msg}"
35
+ end
36
+
37
+ self.new(key, secret, flickr.access_token, flickr.access_secret)
38
+ end
39
+
40
+ def initialize(key, secret, access_token, access_secret)
41
+ FlickRaw.api_key = key
42
+ FlickRaw.shared_secret = secret
43
+ flickr.access_token = access_token
44
+ flickr.access_secret = access_secret
45
+
46
+ if File.exists?('./.flickr-store')
47
+ begin
48
+ @dict = Marshal.load File.read('./.flickr-store')
49
+ rescue
50
+ FileUtils.touch('./.flickr-store')
51
+ @dict = {}
52
+ end
53
+ else
54
+ FileUtils.touch('./.flickr-store')
55
+ @dict = {}
56
+ end
57
+ end
58
+
59
+ [:access_token, :access_secret].each do |meth|
60
+ define_method meth do
61
+ flickr.send(meth)
62
+ end
63
+ end
64
+
65
+ def upload(file)
66
+ original_file = File.new(file, 'r')
67
+ outfile = Tempfile.new(SecureRandom.hex)
68
+ encoded_file = PNG.encode(original_file, outfile)
69
+
70
+ id = flickr.upload_photo encoded_file, title: File.basename(original_file.path)
71
+
72
+ outfile.close!
73
+ outfile.unlink
74
+
75
+ @dict[File.realpath(original_file.path)] = id
76
+ update_dict!
77
+ end
78
+
79
+ def fetch(name, outfile)
80
+ path = File.realpath(name)
81
+ id = @dict[path]
82
+ sizes = flickr.photos.getSizes(photo_id: id)
83
+ image = sizes.select { |s| s['label'].downcase == 'original' }.first
84
+ url = image['source']
85
+
86
+ file = Tempfile.new(SecureRandom.hex)
87
+ file.write open(url).read
88
+ file.flush
89
+
90
+ PNG.decode(file, outfile)
91
+
92
+ file.close!
93
+ file.unlink
94
+ end
95
+
96
+ private
97
+
98
+ def update_dict!
99
+ File.write "./.flickr-store", Marshal.dump(@dict)
100
+ end
101
+ end
102
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flickr-store
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan LeFevre
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: png-encode
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: flickraw
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Store arbitrary data with your 1TB Flickr cloud drive.
47
+ email:
48
+ - meltingice8917@gmail.com
49
+ executables:
50
+ - flickr-authenticate
51
+ - flickr-store
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - Gemfile
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
60
+ - bin/flickr-authenticate
61
+ - bin/flickr-store
62
+ - flickr-store.gemspec
63
+ - lib/flickr-store.rb
64
+ - lib/flickr-store/version.rb
65
+ homepage: http://github.com/meltingice/flickr-store
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.23
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Store arbitrary data with your 1TB Flickr cloud drive by encoding any file
89
+ as a PNG. This is mostly a proof of concept right now. Don't do anything beyond
90
+ tinkering with it yet.
91
+ test_files: []
92
+ has_rdoc: