davetron5000-gliffy 0.1.7 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +0,0 @@
1
- require 'gliffy/commands/list'
2
- require 'gliffy/commands/delete'
3
- require 'gliffy/commands/url'
4
- require 'gliffy/commands/get'
5
- require 'gliffy/commands/edit'
6
- require 'gliffy/commands/new'
@@ -1,10 +0,0 @@
1
- desc 'Delete a diagram'
2
- arg_name 'diagram_id [diagram_id]*'
3
- command [:delete,:del,:rm] do |c|
4
- c.action do |global_options,options,args|
5
- raise UnknownArgumentException("diagram id is required") if args.length == 0;
6
- args.each do |diagram_id|
7
- $gliffy.delete_diagram(diagram_id)
8
- end
9
- end
10
- end
@@ -1,19 +0,0 @@
1
- desc 'Edit a diagram'
2
- arg_name 'diagram_id'
3
- command :edit do |c|
4
-
5
- c.action do |global_options,options,args|
6
-
7
- raise(UnknownArgumentException,'You must specify one diagram id') if args.length != 1
8
-
9
- return_link = $gliffy.get_diagram_as_url(args[0])
10
- link = $gliffy.get_edit_diagram_link(args[0],return_link,"Done")
11
- if Gliffy::CLIConfig.instance.config[:open_url]
12
- system(sprintf(Gliffy::CLIConfig.instance.config[:open_url],link.full_url))
13
- else
14
- puts "Nothing configured for #{:open_url.to_s} to open the url"
15
- puts link.full_url
16
- end
17
- end
18
- end
19
-
@@ -1,46 +0,0 @@
1
- desc 'Download a diagram as an image to a file'
2
- arg_name 'diagram_id [diagram_id]*'
3
- command :get do |c|
4
-
5
- c.desc 'Get a specific version number'
6
- c.arg_name 'version_number'
7
- c.default_value nil
8
- c.flag [:v,:version]
9
-
10
- c.desc 'Specify the filename'
11
- c.arg_name 'filename'
12
- c.default_value nil
13
- c.flag [:f,:filename]
14
-
15
- c.desc 'Specify the image type (one of jpeg, jpg, png, svg, xml)'
16
- c.arg_name 'type'
17
- c.default_value 'jpg'
18
- c.flag [:t,:type,:"image-type"]
19
-
20
- c.action do |global_options,options,args|
21
-
22
- raise(UnknownArgumentException,'You must specify a diagram id') if args.length == 0
23
- raise(MissingArgumentException,'You may not specify a filename when getting multiple diagrams') if args.length > 1 and options[:f]
24
- args.each do |diagram_id|
25
-
26
- version_number = options[:v]
27
- filename = options[:f]
28
- type = options[:t].to_sym
29
- if !filename
30
- dir = options['d'] || '.'
31
- metadata = $gliffy.get_diagram_metadata(diagram_id)
32
- filename = metadata.name.gsub(/[\s\/\-\+\$]/,'_')
33
- if version_number
34
- filename = "#{dir}/#{filename}_v#{version_number}.#{type.to_s}"
35
- else
36
- filename = "#{dir}/#{filename}.#{type.to_s}"
37
- end
38
- end
39
-
40
- get_options = { :mime_type => type, :file => filename }
41
- get_options[:version] = version_number if version_number
42
- $gliffy.get_diagram_as_image(diagram_id,get_options)
43
- puts filename
44
- end
45
- end
46
- end
@@ -1,27 +0,0 @@
1
- desc 'List all diagrams in the account'
2
- command [:list,:ls] do |c|
3
-
4
- c.desc 'List long form'
5
- c.switch :l
6
-
7
- c.action do |global_options,options,args|
8
- diagrams = $gliffy.get_diagrams
9
- if options[:l]
10
- max = diagrams.inject(0) { |max,diagram| diagram.name.length > max ? diagram.name.length : max }
11
- diagrams.sort.each do |diagram|
12
- printf "%8d %s %-#{max}s %-3d %s %s %s\n",
13
- diagram.id,
14
- diagram.is_public? ? "P" : "-",
15
- diagram.name,
16
- diagram.num_versions,
17
- format_date(diagram.create_date),
18
- format_date(diagram.mod_date),
19
- diagram.owner_username
20
- end
21
- else
22
- printf_string = "%d %s\n"
23
- diagrams.sort.each { |diagram| printf printf_string,diagram.id,diagram.name }
24
- end
25
- end
26
- end
27
-
@@ -1,25 +0,0 @@
1
- desc 'Create a new diagram'
2
- arg_name 'new_diagram_name'
3
- command [:new,:create] do |c|
4
- c.desc 'use the given diagram_id as a template'
5
- c.default_value nil
6
- c.flag [:t,:template]
7
-
8
- c.desc 'don\'t edit the new diagram'
9
- c.switch [:n,:"no-edit"]
10
-
11
- c.action do |global_options,options,args|
12
-
13
- raise(UnknownArgumentException,'You must specify the diagram name') if args.length != 1
14
-
15
- template_id = options[:t]
16
-
17
- diagram = $gliffy.create_diagram(args[0],template_id)
18
- if options[:n]
19
- puts "Diagram #{diagram.name} created with id #{diagram.id}"
20
- else
21
- GLI.run(['edit',diagram.id.to_s])
22
- end
23
- end
24
- end
25
-
@@ -1,21 +0,0 @@
1
- desc 'Get the URL for a diagram as an image image'
2
- arg_name 'diagram_id'
3
- command :url do |c|
4
- c.desc 'Open URL with configured :open_url command'
5
- c.switch [:o,:open]
6
- c.action do |global_options,options,args|
7
- raise UnknownArgumentException,"diagram id is required" if args.length == 0
8
- raise UnknownArgumentException,"Only one diagram id is supported" if args.length > 1
9
- url = $gliffy.get_diagram_as_url(args[0])
10
- if options[:o]
11
- if Gliffy::CLIConfig.instance.config[:open_image]
12
- system(sprintf(Gliffy::CLIConfig.instance.config[:open_image],url))
13
- else
14
- puts "Nothing configured for #{:open_image.to_s} to open the image"
15
- puts url
16
- end
17
- else
18
- puts url
19
- end
20
- end
21
- end
@@ -1,55 +0,0 @@
1
- require 'logger'
2
-
3
- module Gliffy
4
-
5
- # Global Configuration for Gliffy. This is a singleton currently and can be accessed
6
- # via the config class method
7
- #
8
- # * You mostly need to set api_key, secret_key and account_name
9
- # * You may wish to set protocol if you have a premium account and wish to use https
10
- class Config
11
-
12
- # A Logger level to control logging
13
- attr_accessor :log_level
14
- # The log device (as passed to Logger) for where log messages should go
15
- attr_accessor :log_device
16
- # The protocol, either 'http' or 'https' (though feel free to try 'gopher:' :)
17
- attr_accessor :protocol
18
- # The gliffy app root, which is pretty much www.gliffy.com/gliffy unless you know a secret
19
- attr_accessor :gliffy_app_root
20
- # The url relative to gliffy_app_root of where the API is accessed
21
- attr_accessor :gliffy_rest_context
22
- # Your API Key
23
- attr_accessor :api_key
24
- # Your Secret Key
25
- attr_accessor :secret_key
26
- # The name of your account
27
- attr_accessor :account_name
28
-
29
- @@instance=nil
30
-
31
- def initialize
32
- @log_level = Logger::DEBUG
33
- @log_device = STDERR
34
- @protocol = 'http'
35
- @gliffy_app_root = 'www.gliffy.com/gliffy';
36
- @gliffy_rest_context = 'rest'
37
- @api_key = 'no api key specified'
38
- @secret_key = 'no secret key specified'
39
- @account_name = 'no account name specified'
40
- end
41
-
42
- # Returns the entire URL to the gliffy api root. This uses protocol, gliffy_app_root
43
- # and gliffy_rest_context, so you should not really override this
44
- def gliffy_root
45
- "#{protocol}://#{gliffy_app_root}/#{gliffy_rest_context}"
46
- end
47
-
48
- def self.config=(config); @@instance = config; end
49
- def self.config
50
- @@instance = Config.new if !@@instance
51
- @@instance
52
- end
53
- end
54
- end
55
-
@@ -1,100 +0,0 @@
1
- require 'rexml/document'
2
- require 'array_has_response'
3
- require 'gliffy/rest'
4
-
5
- include REXML
6
-
7
- module Gliffy
8
-
9
- # A gliffy diagram (or, rather, the meta data about that diagram)
10
- class Diagram < Response
11
-
12
- attr_reader :id
13
- attr_reader :num_versions
14
- attr_reader :name
15
- # The username of the proper owner of this diagram
16
- attr_reader :owner_username
17
- # A Time representing the date on which this diagram was created
18
- attr_reader :create_date
19
- # A Time representing the date on which this diagram was last modified
20
- attr_reader :mod_date
21
- # A Time representing the date on which this diagram was published,
22
- # or nil if it was not published
23
- attr_reader :published_date
24
-
25
- def self.from_xml(element)
26
- id = element.attributes['id'].to_i
27
- num_versions = element.attributes['num-versions'].to_i
28
- is_private = element.attributes['is-private'] == "true"
29
- is_public = element.attributes['is-public'] == "true"
30
-
31
- create_date = Time.at(element.elements['create-date'].text.to_i / 1000)
32
- mod_date = Time.at(element.elements['mod-date'].text.to_i / 1000)
33
- published_date = element.elements['published-date'] ? Time.at(element.elements['published-date'].text.to_i / 1000) : nil
34
- name = element.elements['name'].text
35
- owner_username = element.elements['owner'] ? element.elements['owner'].text : nil
36
-
37
- Diagram.new(id,name,owner_username,is_public,is_private,num_versions,create_date,mod_date,published_date)
38
- end
39
-
40
- # True if this diagram is public
41
- def is_public?
42
- @is_public
43
- end
44
-
45
- # True if this diagram is private (and available only
46
- # to the owner and account administrators)
47
- def is_private?
48
- @is_private
49
- end
50
-
51
- # sorts by diagram name
52
- def <=>(other_diagram)
53
- name <=> other_diagram.name
54
- end
55
-
56
- protected
57
- def initialize(id,name,owner_username,is_public,is_private,num_versions,create_date,mod_date,published_date)
58
- super()
59
- @id = id
60
- @name = name
61
- @owner_username = owner_username
62
- @is_public = is_public
63
- @is_private = is_private
64
- @num_versions = num_versions
65
- @create_date = create_date
66
- @mod_date = mod_date
67
- @published_date = published_date
68
- end
69
-
70
- end
71
-
72
- # A link to edit a specific gliffy diagram
73
- class LaunchLink < Response
74
-
75
- # The name of the diagram, which can helpful
76
- # in creating HTML hyperlinks to url
77
- attr_reader :diagram_name
78
- attr_reader :url
79
-
80
- def self.from_xml(element)
81
- diagram_name = element.attributes['diagram-name']
82
- url = element.text
83
- LaunchLink.new(diagram_name,url)
84
- end
85
-
86
- def full_url
87
- Gliffy::Config.config.protocol + "://" + Gliffy::Config.config.gliffy_app_root + url
88
- end
89
-
90
- protected
91
-
92
- def initialize(name,url)
93
- super()
94
- @diagram_name = name
95
- @url = url
96
- end
97
- end
98
-
99
- class Diagrams < ArrayResponseParser; end
100
- end
@@ -1,63 +0,0 @@
1
- require 'rexml/document'
2
- require 'array_has_response'
3
- require 'gliffy/rest'
4
-
5
- include REXML
6
-
7
- module Gliffy
8
-
9
- class Folders < ArrayResponseParser; end
10
-
11
- class Folder < Response
12
-
13
- # An array of Folder objects that are contained within this folder
14
- # If this is empty, it means this Folder is a leaf
15
- attr_reader :child_folders
16
- attr_reader :id
17
- attr_reader :name
18
- # The full path to this folder within the account's
19
- # folder hierarchy
20
- attr_reader :path
21
-
22
- def self.from_xml(element)
23
- id = element.attributes['id'].to_i
24
- default = element.attributes['is-default'] == "true"
25
- name = element.elements['name'].text
26
- path = element.elements['path'].text
27
- child_folders = Array.new
28
- element.each_element do |element|
29
- child_folders << Folder.from_xml(element) if element.name == "folder"
30
- end
31
- Folder.new(id,name,default,path,child_folders)
32
- end
33
-
34
- # Returns true if this folder is the default folder
35
- # used when an operation requiring a folder
36
- # doesn't specify one (such as when creating a new
37
- # diagram)
38
- def default?
39
- @default
40
- end
41
-
42
- # Encodes the elements of a folder path so it can safely go into a URL
43
- def self.encode_path_elements(folder_path)
44
- encoded = ''
45
- folder_path.split(/\//).each do |part|
46
- encoded += CGI::escape(part)
47
- encoded += "/"
48
- end
49
- encoded.gsub(/\/$/,'')
50
- end
51
-
52
- protected
53
-
54
- def initialize(id,name,default,path,child_folders)
55
- super()
56
- @id = id
57
- @name = name
58
- @default = default
59
- @path = path
60
- @child_folders = child_folders
61
- end
62
- end
63
- end
@@ -1,110 +0,0 @@
1
- require 'digest/md5'
2
- require 'cgi'
3
- require 'rubygems'
4
- require 'request_errors'
5
- require 'resource'
6
- require 'rest_client'
7
-
8
- require 'gliffy/config'
9
- require 'gliffy/url'
10
-
11
- require 'logger'
12
-
13
- module Gliffy
14
-
15
- # Provides REST access to Gliffy, handling the signing of the requests
16
- # but not the parsing of the results. This class responds to the four primary HTTP methods:
17
- #
18
- # * get
19
- # * put
20
- # * post
21
- # * delete
22
- #
23
- # Each method takes three parameters:
24
- # [url] - the relative URL being requested
25
- # [params] - a hash of parameters to include in the request (these are specific to the request, not things like apiKey or token)
26
- # [headers] - any HTTP headers you want to set
27
- #
28
- # params and headers are optional. These methods return whatever Gliffy sent back. The context
29
- # of the request should be used to determine the type, however it should be relatively safe to call
30
- # Response#success? on whatever is returned to determine if everythign was OK
31
- #
32
- class Rest
33
-
34
- # Provides access to the current token,
35
- # returning nil if none has been set
36
- attr_accessor :current_token
37
-
38
- # Provides access to the logger
39
- # Do not set this to nil
40
- attr_accessor :logger
41
-
42
- attr_accessor :rest_client
43
-
44
- # Create an accessor to the Gliffy REST api
45
- #
46
- def initialize
47
- @current_token = nil
48
- self.rest_client=RestClient
49
- @logger = Logger.new(Config.config.log_device)
50
- @logger.level = Config.config.log_level
51
-
52
- @logger.debug("Creating #{self.class.to_s} with api_key of #{Config.config.api_key} against #{Config.config.gliffy_root}")
53
- end
54
-
55
- # Returns the complete URL that would be requested for
56
- # the given URL and parameters
57
- #
58
- # [url] the URL, relative to the Gliffy API Root
59
- # [params] a hash of parameters
60
- #
61
- def get_url(url,params=nil)
62
- return create_url(url,params)
63
- end
64
-
65
- # Implements the http methods
66
- def method_missing(symbol,*args)
67
- if HTTP_METHODS[symbol] && (args.length > 0)
68
- url,params,headers = args
69
- make_rest_request(symbol,url,params,headers)
70
- else
71
- if (HTTP_METHODS[symbol])
72
- raise ArgumentError.new("Wrong number of arguments for method #{symbol.to_s}")
73
- else
74
- super.method_missing(symbol,*args)
75
- end
76
- end
77
- end
78
-
79
- # Create the URL that would be needed to access the given resource with the given
80
- # parameters
81
- #
82
- # [+url+] url, relative to the gliffy root, to retrieve
83
- # [+params+] optional hash of parameters
84
- #
85
- def create_url(url,params=nil)
86
- url = SignedURL.new(Config.config.api_key,Config.config.secret_key,Config.config.gliffy_root,url)
87
- url.params=params if params
88
- url['token'] = @current_token.token if @current_token
89
-
90
- url.full_url
91
- end
92
-
93
- protected
94
-
95
- def make_rest_request(method,url,params,headers)
96
- headers = Hash.new if !headers
97
- request_url = create_url(url,params)
98
- @logger.debug("#{method.to_s.upcase} #{request_url}")
99
- @rest_client.send(method,request_url,headers)
100
- end
101
-
102
- HTTP_METHODS = {
103
- :get => true,
104
- :put => true,
105
- :delete => true,
106
- :post => true,
107
- };
108
-
109
- end
110
- end