gliffy 0.0.6 → 0.0.7
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.
- checksums.yaml +15 -0
- data/LICENSE +20 -0
- data/README.md +30 -11
- data/lib/gliffy.rb +37 -33
- data/lib/gliffy/account.rb +59 -59
- data/lib/gliffy/api.rb +89 -89
- data/lib/gliffy/api/error.rb +14 -0
- data/lib/gliffy/api/facade.rb +72 -4
- data/lib/gliffy/api/response.rb +4 -0
- data/lib/gliffy/document.rb +103 -69
- data/lib/gliffy/document/presentation.rb +27 -0
- data/lib/gliffy/{document_png.rb → document/presentation/png.rb} +2 -26
- data/lib/gliffy/document/presentation/svg.rb +10 -0
- data/lib/gliffy/document/presentation/xml.rb +10 -0
- data/lib/gliffy/folder.rb +91 -71
- data/spec/fixtures/error-401.xml +1 -0
- data/spec/lib/gliffy/account_spec.rb +107 -107
- data/spec/lib/gliffy/api/error_spec.rb +35 -0
- data/spec/lib/gliffy/api/facade_spec.rb +222 -93
- data/spec/lib/gliffy/api/response_spec.rb +46 -29
- data/spec/lib/gliffy/api_spec.rb +206 -206
- data/spec/lib/gliffy/{document_png_spec.rb → document/presentation/png_spec.rb} +10 -11
- data/spec/lib/gliffy/document/presentation/svg_spec.rb +38 -0
- data/spec/lib/gliffy/document/presentation/xml_spec.rb +38 -0
- data/spec/lib/gliffy/document/presentation_spec.rb +8 -0
- data/spec/lib/gliffy/document_spec.rb +179 -108
- data/spec/lib/gliffy/folder_spec.rb +224 -175
- data/spec/spec_helper.rb +39 -35
- data/spec/support/document_presentation_shared_examples.rb +6 -0
- metadata +34 -24
data/lib/gliffy/api/facade.rb
CHANGED
@@ -10,19 +10,31 @@ module Gliffy
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def raw(partial_url, params = {})
|
13
|
-
|
13
|
+
api.raw(api_root + partial_url, params)
|
14
14
|
end
|
15
15
|
|
16
16
|
def get(partial_url, params)
|
17
|
-
|
17
|
+
response = api.get(api_root + partial_url, params)
|
18
|
+
|
19
|
+
if response.error?
|
20
|
+
handle_error response
|
21
|
+
end
|
22
|
+
|
23
|
+
response
|
18
24
|
end
|
19
25
|
|
20
26
|
def post(partial_url, params)
|
21
|
-
|
27
|
+
response = api.post(api_root + partial_url, params)
|
28
|
+
|
29
|
+
if response.error?
|
30
|
+
handle_error response
|
31
|
+
end
|
32
|
+
|
33
|
+
response
|
22
34
|
end
|
23
35
|
|
24
36
|
def web(partial_url, params)
|
25
|
-
|
37
|
+
api.web(web_root + partial_url, params)
|
26
38
|
end
|
27
39
|
|
28
40
|
def get_folders(account_id)
|
@@ -30,8 +42,64 @@ module Gliffy
|
|
30
42
|
:action => 'get')
|
31
43
|
end
|
32
44
|
|
45
|
+
def update_document_metadata(document_id, name, shared)
|
46
|
+
params = {
|
47
|
+
:action => "update",
|
48
|
+
}
|
49
|
+
|
50
|
+
if not name.nil?
|
51
|
+
params[:documentName] = name
|
52
|
+
end
|
53
|
+
|
54
|
+
if not shared.nil?
|
55
|
+
params[:public] = shared ? "true" : "false"
|
56
|
+
end
|
57
|
+
|
58
|
+
post("/accounts/#{account_id}/documents/#{document_id}/meta-data.xml",
|
59
|
+
params)
|
60
|
+
end
|
61
|
+
|
62
|
+
def delete_document(document_id)
|
63
|
+
post("/accounts/#{account_id}/documents/#{document_id}.xml",
|
64
|
+
:action => "delete")
|
65
|
+
end
|
66
|
+
|
67
|
+
def create_document(name, type, original_id, path)
|
68
|
+
params = {
|
69
|
+
:action => "create",
|
70
|
+
:documentName => name,
|
71
|
+
:documentType => type
|
72
|
+
}
|
73
|
+
|
74
|
+
if not original_id.nil?
|
75
|
+
params[:templateDiagramId] = original_id
|
76
|
+
end
|
77
|
+
|
78
|
+
if not path.nil?
|
79
|
+
params[:folderPath] = path
|
80
|
+
end
|
81
|
+
|
82
|
+
post("/accounts/#{account_id}/documents.xml",
|
83
|
+
params)
|
84
|
+
end
|
85
|
+
|
33
86
|
private
|
34
87
|
|
88
|
+
def handle_error(response)
|
89
|
+
code = response.integer("//g:response/g:error/@http-status")
|
90
|
+
text = response.string("//g:response/g:error/text()")
|
91
|
+
|
92
|
+
raise Gliffy::API::Error.new(code, text)
|
93
|
+
end
|
94
|
+
|
95
|
+
def api
|
96
|
+
@api
|
97
|
+
end
|
98
|
+
|
99
|
+
def account_id
|
100
|
+
api.account_id
|
101
|
+
end
|
102
|
+
|
35
103
|
def initialize(protocol, api)
|
36
104
|
@protocol = protocol
|
37
105
|
@api = api
|
data/lib/gliffy/api/response.rb
CHANGED
data/lib/gliffy/document.rb
CHANGED
@@ -1,69 +1,103 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
1
|
+
require "observer"
|
2
|
+
|
3
|
+
module Gliffy
|
4
|
+
class Document
|
5
|
+
include Observable
|
6
|
+
|
7
|
+
TYPE_DIAGRAM = "diagram"
|
8
|
+
|
9
|
+
attr_reader :owner
|
10
|
+
attr_reader :id
|
11
|
+
attr_reader :is_public
|
12
|
+
attr_reader :versions
|
13
|
+
attr_reader :name
|
14
|
+
attr_reader :modified, :created, :published
|
15
|
+
|
16
|
+
def self.load(owner, node)
|
17
|
+
@loaded ||= {}
|
18
|
+
|
19
|
+
id = node.integer('@id')
|
20
|
+
if not @loaded.has_key? id then
|
21
|
+
@loaded[id] = Gliffy::Document.new(
|
22
|
+
owner,
|
23
|
+
id,
|
24
|
+
:is_public => node.exists('@is-public'),
|
25
|
+
:versions => node.integer('@num-versions'),
|
26
|
+
:name => node.string('g:name'),
|
27
|
+
:modified => node.timestamp('g:mod-date'),
|
28
|
+
:created => node.timestamp('g:create-date'),
|
29
|
+
:published => node.timestamp('g:published-date')
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
@loaded[id]
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.clear_cache
|
37
|
+
@loaded = {}
|
38
|
+
end
|
39
|
+
|
40
|
+
def rename(new_name)
|
41
|
+
@name = new_name
|
42
|
+
|
43
|
+
api.update_document_metadata(id, new_name, nil)
|
44
|
+
end
|
45
|
+
|
46
|
+
def delete
|
47
|
+
api.delete_document(id)
|
48
|
+
@is_deleted = true
|
49
|
+
|
50
|
+
changed
|
51
|
+
notify_observers :delete, self
|
52
|
+
end
|
53
|
+
|
54
|
+
def deleted?
|
55
|
+
@is_deleted
|
56
|
+
end
|
57
|
+
|
58
|
+
def editor(return_url, return_text)
|
59
|
+
api.web(
|
60
|
+
"/gliffy/",
|
61
|
+
:launchDiagramId => id,
|
62
|
+
:returnURL => return_url,
|
63
|
+
:returnButtonText => return_text
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
def svg
|
68
|
+
Document::Presentation::SVG.new(self)
|
69
|
+
end
|
70
|
+
|
71
|
+
def xml
|
72
|
+
Document::Presentation::XML.new(self)
|
73
|
+
end
|
74
|
+
|
75
|
+
def png
|
76
|
+
Document::Presentation::PNG.new(self)
|
77
|
+
end
|
78
|
+
|
79
|
+
def public?
|
80
|
+
is_public
|
81
|
+
end
|
82
|
+
|
83
|
+
def api
|
84
|
+
owner.api
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def initialize(owner, id, params)
|
90
|
+
@owner = owner
|
91
|
+
@id = id
|
92
|
+
|
93
|
+
@is_public = params[:is_public]
|
94
|
+
@versions = params[:versions]
|
95
|
+
@name = params[:name]
|
96
|
+
@modified = params[:modified]
|
97
|
+
@created = params[:created]
|
98
|
+
@published = params[:published]
|
99
|
+
|
100
|
+
@is_deleted = false
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Gliffy
|
2
|
+
class Document::Presentation
|
3
|
+
attr_reader :document
|
4
|
+
|
5
|
+
def initialize(document)
|
6
|
+
@document = document
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def api
|
12
|
+
document.api
|
13
|
+
end
|
14
|
+
|
15
|
+
def account
|
16
|
+
document.owner
|
17
|
+
end
|
18
|
+
|
19
|
+
def document_id
|
20
|
+
document.id
|
21
|
+
end
|
22
|
+
|
23
|
+
def account_id
|
24
|
+
account.id
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,16 +1,10 @@
|
|
1
1
|
module Gliffy
|
2
|
-
class Document::PNG
|
3
|
-
attr_reader :document
|
4
|
-
|
2
|
+
class Document::Presentation::PNG < Document::Presentation
|
5
3
|
SIZE_THUMBNAIL = "T"
|
6
4
|
SIZE_SMALL = "S"
|
7
5
|
SIZE_MEDIUM = "M"
|
8
6
|
SIZE_FULL = "L"
|
9
7
|
|
10
|
-
def initialize(document)
|
11
|
-
@document = document
|
12
|
-
end
|
13
|
-
|
14
8
|
def content(size)
|
15
9
|
api.raw(
|
16
10
|
"/accounts/#{account_id}/documents/#{document_id}.png",
|
@@ -34,23 +28,5 @@ module Gliffy
|
|
34
28
|
def full
|
35
29
|
content(SIZE_FULL)
|
36
30
|
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def api
|
41
|
-
document.api
|
42
|
-
end
|
43
|
-
|
44
|
-
def account
|
45
|
-
document.owner
|
46
|
-
end
|
47
|
-
|
48
|
-
def document_id
|
49
|
-
document.id
|
50
|
-
end
|
51
|
-
|
52
|
-
def account_id
|
53
|
-
account.id
|
54
|
-
end
|
55
31
|
end
|
56
|
-
end
|
32
|
+
end
|
data/lib/gliffy/folder.rb
CHANGED
@@ -1,71 +1,91 @@
|
|
1
|
-
require 'uri'
|
2
|
-
|
3
|
-
module Gliffy
|
4
|
-
class Folder
|
5
|
-
attr_reader :name, :path
|
6
|
-
attr_reader :owner, :parent
|
7
|
-
attr_reader :folders
|
8
|
-
|
9
|
-
def self.load(owner, node)
|
10
|
-
Gliffy::Folder.new(
|
11
|
-
owner,
|
12
|
-
node.string('g:name'),
|
13
|
-
node.string('g:path'),
|
14
|
-
node.nodes('g:folder').map {|n| Gliffy::Folder.load(owner, n)}
|
15
|
-
)
|
16
|
-
end
|
17
|
-
|
18
|
-
def initialize(owner, name, path, folders)
|
19
|
-
@owner = owner
|
20
|
-
@name = name
|
21
|
-
@path = path
|
22
|
-
|
23
|
-
@folders = folders
|
24
|
-
@folders.each do |f|
|
25
|
-
f.parent = self
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def parent=(parent)
|
30
|
-
if path != parent.path + "/" + name then
|
31
|
-
raise "Invalid parent"
|
32
|
-
end
|
33
|
-
|
34
|
-
@parent = parent
|
35
|
-
end
|
36
|
-
|
37
|
-
def
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
def
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module Gliffy
|
4
|
+
class Folder
|
5
|
+
attr_reader :name, :path
|
6
|
+
attr_reader :owner, :parent
|
7
|
+
attr_reader :folders
|
8
|
+
|
9
|
+
def self.load(owner, node)
|
10
|
+
Gliffy::Folder.new(
|
11
|
+
owner,
|
12
|
+
node.string('g:name'),
|
13
|
+
node.string('g:path'),
|
14
|
+
node.nodes('g:folder').map {|n| Gliffy::Folder.load(owner, n)}
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(owner, name, path, folders)
|
19
|
+
@owner = owner
|
20
|
+
@name = name
|
21
|
+
@path = path
|
22
|
+
|
23
|
+
@folders = folders
|
24
|
+
@folders.each do |f|
|
25
|
+
f.parent = self
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def parent=(parent)
|
30
|
+
if path != parent.path + "/" + name then
|
31
|
+
raise "Invalid parent"
|
32
|
+
end
|
33
|
+
|
34
|
+
@parent = parent
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_document(name)
|
38
|
+
api.create_document(name, Gliffy::Document::TYPE_DIAGRAM, nil, path)
|
39
|
+
end
|
40
|
+
|
41
|
+
def documents
|
42
|
+
@documents ||= load_documents
|
43
|
+
end
|
44
|
+
|
45
|
+
def root?
|
46
|
+
path == "ROOT"
|
47
|
+
end
|
48
|
+
|
49
|
+
# observer callback
|
50
|
+
def update(event, target)
|
51
|
+
case event
|
52
|
+
when :delete
|
53
|
+
@documents = @documents.delete_if { |element| element == target }
|
54
|
+
else
|
55
|
+
raise ArgumentError.new(event)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def api
|
62
|
+
owner.api
|
63
|
+
end
|
64
|
+
|
65
|
+
def account_id
|
66
|
+
owner.id
|
67
|
+
end
|
68
|
+
|
69
|
+
def escaped_path
|
70
|
+
path.gsub(' ', '+')
|
71
|
+
end
|
72
|
+
|
73
|
+
def load_documents
|
74
|
+
# Path is alphanumeric + spaces and '/'. Spaces should be
|
75
|
+
# escaped; slashes should NOT be escaped.
|
76
|
+
url = "/accounts/#{account_id}/folders/#{escaped_path}/documents.xml"
|
77
|
+
response = api.get(url,
|
78
|
+
:action => "get")
|
79
|
+
|
80
|
+
response
|
81
|
+
.nodes('//g:document')
|
82
|
+
.map { |n| load_document n }
|
83
|
+
end
|
84
|
+
|
85
|
+
def load_document(n)
|
86
|
+
document = Gliffy::Document.load(owner, n)
|
87
|
+
document.add_observer(self)
|
88
|
+
document
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|