davetron5000-gliffy 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/gliffy +20 -13
  2. data/lib/gliffy/handle.rb +11 -0
  3. metadata +1 -1
data/bin/gliffy CHANGED
@@ -168,7 +168,7 @@ command [:view,:get] do |c|
168
168
  c.flag [:s,:size]
169
169
 
170
170
  c.desc 'Version'
171
- c.arg_name 'version number (omit for latest, "1" is the first version)'
171
+ c.arg_name 'version number (1-based)'
172
172
  c.flag [:v,:version]
173
173
 
174
174
  c.desc 'Get the URL only'
@@ -178,30 +178,37 @@ command [:view,:get] do |c|
178
178
  c.long_desc 'This is not strictly documented by the gliffy API, but, for public documents, this URL is more usable, as it can be requested any number of times. The non-public URLs contain signature information that makes them one-time-use only.'
179
179
  c.switch [:p,:publicurl]
180
180
 
181
+ c.desc 'Command to run to open URL for editing in browser'
182
+ c.long_desc 'If defined, this command will be run with the URL for editing given to it. Hopefully, this will pop up Gliffy in your browser.'
183
+ c.default_value RUBY_PLATFORM =~ /^universal-darwin/ ? 'open' : nil
184
+ c.flag [:o,:openwith]
185
+
186
+ c.desc 'Just print the url/filename; don''t try to open it'
187
+ c.switch [:O,:noopen]
188
+
181
189
  c.action do |global_options,options,args|
182
190
  args.each do |document_id|
183
191
  version = options[:v]
184
192
  version_name = ''
185
193
  version_name = "_V#{version}" if version
194
+ opened = false
195
+ location = nil
186
196
  if options[:u]
187
- puts $handle.document_get_url(document_id,options[:t].to_sym,options[:s].to_sym,version)
197
+ location = $handle.document_get_url(document_id,options[:t].to_sym,options[:s].to_sym,version)
188
198
  elsif options[:p]
189
- document = $handle.document_get_metadata(document_id)
190
- if document.is_public?
191
- # This isn't formally documented in the API so we put it here
192
- puts "http://www.gliffy.com/pubdoc/#{document.document_id}/#{options[:s]}.jpg"
193
- else
194
- puts "Document is not public"
195
- puts $handle.document_get_url(document_id,options[:t].to_sym,options[:s].to_sym,version)
196
- end
199
+ location = $handle.document_get_public_url(document_id,options[:s].to_sym)
197
200
  else
198
201
  bytes = $handle.document_get(document_id,options[:t].to_sym,options[:s].to_sym,version)
199
- filename = "#{document_id}_#{options[:s]}#{version_name}.#{options[:t]}"
200
- File.open(filename,'wb') do |f|
202
+ location = "#{document_id}_#{options[:s]}#{version_name}.#{options[:t]}"
203
+ File.open(location,'wb') do |f|
201
204
  f.write(bytes)
202
205
  end
203
- puts "Wrote #{filename}"
204
206
  end
207
+ if options[:o] && !options[:O]
208
+ opened = system "#{options[:o]} \"#{location}\""
209
+ puts "Couldn't run #{options[:o]} to open file/url" if !opened
210
+ end
211
+ puts location if !opened
205
212
  end
206
213
  end
207
214
  end
@@ -159,6 +159,17 @@ module Gliffy
159
159
  end
160
160
  end
161
161
 
162
+ # Gets the public link to the document, which is static
163
+ # and not dependent on the key or authorization.
164
+ # This isn't formally part of the Gliffy API, but is
165
+ # convienient. The document must be public
166
+ # and you can only get it in JPG format.
167
+ # [+document_id+] identifier of the document
168
+ # [+size+] size to show, from biggest to smallest: :L, :M, :S, :T
169
+ def document_get_public_url(document_id,size=:L)
170
+ "http://www.gliffy.com/pubdoc/#{document_id}/#{size.to_s}.jpg"
171
+ end
172
+
162
173
  # Get a link to a document
163
174
  # [+document_id+] identifier of the document
164
175
  # [+type+] document type. Types known to work:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: davetron5000-gliffy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Copeland