A “handle” to access Gliffy on a per-user-session basis Since most calls to gliffy require a user-token, this class encapsulates that token and the calls made under it.
- A
- D
- F
- N
- U
ROOT_FOLDER | = | 'ROOT' |
[R] | logger | Get access to the logger (useful for controlling log messages) |
[R] | request | Get access to the Request (useful for hacking or testing) |
[R] | token | Get access to the current token (useful for caching to disk) |
[W] | error_callback | Use this to override what happens when an error from Gliffy is received. The default (or nil) is to raise the exception that was generated. If you want to override this provide a block that takes the response that was received (which will be a hash-like object from HTTParty, possibly nil) and the exception that was generated (the message of which will have been parsed from Gliffy’s XML if that was possible): # If we got an HTTParty response, try to print out the body and the Gliffy message # Otherwise, barf handle.response = Proc.new do |response,exception| if response && response.respond_to? :body puts exception.to_str puts response.body else raise exception end end |
Create a new handle to Gliffy
- api_root
- root URL (without the protocol) of where to connect to Gliffy
- edit_api_root
- root URL (without the protocol) of where to connect to Gliffy for the edit link only
- credentials
- a Credentials object to use for access
- http
- override of http access class (use at your own risk; must be substituable for HTTPart)
- logger
- logger instance, if you don’t want the default
# File lib/gliffy/handle.rb, line 46 def initialize(api_root,edit_api_root,credentials,http=nil,logger=nil) @credentials = credentials @request = Request.new(api_root,credentials) @edit_link_request = Request.new(edit_api_root,credentials) @request.http = http if !http.nil? @logger = logger || Logger.new(STDOUT) @logger.level = Logger::INFO @request.logger = @logger if !@credentials.has_access_token? update_token end @error_callback = nil end
Get admins of your account. Returns users
Returns all documents in the account
- show
- if nil, all documents are returned; if :public only public are returned.
Returns all folders in the account
Returns account meta data
- show_users
- if true, include the list of users in this account
Get users in your account
Delete the current token
Create a new document
- name
- Name of the new document
- folder_path
- Path in which to place the document initially (nil to use default)
- template_id
- document id of a document to copy when initializing this new document (nil to make a blank one)
- type
- If Gliffy ever supports other document types, use this
Returns a document representing the document that was created.
# File lib/gliffy/handle.rb, line 118 def document_create(name,folder_path=nil,template_id=nil,type=:diagram) params = { :documentName => name, :documentType => type } params[:templateDiagramId] = template_id if !template_id.nil? params[:folderPath] = normalize_folder_path(folder_path) if !folder_path.nil? documents = make_request(:create,"#{account_url}/documents.xml",params) return nil if documents.nil? documents[0] end
Delete an existing document
Get the link to edit a document
Get a document; returning the actual bytes
- document_id
- identifier of the document
- type
- document type. Types known to work:
- :jpeg
- - JPEG
- :png
- - PNG
- :svg
- - SVG (for Visio import)
- :xml
- - Gliffy proprietary XML format (for archiving)
- size
- size to show, from biggest to smallest: :L, :M, :S, :T
- version
- The version to get, or nil to get the most recent
# File lib/gliffy/handle.rb, line 151 def document_get(document_id,type=:jpeg,size=:L,version=nil) params = { :size => size } params[:version] = version if !version.nil? response = make_request(:get,document_url(document_id,type),params,false) if (type == :xml) || (type == :svg) response.body else response end end
Get meta-data about a document.
- document_id
- identifier of the document
- show_revisions
- if true, include info about the documents’ revision history
Gets the public link to the document, which is static and not dependent on the key or authorization. This isn’t formally part of the Gliffy API, but is convienient. The document must be public and you can only get it in JPG format.
- document_id
- identifier of the document
- size
- size to show, from biggest to smallest: :L, :M, :S, :T
Get a link to a document
- document_id
- identifier of the document
- type
- document type. Types known to work:
- :jpg
- - JPEG
- :png
- - PNG
- :svg
- - SVG (for Visio import)
- :xml
- - Gliffy proprietary XML format (for archiving)
- size
- size to show, from biggest to smallest: :L, :M, :S, :T
- version
- The version to get, or nil to get the most recent
Move a document to a different folder
Update a document’s meta-data or content
- document_id
- identifier of document to update
- options
- data to update; omission of an option will not change it
- :name
- change the name
- :public
- if false, will remove public statues, if true, will make public
- :content
- if present, should be the gliffy XML content to update (don’t use this unless it’s crucial)
# File lib/gliffy/handle.rb, line 208 def document_update(document_id,options) if (options[:content]) make_request(:update,document_url(document_id),{:content => options[:content]}) end if (options[:name] || options[:public]) params = {} params[:documentName] = options[:name] if options[:name] params[:public] = options[:public] if options[:public] make_request(:update,document_metadata_url(document_id),params) end end
Add a user to a folder
Create a new folder
- path
- the path to the folder, each path separated by a forward slash. If this starts with a forward slash it will attempt to make folder with the exact given path. This will probably fail. If this DOESN’T start with a slash, this will make the folder inside ROOT, which is what you want. So, don’t start this with a slash.
Delete a folder
- path
- the path to the folder. See folder_create.
Get the documents in a folder
- path
- the path to the folder whose documents to get
Remove a user from access to the folder
Get users with access to the folder
- path
- the path to the folder whose users to get
Updates the token being used if there isn’t one in the credentials, or by forcing
- force
- always attempt to update the token
# File lib/gliffy/handle.rb, line 63 def update_token(force=false) if !@credentials.has_access_token? || force @logger.debug("Requesting new token " + (force ? " by force " : " since we have none ")) response = @request.create(token_url, :description => @credentials.description, :protocol_override => :https) @token = Response.from_http_response(response) @credentials.update_access_token(@token) end end
Create a new user
- username
- the name to give this user
Delete an existing user
Get the documents a user has access to (this is potentially expensive, as it results in multiple calls to gliffy)
- username
- if provided, get documents for the given username, otherwise get them for the logged-in user
Get the folders a user has access to
- username
- if provided, get folders for the given username, otherwise get them for the logged-in user
Update a user’s meta-data
- username
- the username to operate on
- options
- the options for updating their info. Any omitted option will not change
that value on the server.
- sets their email address
- :password
- sets their password for logging into gliffy.com
- :admin
- if true, sets them to be an admin; if false, revokes their admin privs