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
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><response success="false" xmlns="http://www.gliffy.com"><error http-status="401">Your account has reached its maximum number of diagrams</error></response>
|
@@ -1,107 +1,107 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Gliffy::Account do
|
4
|
-
let(:account_id) { 101 }
|
5
|
-
let(:expiration) { 32154788584000 }
|
6
|
-
let(:api) do
|
7
|
-
api = double(Gliffy::API)
|
8
|
-
api.stub(
|
9
|
-
:get_folders
|
10
|
-
).and_return(
|
11
|
-
Gliffy::API::Response.new(fixture("folder"))
|
12
|
-
)
|
13
|
-
api
|
14
|
-
end
|
15
|
-
|
16
|
-
let(:account) do
|
17
|
-
response = Gliffy::API::Response.new(
|
18
|
-
fixture(
|
19
|
-
"account",
|
20
|
-
:account_id => account_id,
|
21
|
-
:expiration => expiration
|
22
|
-
)
|
23
|
-
)
|
24
|
-
Gliffy::Account.load(api, response)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "has an id" do
|
28
|
-
expect(account).to respond_to :id
|
29
|
-
expect(account.id).to eq account_id
|
30
|
-
end
|
31
|
-
|
32
|
-
it "has a name" do
|
33
|
-
expect(account).to respond_to :name
|
34
|
-
expect(account.name).to eq "BurnsODyne"
|
35
|
-
end
|
36
|
-
|
37
|
-
it "has max users count" do
|
38
|
-
expect(account).to respond_to :max_users
|
39
|
-
expect(account.max_users).to eq 10
|
40
|
-
end
|
41
|
-
|
42
|
-
it "has a type" do
|
43
|
-
expect(account).to respond_to :type
|
44
|
-
expect(account.type).to eq Gliffy::Account::TYPE_BUSINESS
|
45
|
-
end
|
46
|
-
|
47
|
-
it "has 'terms accepted' flag" do
|
48
|
-
expect(account).to respond_to :terms_accepted
|
49
|
-
expect(account.terms_accepted).to be_true
|
50
|
-
end
|
51
|
-
|
52
|
-
it "has an expiration date" do
|
53
|
-
expect(account).to respond_to :expiration_date
|
54
|
-
expect(account.expiration_date).to eq Time.at(expiration / 1000).to_datetime
|
55
|
-
end
|
56
|
-
|
57
|
-
it "provides direct access to documents" do
|
58
|
-
expect(account).to respond_to :document
|
59
|
-
end
|
60
|
-
|
61
|
-
it "delegates task of fetching the document to API" do
|
62
|
-
document_id = 1011
|
63
|
-
document_name = "NAME"
|
64
|
-
|
65
|
-
document_fixture = fixture(
|
66
|
-
"document",
|
67
|
-
:document_id => document_id,
|
68
|
-
:document_name => document_name
|
69
|
-
)
|
70
|
-
|
71
|
-
api.should_receive(
|
72
|
-
:get
|
73
|
-
).with(
|
74
|
-
"/accounts/#{account_id}/documents/#{document_id}/meta-data.xml",
|
75
|
-
hash_including(
|
76
|
-
:action => 'get'
|
77
|
-
)
|
78
|
-
).and_return(Gliffy::API::Response.new(document_fixture))
|
79
|
-
|
80
|
-
document = account.document(document_id)
|
81
|
-
|
82
|
-
expect(document.id).to eq document_id
|
83
|
-
expect(document.name).to eq document_name
|
84
|
-
expect(document.owner).to be account
|
85
|
-
end
|
86
|
-
|
87
|
-
it "has a root folder" do
|
88
|
-
expect(account).to respond_to :root
|
89
|
-
expect(account.root).to be_instance_of Gliffy::Folder
|
90
|
-
end
|
91
|
-
|
92
|
-
describe "root folder" do
|
93
|
-
subject(:root_folder) { account.root }
|
94
|
-
|
95
|
-
it "is named ROOT" do
|
96
|
-
expect(root_folder.name).to eq "ROOT"
|
97
|
-
end
|
98
|
-
|
99
|
-
it "has ROOT path" do
|
100
|
-
expect(root_folder.path).to eq "ROOT"
|
101
|
-
end
|
102
|
-
|
103
|
-
it "refers to the original account as owner" do
|
104
|
-
expect(root_folder.owner).to be account
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gliffy::Account do
|
4
|
+
let(:account_id) { 101 }
|
5
|
+
let(:expiration) { 32154788584000 }
|
6
|
+
let(:api) do
|
7
|
+
api = double(Gliffy::API)
|
8
|
+
api.stub(
|
9
|
+
:get_folders
|
10
|
+
).and_return(
|
11
|
+
Gliffy::API::Response.new(fixture("folder"))
|
12
|
+
)
|
13
|
+
api
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:account) do
|
17
|
+
response = Gliffy::API::Response.new(
|
18
|
+
fixture(
|
19
|
+
"account",
|
20
|
+
:account_id => account_id,
|
21
|
+
:expiration => expiration
|
22
|
+
)
|
23
|
+
)
|
24
|
+
Gliffy::Account.load(api, response)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "has an id" do
|
28
|
+
expect(account).to respond_to :id
|
29
|
+
expect(account.id).to eq account_id
|
30
|
+
end
|
31
|
+
|
32
|
+
it "has a name" do
|
33
|
+
expect(account).to respond_to :name
|
34
|
+
expect(account.name).to eq "BurnsODyne"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "has max users count" do
|
38
|
+
expect(account).to respond_to :max_users
|
39
|
+
expect(account.max_users).to eq 10
|
40
|
+
end
|
41
|
+
|
42
|
+
it "has a type" do
|
43
|
+
expect(account).to respond_to :type
|
44
|
+
expect(account.type).to eq Gliffy::Account::TYPE_BUSINESS
|
45
|
+
end
|
46
|
+
|
47
|
+
it "has 'terms accepted' flag" do
|
48
|
+
expect(account).to respond_to :terms_accepted
|
49
|
+
expect(account.terms_accepted).to be_true
|
50
|
+
end
|
51
|
+
|
52
|
+
it "has an expiration date" do
|
53
|
+
expect(account).to respond_to :expiration_date
|
54
|
+
expect(account.expiration_date).to eq Time.at(expiration / 1000).to_datetime
|
55
|
+
end
|
56
|
+
|
57
|
+
it "provides direct access to documents" do
|
58
|
+
expect(account).to respond_to :document
|
59
|
+
end
|
60
|
+
|
61
|
+
it "delegates task of fetching the document to API" do
|
62
|
+
document_id = 1011
|
63
|
+
document_name = "NAME"
|
64
|
+
|
65
|
+
document_fixture = fixture(
|
66
|
+
"document",
|
67
|
+
:document_id => document_id,
|
68
|
+
:document_name => document_name
|
69
|
+
)
|
70
|
+
|
71
|
+
api.should_receive(
|
72
|
+
:get
|
73
|
+
).with(
|
74
|
+
"/accounts/#{account_id}/documents/#{document_id}/meta-data.xml",
|
75
|
+
hash_including(
|
76
|
+
:action => 'get'
|
77
|
+
)
|
78
|
+
).and_return(Gliffy::API::Response.new(document_fixture))
|
79
|
+
|
80
|
+
document = account.document(document_id)
|
81
|
+
|
82
|
+
expect(document.id).to eq document_id
|
83
|
+
expect(document.name).to eq document_name
|
84
|
+
expect(document.owner).to be account
|
85
|
+
end
|
86
|
+
|
87
|
+
it "has a root folder" do
|
88
|
+
expect(account).to respond_to :root
|
89
|
+
expect(account.root).to be_instance_of Gliffy::Folder
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "root folder" do
|
93
|
+
subject(:root_folder) { account.root }
|
94
|
+
|
95
|
+
it "is named ROOT" do
|
96
|
+
expect(root_folder.name).to eq "ROOT"
|
97
|
+
end
|
98
|
+
|
99
|
+
it "has ROOT path" do
|
100
|
+
expect(root_folder.path).to eq "ROOT"
|
101
|
+
end
|
102
|
+
|
103
|
+
it "refers to the original account as owner" do
|
104
|
+
expect(root_folder.owner).to be account
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gliffy::API::Error do
|
4
|
+
let(:code) { 401 }
|
5
|
+
let(:text) { "ERROR" }
|
6
|
+
let(:error) { Gliffy::API::Error.new(code, text) }
|
7
|
+
|
8
|
+
it "is an exception" do
|
9
|
+
expect(error).to be_a_kind_of Exception
|
10
|
+
end
|
11
|
+
|
12
|
+
it "has an error code" do
|
13
|
+
expect(error).to respond_to :code
|
14
|
+
end
|
15
|
+
|
16
|
+
it "has an error text" do
|
17
|
+
expect(error).to respond_to :text
|
18
|
+
end
|
19
|
+
|
20
|
+
it "can be implicitly converted to string" do
|
21
|
+
expect(error).to respond_to :to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "string representation" do
|
25
|
+
subject(:message) { error.to_s }
|
26
|
+
|
27
|
+
it "should contain error code" do
|
28
|
+
expect(message).to match error.code.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should contain error text" do
|
32
|
+
expect(message).to match error.text
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,111 +1,240 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
shared_examples_for "an API facade" do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context "when sending POST request" do
|
18
|
-
it "forwards request to the API backend with HTTP protocol" do
|
19
|
-
api.should_receive(
|
20
|
-
:post
|
21
|
-
).with(
|
22
|
-
match(url_matcher),
|
23
|
-
hash_including(params)
|
24
|
-
).and_return(response)
|
25
|
-
|
26
|
-
expect(facade.post("/test", params)).to be response
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context "when GETting raw resource contents" do
|
31
|
-
it "forwards request to the API backend with HTTP protocol" do
|
32
|
-
api.should_receive(
|
33
|
-
:raw
|
34
|
-
).with(
|
35
|
-
match(url_matcher),
|
36
|
-
hash_including(params)
|
37
|
-
).and_return(response)
|
38
|
-
|
39
|
-
expect(facade.raw("/test", params)).to be response
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context "when generating web link" do
|
44
|
-
it "forwards request to the API backend with HTTP protocol" do
|
45
|
-
api.should_receive(
|
46
|
-
:web
|
47
|
-
).with(
|
48
|
-
match(url_matcher),
|
49
|
-
hash_including(params)
|
50
|
-
).and_return(response)
|
51
|
-
|
52
|
-
expect(facade.web("/test", params)).to be response
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "when loading a list of folders" do
|
57
|
-
it "wraps own 'get' method" do
|
58
|
-
account_id = 99
|
59
|
-
|
60
|
-
facade.should_receive(
|
61
|
-
:get
|
62
|
-
).with(
|
63
|
-
"/accounts/#{account_id}/folders.xml",
|
64
|
-
{ :action => "get"}
|
65
|
-
).and_return(response)
|
66
|
-
|
67
|
-
expect(facade.get_folders(account_id)).to be response
|
68
|
-
end
|
4
|
+
context "when sending GET request" do
|
5
|
+
it "forwards request to the API backend with HTTP protocol" do
|
6
|
+
api.should_receive(
|
7
|
+
:get
|
8
|
+
).with(
|
9
|
+
match(url_matcher),
|
10
|
+
hash_including(params)
|
11
|
+
).and_return(response)
|
12
|
+
|
13
|
+
expect(facade.get("/test", params)).to be response
|
69
14
|
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when sending POST request" do
|
18
|
+
it "forwards request to the API backend with HTTP protocol" do
|
19
|
+
api.should_receive(
|
20
|
+
:post
|
21
|
+
).with(
|
22
|
+
match(url_matcher),
|
23
|
+
hash_including(params)
|
24
|
+
).and_return(response)
|
25
|
+
|
26
|
+
expect(facade.post("/test", params)).to be response
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when GETting raw resource contents" do
|
31
|
+
it "forwards request to the API backend with HTTP protocol" do
|
32
|
+
api.should_receive(
|
33
|
+
:raw
|
34
|
+
).with(
|
35
|
+
match(url_matcher),
|
36
|
+
hash_including(params)
|
37
|
+
).and_return(response)
|
38
|
+
|
39
|
+
expect(facade.raw("/test", params)).to be response
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when generating web link" do
|
44
|
+
it "forwards request to the API backend with HTTP protocol" do
|
45
|
+
api.should_receive(
|
46
|
+
:web
|
47
|
+
).with(
|
48
|
+
match(url_matcher),
|
49
|
+
hash_including(params)
|
50
|
+
).and_return(response)
|
51
|
+
|
52
|
+
expect(facade.web("/test", params)).to be response
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when loading a list of folders" do
|
57
|
+
it "wraps own 'get' method" do
|
58
|
+
account_id = 99
|
59
|
+
|
60
|
+
facade.should_receive(
|
61
|
+
:get
|
62
|
+
).with(
|
63
|
+
"/accounts/#{account_id}/folders.xml",
|
64
|
+
{ :action => "get"}
|
65
|
+
).and_return(response)
|
66
|
+
|
67
|
+
expect(facade.get_folders(account_id)).to be response
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "when updating document metadata" do
|
72
|
+
let(:document_id) { 221 }
|
73
|
+
let(:document_name) { "NEW DOCUMENT" }
|
74
|
+
let(:public_flag) { true }
|
75
|
+
let(:public_text) { "true" }
|
76
|
+
|
77
|
+
it "sends POST request" do
|
78
|
+
facade
|
79
|
+
.should_receive(:post)
|
80
|
+
.with("/accounts/#{account_id}/documents/#{document_id}/meta-data.xml",
|
81
|
+
hash_including(:action => "update",
|
82
|
+
:documentName => document_name,
|
83
|
+
:public => public_text))
|
84
|
+
|
85
|
+
facade.update_document_metadata(document_id, document_name, public_flag)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "doesn't send name if no name is passed to the method" do
|
89
|
+
facade
|
90
|
+
.should_receive(:post)
|
91
|
+
.with(anything(),
|
92
|
+
hash_not_including(:documentName))
|
93
|
+
|
94
|
+
facade.update_document_metadata(document_id, nil, public_flag)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "doesn't send public flag if it is not passed to the method" do
|
98
|
+
facade
|
99
|
+
.should_receive(:post)
|
100
|
+
.with(anything(),
|
101
|
+
hash_not_including(:public))
|
102
|
+
|
103
|
+
facade.update_document_metadata(document_id, document_name, nil)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
it "allows user to delete a document" do
|
108
|
+
expect(facade).to respond_to :delete_document
|
109
|
+
end
|
110
|
+
|
111
|
+
context "when deleting a document" do
|
112
|
+
let(:document_id) { 221 }
|
113
|
+
|
114
|
+
it "sends POST request" do
|
115
|
+
facade
|
116
|
+
.should_receive(:post)
|
117
|
+
.with("/accounts/#{account_id}/documents/#{document_id}.xml",
|
118
|
+
hash_including(:action => "delete"))
|
119
|
+
|
120
|
+
facade.delete_document(document_id)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
it "allows user to create a document" do
|
125
|
+
expect(facade).to respond_to :create_document
|
126
|
+
end
|
127
|
+
|
128
|
+
context "when creating a document" do
|
129
|
+
let(:document_name) { "NAME" }
|
130
|
+
let(:document_type) { Gliffy::Document::TYPE_DIAGRAM }
|
131
|
+
let(:original_id) { 45 }
|
132
|
+
let(:path) { "ROOT/FOLDER" }
|
133
|
+
|
134
|
+
it "sends POST request" do
|
135
|
+
facade.should_receive(:post)
|
136
|
+
.with("/accounts/#{account_id}/documents.xml",
|
137
|
+
hash_including(:action => "create",
|
138
|
+
:documentName => document_name,
|
139
|
+
:documentType => document_type,
|
140
|
+
:templateDiagramId => original_id,
|
141
|
+
:folderPath => path))
|
142
|
+
|
143
|
+
facade.create_document(document_name, document_type, original_id, path)
|
144
|
+
end
|
145
|
+
|
146
|
+
context "when template id is not provided" do
|
147
|
+
it "doesn't send template id" do
|
148
|
+
facade.should_receive(:post)
|
149
|
+
.with(anything(),
|
150
|
+
hash_not_including(:templateDiagramId))
|
151
|
+
|
152
|
+
facade.create_document(document_name, document_type, nil, path)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context "when path is not provided" do
|
157
|
+
it "doesn't send path" do
|
158
|
+
facade.should_receive(:post)
|
159
|
+
.with(anything(),
|
160
|
+
hash_not_including(:folderPath))
|
161
|
+
|
162
|
+
facade.create_document(document_name, document_type, original_id, nil)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
context "when POST request returns an error" do
|
168
|
+
let(:response) { Gliffy::API::Response.new(fixture("error-401")) }
|
169
|
+
|
170
|
+
before :each do
|
171
|
+
api.stub(
|
172
|
+
:post
|
173
|
+
).and_return(
|
174
|
+
response
|
175
|
+
)
|
176
|
+
end
|
177
|
+
|
178
|
+
it "throws an exception" do
|
179
|
+
expect { facade.post("/random_url", {}) }.to raise_error(Gliffy::API::Error)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context "when GET request returns an error" do
|
184
|
+
let(:response) { Gliffy::API::Response.new(fixture("error-401")) }
|
185
|
+
|
186
|
+
before :each do
|
187
|
+
api.stub(
|
188
|
+
:get
|
189
|
+
).and_return(
|
190
|
+
response
|
191
|
+
)
|
192
|
+
end
|
193
|
+
|
194
|
+
it "throws an exception" do
|
195
|
+
expect { facade.get("/random_url", {}) }.to raise_error(Gliffy::API::Error)
|
196
|
+
end
|
197
|
+
end
|
70
198
|
end
|
71
199
|
|
72
200
|
describe Gliffy::API::Facade do
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
201
|
+
let(:account_id) { 99 }
|
202
|
+
let(:api) { double(Gliffy::API, { :account_id => account_id }) }
|
203
|
+
let(:response) { double(Gliffy::API::Response, :error? => false) }
|
204
|
+
let(:params) {
|
205
|
+
{
|
206
|
+
:test1 => "value1",
|
207
|
+
:test2 => "value2"
|
80
208
|
}
|
209
|
+
}
|
81
210
|
|
82
|
-
|
83
|
-
|
211
|
+
describe "plain facade" do
|
212
|
+
let(:facade) { Gliffy::API::Facade.http(api) }
|
84
213
|
|
85
|
-
|
86
|
-
|
87
|
-
end
|
214
|
+
it_should_behave_like "an API facade" do
|
215
|
+
let(:url_matcher) { %{http://.+/test} }
|
88
216
|
end
|
217
|
+
end
|
89
218
|
|
90
|
-
|
91
|
-
|
219
|
+
describe "secure facade" do
|
220
|
+
let(:facade) { Gliffy::API::Facade.https(api) }
|
92
221
|
|
93
|
-
|
94
|
-
|
95
|
-
end
|
222
|
+
it_should_behave_like "an API facade" do
|
223
|
+
let(:url_matcher) { %{https://.+/test} }
|
96
224
|
end
|
225
|
+
end
|
97
226
|
|
98
|
-
|
99
|
-
|
227
|
+
describe "static methods" do
|
228
|
+
subject { Gliffy::API::Facade }
|
100
229
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
230
|
+
it "provide access to API via basic HTTP protocol" do
|
231
|
+
expect(subject).to respond_to :http
|
232
|
+
expect(subject.http(api)).to be_instance_of Gliffy::API::Facade
|
233
|
+
end
|
105
234
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
end
|
235
|
+
it "provide access to API via secure HTTPS protocol" do
|
236
|
+
expect(subject).to respond_to :https
|
237
|
+
expect(subject.https(api)).to be_instance_of Gliffy::API::Facade
|
110
238
|
end
|
111
|
-
end
|
239
|
+
end
|
240
|
+
end
|