davetron5000-gliffy 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -51,6 +51,44 @@ Now you can use the gliffy handle in a controller or a view. Perhaps you'd make
51
51
  :returnButtonText => 'Back to My Awesome Blog'}))
52
52
  end
53
53
 
54
+ It is recommended that you do not expose the Gliffy URLs directly in your views; since each URL can be called one time only and they *must* be called in the order generated, if you were to have, for example, a page with links to images of your Gliffy diagrams, the browser may not request those links in the order that you need.
55
+
56
+ Instead, create a route like so:
57
+
58
+ map.resources :diagrams, :only => [:index,:new,:destroy,:edit,:show]
59
+
60
+ And implement all Gliffy access in your controller methods
61
+
62
+ # diagrams_controller.rb
63
+ class DiagramsController < ApplicationController
64
+
65
+ Mime::Type.register 'image/jpeg', :jpg, [], ["jpeg"]
66
+ Mime::Type.register 'image/png', :png, [], ["png"]
67
+ Mime::Type.register 'image/svg+xml', :svg, [], ["svg"]
68
+
69
+ def index
70
+ @diagrams = self.gliffy_handle.folder_documents(APP_CONFIG['gliffy_folder']).sort{|a,b| a.name <=> b.name}
71
+ end
72
+
73
+ def show
74
+ size = params[:size] || :L
75
+ respond_to do |format|
76
+ format.jpg { send_data session[:gliffy].document_get(params[:id],:jpeg,size), :type => "image/jpeg", :disposition => 'inline' }
77
+ format.png { send_data session[:gliffy].document_get(params[:id],:png,size), :type => "image/png", :disposition => 'inline' }
78
+ format.svg { send_data session[:gliffy].document_get(params[:id],:svg,size), :type => "image/svg+xml", :filename => params[:id] + ".svg" }
79
+ format.xml { send_data session[:gliffy].document_get(params[:id],:xml,size), :type => "text/xml", :filename => params[:id] + ".xml" }
80
+ end
81
+ end
82
+
83
+ # index.html.erb
84
+ <ul>
85
+ <% @diagrams.each do |diagram| %>
86
+ <li><img src="<%= diagram_path(diagram.document_id) %>" /></li>
87
+ <% end %>
88
+ </ul>
89
+
90
+ This way, your application has links to your controller and the requests to Gliffy are constructed as the browser makes requests to your application.
91
+
54
92
  == Digging Deeper
55
93
 
56
94
  If you wish to bypass the high-level API, you can interact with Gliffy directly via the Gliffy::Request class, which allows you to make arbitrary requests against the Gliffy API, but takes care of signing your URLs and all OAuth things that need to be done:
data/bin/gliffy CHANGED
@@ -18,6 +18,9 @@ flag [:config]
18
18
  desc 'Show debug info'
19
19
  switch [:debug]
20
20
 
21
+ desc 'Show version'
22
+ switch :version
23
+
21
24
  #desc 'Use gob-go instead of the real gliffy (devs only)'
22
25
  #switch [:gobgotest]
23
26
 
@@ -261,6 +264,10 @@ command :config do |c|
261
264
  c.desc 'Force a recreation of your config file, even if it exists'
262
265
  c.switch :force
263
266
 
267
+ c.desc 'Forget token (gets a new one next time)'
268
+ c.long_desc 'Sometimes your token can get corrupted or otherwise become unusable. Using this will delete it, forcing a new one to be requested next time.'
269
+ c.switch :forget
270
+
264
271
  c.action do |global_options,options,args|
265
272
  if $config.nil? || options[:force]
266
273
  puts "What is account ID?"
@@ -286,6 +293,10 @@ command :config do |c|
286
293
  else
287
294
  puts "Aborted"
288
295
  end
296
+ elsif options[:forget]
297
+ $config.update_access_token(nil)
298
+ write_config($config,global_options[:config])
299
+ puts "Token deleted; if your next request fails, re-create your config with --force or contact Gliffy"
289
300
  else
290
301
  $stderr.puts "You already have a config; edit it by hand or use --force to recreate"
291
302
  end
@@ -293,44 +304,58 @@ command :config do |c|
293
304
  end
294
305
 
295
306
  pre do |global,command,options,args|
296
- require 'yaml'
297
- message = nil
298
- begin
299
- $config = File.open(global[:config]) { |f| YAML::load(f) }
300
- rescue
301
- message = "No config file found at #{global[:config]}\nUse #{$0} config to create one"
302
- $config = nil
303
- end
304
- if $config.nil? && command.name != :config
305
- $stderr.puts message if !message.nil?
307
+ if global[:version]
308
+ puts "#{$0} v#{Gliffy::GLIFFY_VERSION}"
306
309
  false
307
310
  else
308
- if !command || command.name != :config
309
- if global[:gobgotest]
310
- puts "Going against gob-go -- developers only!"
311
- class HTTPartyAuth
312
- def post(url)
313
- HTTParty.post(url,:basic_auth => {:username => 'gobgotest' , :password => 'gobgotest'})
311
+ require 'yaml'
312
+ message = nil
313
+ begin
314
+ $config = File.open(global[:config]) { |f| YAML::load(f) }
315
+ rescue
316
+ message = "No config file found at #{global[:config]}\nUse #{$0} config to create one"
317
+ $config = nil
318
+ end
319
+ if $config.nil? && command.name != :config
320
+ $stderr.puts message if !message.nil?
321
+ false
322
+ else
323
+ if !command || command.name != :config
324
+ if global[:gobgotest]
325
+ puts "Going against gob-go -- developers only!"
326
+ class HTTPartyAuth
327
+ def post(url)
328
+ HTTParty.post(url,:basic_auth => {:username => 'gobgotest' , :password => 'gobgotest'})
329
+ end
314
330
  end
331
+ $handle = Gliffy::Handle.new(
332
+ 'gob-go-stable.gliffy.com/api/1.0',
333
+ 'gob-go-stable.gliffy.com/gliffy',
334
+ $config,HTTPartyAuth.new)
335
+ else
336
+ $handle = Gliffy::Handle.new(
337
+ 'www.gliffy.com/api/1.0',
338
+ 'www.gliffy.com/gliffy',
339
+ $config)
315
340
  end
316
- $handle = Gliffy::Handle.new(
317
- 'gob-go-stable.gliffy.com/api/1.0',
318
- 'gob-go-stable.gliffy.com/gliffy',
319
- $config,HTTPartyAuth.new)
320
- else
321
- $handle = Gliffy::Handle.new(
322
- 'www.gliffy.com/api/1.0',
323
- 'www.gliffy.com/gliffy',
324
- $config)
341
+ token = $handle.update_token
342
+ $handle.logger.level = Logger::DEBUG if global[:debug]
343
+ write_config($config,global[:config])
325
344
  end
326
- token = $handle.update_token
327
- $handle.logger.level = Logger::DEBUG if global[:debug]
328
- write_config($config,global[:config])
345
+ true
329
346
  end
330
- true
331
347
  end
332
348
  end
333
349
 
350
+ on_error do |ex|
351
+ raise ex
352
+ #if ex.kind_of? Gliffy::BadAuthorizationException
353
+ # puts "Your token is bustedz"
354
+ # false
355
+ #else
356
+ # true
357
+ #end
358
+ end
334
359
  def write_config(cred,config)
335
360
  File.open(config,'w') do |out|
336
361
  YAML.dump(cred,out)
data/lib/gliffy.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'gliffy/handle'
2
+ require 'gliffy/version'
2
3
 
3
4
  # :include: ../README.rdoc
4
5
  module Gliffy
@@ -22,6 +22,12 @@ module Gliffy
22
22
  super(message)
23
23
  end
24
24
  end
25
+
26
+ class BadAuthorizationException < Exception
27
+ def initialize(message)
28
+ super(message)
29
+ end
30
+ end
25
31
  # Base class for all response from gliffy
26
32
  class Response
27
33
  @@normal_error_callback = Proc.new do |response,exception|
@@ -29,10 +35,17 @@ module Gliffy
29
35
  message = response.inspect
30
36
  if response['response'] && response['response']['error']
31
37
  http_status = response['response']['error']['http_status']
32
- if http_status = "404"
33
- message = "Not Found"
38
+ # It seems that HTTParty is not able to figure out the http-status when the contents of
39
+ # the tag is text. Weird. This hack seems to work reasonably well.
40
+ if !http_status
41
+ http_status = response.body.gsub(/^.*http-status=\"/,'').gsub(/\".*$/,'')
42
+ end
43
+ if http_status == '404'
44
+ message = 'Not Found'
45
+ elsif http_status == '401'
46
+ raise BadAuthorizationException.new(response['response']['error'])
34
47
  else
35
- message = "HTTP Status #{http_status}"
48
+ message = "HTTP Status #{http_status} : #{response['response']['error']}"
36
49
  end
37
50
  end
38
51
  raise exception.class.new(message)
@@ -0,0 +1,4 @@
1
+ # Generated by rake update_version
2
+ module Gliffy
3
+ GLIFFY_VERSION = '0.9.4'
4
+ end
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.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Copeland
@@ -57,6 +57,7 @@ files:
57
57
  - lib/gliffy/request.rb
58
58
  - lib/gliffy/response.rb
59
59
  - lib/gliffy/url.rb
60
+ - lib/gliffy/version.rb
60
61
  - lib/gliffy.rb
61
62
  - bin/gliffy
62
63
  - README.rdoc