quickmug 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MmZmMDI1NjdkNDE0NTY3ZDk3YjJjMjIxNTNkODU4ZjEzYzM3MTRlNg==
5
+ data.tar.gz: !binary |-
6
+ ODljMzgwMTY3MDJiMTVkMmZmNjI2NjE0Y2JjYzQzZjZjMGMyMTMyNA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ Nzk0OGZmODIyMzY0NDBhYmI3ZWExODNkZjhjMTM4YmQ4YmZjMTJlZmVjM2M3
10
+ ZDhmMDg3NjI2NmFiZDdmYjMwMmE5YTRkZWYwOGQyOThjMTg1YmYyNzFmZjYy
11
+ MTMwNWMzMmM1Yzg2MjM3OWFmOTE1YzRmYWI2Mjk1OTgwZmUyMTA=
12
+ data.tar.gz: !binary |-
13
+ MTRiYzlhOTI3ZmE5ZjA5Nzc3OGYzNTRhNjVjZGI0NjJlZjdkMzIxNThjNWQ3
14
+ NzVjZWM0OGY5Njk5ZThmYmQzODE2YzkyMWE1MmVjM2M4NDZkZGIzOGVlZDdl
15
+ MTdhOTk4YzcwNDcyMmMwNzc3ZjhlZmJjM2Y0ODBkZmU1NDhkNDY=
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ lib/bundler/man
9
+ pkg
10
+ rdoc
11
+ spec/reports
12
+ test/tmp
13
+ test/version_tmp
14
+ tmp
15
+
16
+ # YARD artifacts
17
+ .yardoc
18
+ _yardoc
19
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in quickmug.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Christopher Giroir
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,81 @@
1
+ # QuickMug
2
+
3
+ I currently use [Jekyll](http://jekyllrb.com/) for
4
+ [my blog](http://mx.kelsin.net) and
5
+ [SmugMug](http://www.smugmug.com/) for hosted images and photos. I created this
6
+ gem to allow myself to easily upload files to SmugMug from the command
7
+ line. QuickMug also puts a string (in the format of my chosing) on my clipboard
8
+ for easy insertion into my blog post. Right now I use a
9
+ [custom liquid tag](https://github.com/Kelsin/mxKelsin/blob/master/_plugins/images.rb)
10
+ that inserts the images using [Bootstrap](http://twitter.github.io/bootstrap/)'s
11
+ thumbnail classes. I use the following format string in order to do this:
12
+
13
+ {% image [ThumbURL] [LargeURL] [Caption] %}
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ gem 'quickmug'
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install quickmug
28
+
29
+ ## Configuation
30
+
31
+ This is a small gem that helps you upload photos to smugmug. It relies on a
32
+ config file `~/.quickmug` that is a yaml document like the following:
33
+
34
+ consumer:
35
+ key: aaa
36
+ secret: bbb
37
+ access:
38
+ token: ccc
39
+ secret: ddd
40
+ album: 123456789
41
+ format: "{% image [ThumbURL] [LargeURL] [Caption] %}"
42
+
43
+ Consumer data is the API app key that you can get by registering an app on
44
+ SmugMug's website. This allows you to use their api.
45
+
46
+ Access data is your personal access token for your user. You can get this using
47
+ oauth. I plan on adding a feature to this gem that helps you get that... but
48
+ it's not in the code yet (sorry).
49
+
50
+ Album is the album id that uploads will go to. You can get a list of albums by
51
+ running `quickmug albums` (as long as you have the consumer and access tokens
52
+ specified).
53
+
54
+ Format is a string that you would like copied to your clipboard after you upload
55
+ an image. Any blocks like `[xxx]` will be replaced with the `xxx` field from the
56
+ smugmug
57
+ [images.getInfo](http://api.smugmug.com/services/api/?version=1.3.0&method=smugmug.images.getInfo)
58
+ call.
59
+
60
+ ## Usage
61
+
62
+ The following commands are available
63
+
64
+ * **albums** List all of your albums (the selected one is starred)
65
+ * **copy ID KEY** If you pass in a image id and key, this copies the format
66
+ string to the clipboard as if you just uploaded that image.
67
+ * **images [options]** Lists the last 5 of the images from your selected album
68
+ using your format string. You can use `-a` to list all images and `-l NUM`
69
+ to list a certain number.
70
+ * **last** Copies the format string for the last image in your album (this is
71
+ often the one you just uploaded).
72
+ * **upload IMAGE CAPTION** Uploads a image file to smugmug with a caption. You
73
+ don't need quotes around the caption.
74
+
75
+ ## Contributing
76
+
77
+ 1. Fork it
78
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
79
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
80
+ 4. Push to the branch (`git push origin my-new-feature`)
81
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/quickmug ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+ STDOUT.sync = true
3
+
4
+ $:.unshift File.join(File.dirname(__FILE__), *%w{ .. lib })
5
+
6
+ require 'commander/import'
7
+ require 'quickmug'
8
+
9
+ program :name, 'quickmug'
10
+ program :version, QuickMug::VERSION
11
+ program :description, QuickMug::DESCRIPTION
12
+
13
+ default_command :help
14
+
15
+ command :upload do |c|
16
+ c.syntax = 'quickmug upload IMAGE CAPTION'
17
+ c.description = 'Uploads an IMAGE to smugmug with a caption of CAPTION'
18
+
19
+ c.action do |args, options|
20
+ QuickMug.copy(QuickMug::Upload.process(args).render)
21
+ end
22
+ end
23
+
24
+ command :copy do |c|
25
+ c.syntax = 'quickmug copy ID KEY'
26
+ c.description = 'Uses your format setting to copy the image information to the clipboard'
27
+
28
+ c.action do |args, options|
29
+ QuickMug.copy(QuickMug::Image.fromArgs(args).render)
30
+ end
31
+ end
32
+
33
+ command :albums do |c|
34
+ c.syntax = 'quickmug albums'
35
+ c.description = 'List your smugmug albums'
36
+
37
+ c.action do |args, options|
38
+ QuickMug::Album.all.each do |album|
39
+ puts album
40
+ end
41
+ end
42
+ end
43
+
44
+ command :last do |c|
45
+ c.syntax = 'quickmug last'
46
+ c.description = 'Copy and show the last image from the selected album'
47
+
48
+ c.action do |args, options|
49
+ QuickMug.copy(QuickMug::Album.selected.images.last)
50
+ end
51
+ end
52
+
53
+ command :images do |c|
54
+ c.syntax = 'quickmug images [options]'
55
+ c.description = 'List images from your selected album'
56
+ c.option '-a','--all', Integer, 'Show all images'
57
+ c.option '-l NUM','--last NUM', Integer, 'Only load the last NUM images (defaults to 5)'
58
+
59
+ c.action do |args, options|
60
+ options.default :last => 5
61
+ images = QuickMug::Album.selected.images
62
+
63
+ if !options.all
64
+ images = images[(-1 * options.last)..-1]
65
+ end
66
+
67
+ images.each do |image|
68
+ puts image
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,52 @@
1
+ module QuickMug
2
+ class Album
3
+ attr_reader :id, :key
4
+
5
+ def initialize(id, key)
6
+ @id = id
7
+ @key = key
8
+ end
9
+
10
+ def apiHash
11
+ {:AlbumID => @id, :AlbumKey => @key}
12
+ end
13
+
14
+ def info
15
+ @info ||= QuickMug.client.albums.getInfo(apiHash)
16
+ end
17
+
18
+ def images
19
+ @images ||= QuickMug.client.images.get(apiHash)['Images'].map do |data|
20
+ Image.fromApi(data)
21
+ end
22
+ end
23
+
24
+ def selected?
25
+ self.id == QuickMug.config['album']
26
+ end
27
+
28
+ def to_s
29
+ selected = selected? ? '*' : ' '
30
+ " #{selected} #{info['Title']} id:#@id key:#@key"
31
+ end
32
+
33
+ def self.fromApi(data)
34
+ Album.new(data['id'], data['Key'])
35
+ end
36
+
37
+ def self.fromArgs(args)
38
+ raise ArgumentError.new('You must specify an image ID and KEY') if args.size < 2
39
+ Album.new(args[0],args[1])
40
+ end
41
+
42
+ def self.all
43
+ @@albums ||= QuickMug.client.albums.get.map do |data|
44
+ Album.fromApi(data)
45
+ end
46
+ end
47
+
48
+ def self.selected
49
+ @@selected ||= self.all.first(&:selected?)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,41 @@
1
+ module QuickMug
2
+ class Image
3
+ attr_reader :id, :key
4
+
5
+ def initialize(id, key)
6
+ @id = id
7
+ @key = key
8
+ end
9
+
10
+ def apiHash
11
+ {:ImageID => @id, :ImageKey => @key}
12
+ end
13
+
14
+ def info
15
+ @info ||= QuickMug.client.images.getInfo(apiHash)
16
+ end
17
+
18
+ def to_s
19
+ render
20
+ end
21
+
22
+ def render
23
+ output = QuickMug.config['format']
24
+
25
+ info.each do |key, value|
26
+ output = output.gsub("[#{key}]", value.to_s)
27
+ end
28
+
29
+ output
30
+ end
31
+
32
+ def self.fromApi(data)
33
+ Image.new(data['id'], data['Key'])
34
+ end
35
+
36
+ def self.fromArgs(args)
37
+ raise ArgumentError.new('You must specify an image ID and KEY') if args.size < 2
38
+ Image.new(args[0],args[1])
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,25 @@
1
+ module QuickMug
2
+ class Upload
3
+ def self.process(args)
4
+ raise ArgumentError.new('You must specify an image') if args.empty?
5
+ image = File.expand_path(args[0])
6
+ caption = args[1..-1].join(' ')
7
+
8
+ raise ArgumentError.new('The specified file does not exist') unless File.exists?(image)
9
+ raise ArgumentError.new('You must specify album in ~/.quickmug') unless QuickMug.config['album']
10
+
11
+ data = {:AlbumID => QuickMug.config['album']}
12
+
13
+ if caption.length > 0
14
+ data[:Caption] = caption
15
+ end
16
+
17
+ File.open(image, "rb") do |f|
18
+ # Upload file to the album
19
+ data = QuickMug.client.upload_media(data.merge(:file => f))
20
+ end
21
+
22
+ Image.fromApi(data)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,4 @@
1
+ module QuickMug
2
+ VERSION = "0.0.3"
3
+ DESCRIPTION = "Easy command line smugmug uploader"
4
+ end
data/lib/quickmug.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'quickmug/version'
2
+
3
+ require 'rubygems'
4
+ require 'oauth'
5
+ require 'safe_yaml'
6
+ require 'ruby-smugmug'
7
+ require 'clipboard'
8
+
9
+ require 'quickmug/upload'
10
+ require 'quickmug/image'
11
+ require 'quickmug/album'
12
+
13
+ module QuickMug
14
+ def self.config
15
+ @@config ||= YAML.safe_load_file(File.expand_path("~/.quickmug"))
16
+ end
17
+
18
+ def self.client
19
+ @@client ||= SmugMug::Client.new(:api_key => config['consumer']['key'],
20
+ :oauth_secret => config['consumer']['secret'],
21
+ :user => {
22
+ :token => config['access']['token'],
23
+ :secret => config['access']['secret']})
24
+ end
25
+
26
+ def self.copy(text)
27
+ puts(text)
28
+ Clipboard.copy(text.to_s)
29
+ end
30
+ end
data/quickmug.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'quickmug/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "quickmug"
8
+ spec.version = QuickMug::VERSION
9
+ spec.authors = ["Christopher Giroir"]
10
+ spec.email = ["kelsin@valefor.com"]
11
+ spec.description = QuickMug::DESCRIPTION
12
+ spec.summary = QuickMug::DESCRIPTION
13
+ spec.homepage = %q{http://github.com/Kelsin/quickmug}
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency('commander', "~> 4.1.3")
22
+ spec.add_runtime_dependency('safe_yaml', "~> 0.7.0")
23
+ spec.add_runtime_dependency('oauth', "~> 0.4.7")
24
+ spec.add_runtime_dependency('ruby-smugmug', "~> 0.0.1")
25
+ spec.add_runtime_dependency('clipboard', "~> 1.0.5")
26
+ spec.add_runtime_dependency('ffi', "~> 1.8.1")
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.3"
29
+ spec.add_development_dependency "rake"
30
+ end
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quickmug
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Christopher Giroir
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: commander
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 4.1.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 4.1.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: safe_yaml
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.7.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.7.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: oauth
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.4.7
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.4.7
55
+ - !ruby/object:Gem::Dependency
56
+ name: ruby-smugmug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 0.0.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: clipboard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 1.0.5
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 1.0.5
83
+ - !ruby/object:Gem::Dependency
84
+ name: ffi
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 1.8.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 1.8.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: bundler
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: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Easy command line smugmug uploader
126
+ email:
127
+ - kelsin@valefor.com
128
+ executables:
129
+ - quickmug
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - Gemfile
135
+ - LICENSE.txt
136
+ - README.md
137
+ - Rakefile
138
+ - bin/quickmug
139
+ - lib/quickmug.rb
140
+ - lib/quickmug/album.rb
141
+ - lib/quickmug/image.rb
142
+ - lib/quickmug/upload.rb
143
+ - lib/quickmug/version.rb
144
+ - quickmug.gemspec
145
+ homepage: http://github.com/Kelsin/quickmug
146
+ licenses:
147
+ - MIT
148
+ metadata: {}
149
+ post_install_message:
150
+ rdoc_options: []
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ! '>='
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ requirements: []
164
+ rubyforge_project:
165
+ rubygems_version: 2.0.3
166
+ signing_key:
167
+ specification_version: 4
168
+ summary: Easy command line smugmug uploader
169
+ test_files: []