gliffy 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MTk3NDU4YmY2MTdmMTk1MTM4YTE5MmZhOGUwYjg3MzE2ZmI5NzYxNg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZGJhY2Y5ZGFiMGEzMmU5NmIyOGU4NjI0M2NlZWQ3NjZhNWFkMzlkNA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZTBiYjRhOTVmZjgwYTVhY2JlZmFlNzYyMDRlYmE5YTJkZWE1NTNlZjMwYmNj
|
10
|
+
ZDE1NGM1OGM1YTIwNjZkZjFjMjU3MzQ1ZTg0YzEyYTVhYTVjOTI3Yjg1NGM2
|
11
|
+
MTJmYzhkZTg2ZjE1ODUyMDI2YzIwOTgwYmQ5YWMxMWYyNzViMWI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OTJhZTQ2NTZkNTc1MGJjOWM1N2JjNDQ0ZDY3MzI5N2E2ZjdjN2NmNjg3NWVj
|
14
|
+
MzlmMTBlZGYwNDA5ODE5ZjUzMDEzYTI1ZDRjYWE1MWNiMjdiYTY0OTc2ODkw
|
15
|
+
NDI0NTlkZjBmODYyZWVhYjM0ZmU2YmJmNjk0NTJiMDY4N2Q3MzU=
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) [year] [fullname]
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -6,20 +6,39 @@ Basic usage
|
|
6
6
|
|
7
7
|
### Initialization
|
8
8
|
|
9
|
-
api = Gliffy::API.new(ACCOUNT_ID, API_KEY, API_SECRET)
|
10
|
-
api.impersonate('user@domain.com')
|
11
|
-
api.account.root.documents
|
9
|
+
api = Gliffy::API.new(ACCOUNT_ID, API_KEY, API_SECRET)
|
10
|
+
api.impersonate('user@domain.com')
|
11
|
+
api.account.root.documents
|
12
12
|
|
13
13
|
### Working with documents
|
14
14
|
|
15
|
-
doc = account.document(DOCUMENT_ID)
|
16
|
-
|
17
|
-
doc.
|
18
|
-
doc.
|
15
|
+
doc = account.document(DOCUMENT_ID)
|
16
|
+
|
17
|
+
doc.name
|
18
|
+
doc.rename("NEW NAME")
|
19
|
+
|
20
|
+
doc.editor(RETURN_TO, RETURN_BUTTON_TEXT)
|
21
|
+
|
22
|
+
doc.delete
|
23
|
+
|
24
|
+
#### Download document as PNG
|
25
|
+
|
26
|
+
doc.png.full
|
27
|
+
doc.png.medium
|
28
|
+
doc.png.small
|
29
|
+
doc.png.thumbnail
|
30
|
+
|
31
|
+
#### Download document as SVG
|
32
|
+
|
33
|
+
doc.svg.content
|
34
|
+
|
35
|
+
#### Download document as XML
|
36
|
+
|
37
|
+
doc.xml.content
|
19
38
|
|
20
39
|
### Navigating folders
|
21
40
|
|
22
|
-
root = account.root
|
23
|
-
root.folders[0].documents
|
24
|
-
root.folders[1].name
|
25
|
-
root.folders[1].path
|
41
|
+
root = account.root
|
42
|
+
root.folders[0].documents
|
43
|
+
root.folders[1].name
|
44
|
+
root.folders[1].path
|
data/lib/gliffy.rb
CHANGED
@@ -1,33 +1,37 @@
|
|
1
|
-
require 'date'
|
2
|
-
|
3
|
-
require 'gliffy/api'
|
4
|
-
require 'gliffy/api/
|
5
|
-
require 'gliffy/api/
|
6
|
-
require 'gliffy/
|
7
|
-
require 'gliffy/
|
8
|
-
require 'gliffy/
|
9
|
-
require 'gliffy/
|
10
|
-
|
11
|
-
require 'gliffy/
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
#
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
require 'gliffy/api'
|
4
|
+
require 'gliffy/api/error'
|
5
|
+
require 'gliffy/api/facade'
|
6
|
+
require 'gliffy/api/response'
|
7
|
+
require 'gliffy/account'
|
8
|
+
require 'gliffy/document'
|
9
|
+
require 'gliffy/document/presentation'
|
10
|
+
require 'gliffy/document/presentation/png'
|
11
|
+
require 'gliffy/document/presentation/svg'
|
12
|
+
require 'gliffy/document/presentation/xml'
|
13
|
+
require 'gliffy/folder'
|
14
|
+
|
15
|
+
require 'gliffy/oauth/helper'
|
16
|
+
|
17
|
+
module Gliffy
|
18
|
+
class << self
|
19
|
+
def default_application_name
|
20
|
+
"Gliffy Ruby Gem"
|
21
|
+
end
|
22
|
+
|
23
|
+
# some calls (e.g. OAuth token generation) should be done through
|
24
|
+
# secure HTTPS; other calls (e.g. actions performed by
|
25
|
+
# non-privileged accounts) should be done though plain HTTP
|
26
|
+
#
|
27
|
+
# We're using protocol-relative URL here.
|
28
|
+
def api_root
|
29
|
+
'//www.gliffy.com/api/1.0'
|
30
|
+
end
|
31
|
+
|
32
|
+
# We're using protocol-relative (//hosrname/path/ format) URL here.
|
33
|
+
def web_root
|
34
|
+
'//www.gliffy.com'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/gliffy/account.rb
CHANGED
@@ -1,59 +1,59 @@
|
|
1
|
-
module Gliffy
|
2
|
-
class Account
|
3
|
-
TYPE_BUSINESS = "Business"
|
4
|
-
|
5
|
-
attr_reader :api
|
6
|
-
attr_reader :id
|
7
|
-
attr_reader :name
|
8
|
-
attr_reader :max_users, :type, :terms_accepted
|
9
|
-
attr_reader :expiration_date
|
10
|
-
|
11
|
-
def self.load(api, response)
|
12
|
-
Gliffy::Account.new(
|
13
|
-
api,
|
14
|
-
:id => response.integer('//g:account/@id'),
|
15
|
-
:name => response.string('//g:account/g:name'),
|
16
|
-
:max_users => response.integer('//g:account/@max-users'),
|
17
|
-
:type => response.string('//g:account/@account-type'),
|
18
|
-
:terms_accepted => response.string('//g:account/@terms') == "true",
|
19
|
-
:expiration_date => response.timestamp('//g:account/g:expiration-date')
|
20
|
-
)
|
21
|
-
end
|
22
|
-
|
23
|
-
def root
|
24
|
-
@root ||= load_root
|
25
|
-
end
|
26
|
-
|
27
|
-
def document(document_id)
|
28
|
-
response = api.get("/accounts/#{id}/documents/#{document_id}/meta-data.xml",
|
29
|
-
:action => 'get')
|
30
|
-
|
31
|
-
Gliffy::Document.load(
|
32
|
-
self,
|
33
|
-
response.node('//g:document')
|
34
|
-
)
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def initialize(api, params)
|
40
|
-
@api = api
|
41
|
-
|
42
|
-
@id = params[:id]
|
43
|
-
@name = params[:name]
|
44
|
-
@max_users = params[:max_users]
|
45
|
-
@type = params[:type]
|
46
|
-
@terms_accepted = params[:terms_accepted]
|
47
|
-
@expiration_date = params[:expiration_date]
|
48
|
-
end
|
49
|
-
|
50
|
-
def load_root
|
51
|
-
response = api.get_folders(id)
|
52
|
-
|
53
|
-
Gliffy::Folder.load(
|
54
|
-
self,
|
55
|
-
response.node("/g:response/g:folders/g:folder")
|
56
|
-
)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
1
|
+
module Gliffy
|
2
|
+
class Account
|
3
|
+
TYPE_BUSINESS = "Business"
|
4
|
+
|
5
|
+
attr_reader :api
|
6
|
+
attr_reader :id
|
7
|
+
attr_reader :name
|
8
|
+
attr_reader :max_users, :type, :terms_accepted
|
9
|
+
attr_reader :expiration_date
|
10
|
+
|
11
|
+
def self.load(api, response)
|
12
|
+
Gliffy::Account.new(
|
13
|
+
api,
|
14
|
+
:id => response.integer('//g:account/@id'),
|
15
|
+
:name => response.string('//g:account/g:name'),
|
16
|
+
:max_users => response.integer('//g:account/@max-users'),
|
17
|
+
:type => response.string('//g:account/@account-type'),
|
18
|
+
:terms_accepted => response.string('//g:account/@terms') == "true",
|
19
|
+
:expiration_date => response.timestamp('//g:account/g:expiration-date')
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def root
|
24
|
+
@root ||= load_root
|
25
|
+
end
|
26
|
+
|
27
|
+
def document(document_id)
|
28
|
+
response = api.get("/accounts/#{id}/documents/#{document_id}/meta-data.xml",
|
29
|
+
:action => 'get')
|
30
|
+
|
31
|
+
Gliffy::Document.load(
|
32
|
+
self,
|
33
|
+
response.node('//g:document')
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def initialize(api, params)
|
40
|
+
@api = api
|
41
|
+
|
42
|
+
@id = params[:id]
|
43
|
+
@name = params[:name]
|
44
|
+
@max_users = params[:max_users]
|
45
|
+
@type = params[:type]
|
46
|
+
@terms_accepted = params[:terms_accepted]
|
47
|
+
@expiration_date = params[:expiration_date]
|
48
|
+
end
|
49
|
+
|
50
|
+
def load_root
|
51
|
+
response = api.get_folders(id)
|
52
|
+
|
53
|
+
Gliffy::Folder.load(
|
54
|
+
self,
|
55
|
+
response.node("/g:response/g:folders/g:folder")
|
56
|
+
)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/gliffy/api.rb
CHANGED
@@ -1,89 +1,89 @@
|
|
1
|
-
require 'uri'
|
2
|
-
require 'oauth'
|
3
|
-
require 'nokogiri'
|
4
|
-
require 'cgi'
|
5
|
-
|
6
|
-
module Gliffy
|
7
|
-
class API
|
8
|
-
attr_reader :consumer
|
9
|
-
attr_reader :account_id
|
10
|
-
attr_accessor :application_name
|
11
|
-
|
12
|
-
def initialize(account_id, key, secret)
|
13
|
-
@consumer = init_consumer(key, secret)
|
14
|
-
@account_id = account_id
|
15
|
-
@application_name = Gliffy.default_application_name
|
16
|
-
end
|
17
|
-
|
18
|
-
def plain
|
19
|
-
Gliffy::API::Facade.http(self)
|
20
|
-
end
|
21
|
-
|
22
|
-
def secure
|
23
|
-
Gliffy::API::Facade.https(self)
|
24
|
-
end
|
25
|
-
|
26
|
-
def get(url, params = {})
|
27
|
-
Gliffy::API::Response.new(Nokogiri.XML(raw(url, params)))
|
28
|
-
end
|
29
|
-
|
30
|
-
def raw(url, params = {})
|
31
|
-
r = token.get(url + '?' + query(params))
|
32
|
-
r.body
|
33
|
-
end
|
34
|
-
|
35
|
-
def post(url, params)
|
36
|
-
r = token.post(url, params)
|
37
|
-
Gliffy::API::Response.new(Nokogiri.XML(r.body))
|
38
|
-
end
|
39
|
-
|
40
|
-
def web(url, params)
|
41
|
-
consumer.create_signed_request(
|
42
|
-
:get,
|
43
|
-
url + '?' + query(params),
|
44
|
-
token
|
45
|
-
).path
|
46
|
-
end
|
47
|
-
|
48
|
-
def account
|
49
|
-
@account ||= load_account
|
50
|
-
end
|
51
|
-
|
52
|
-
def impersonate(user)
|
53
|
-
escaped_id = URI.escape @account_id.to_s
|
54
|
-
escaped_user = URI.escape user
|
55
|
-
|
56
|
-
response = secure.post(
|
57
|
-
"/accounts/#{escaped_id}/users/#{escaped_user}/oauth_token.xml",
|
58
|
-
:action => 'create',
|
59
|
-
:description => application_name
|
60
|
-
)
|
61
|
-
|
62
|
-
token.token = response.string('//g:oauth-token')
|
63
|
-
token.secret = response.string('//g:oauth-token-secret')
|
64
|
-
end
|
65
|
-
|
66
|
-
private
|
67
|
-
|
68
|
-
def query(params)
|
69
|
-
params.map {|k, v| "#{CGI.escape k.to_s}=#{CGI.escape v.to_s}" }.join('&')
|
70
|
-
end
|
71
|
-
|
72
|
-
def token
|
73
|
-
@token ||= OAuth::AccessToken.new @consumer
|
74
|
-
end
|
75
|
-
|
76
|
-
def load_account
|
77
|
-
response = plain.get("/accounts/#{account_id}.xml",
|
78
|
-
{ :action => 'get' })
|
79
|
-
Gliffy::Account.load(plain, response)
|
80
|
-
end
|
81
|
-
|
82
|
-
def init_consumer(key, secret)
|
83
|
-
OAuth::Consumer.new(key,
|
84
|
-
secret,
|
85
|
-
:site => Gliffy.web_root,
|
86
|
-
:scheme => :query_string)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
1
|
+
require 'uri'
|
2
|
+
require 'oauth'
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'cgi'
|
5
|
+
|
6
|
+
module Gliffy
|
7
|
+
class API
|
8
|
+
attr_reader :consumer
|
9
|
+
attr_reader :account_id
|
10
|
+
attr_accessor :application_name
|
11
|
+
|
12
|
+
def initialize(account_id, key, secret)
|
13
|
+
@consumer = init_consumer(key, secret)
|
14
|
+
@account_id = account_id
|
15
|
+
@application_name = Gliffy.default_application_name
|
16
|
+
end
|
17
|
+
|
18
|
+
def plain
|
19
|
+
Gliffy::API::Facade.http(self)
|
20
|
+
end
|
21
|
+
|
22
|
+
def secure
|
23
|
+
Gliffy::API::Facade.https(self)
|
24
|
+
end
|
25
|
+
|
26
|
+
def get(url, params = {})
|
27
|
+
Gliffy::API::Response.new(Nokogiri.XML(raw(url, params)))
|
28
|
+
end
|
29
|
+
|
30
|
+
def raw(url, params = {})
|
31
|
+
r = token.get(url + '?' + query(params))
|
32
|
+
r.body
|
33
|
+
end
|
34
|
+
|
35
|
+
def post(url, params)
|
36
|
+
r = token.post(url, params)
|
37
|
+
Gliffy::API::Response.new(Nokogiri.XML(r.body))
|
38
|
+
end
|
39
|
+
|
40
|
+
def web(url, params)
|
41
|
+
consumer.create_signed_request(
|
42
|
+
:get,
|
43
|
+
url + '?' + query(params),
|
44
|
+
token
|
45
|
+
).path
|
46
|
+
end
|
47
|
+
|
48
|
+
def account
|
49
|
+
@account ||= load_account
|
50
|
+
end
|
51
|
+
|
52
|
+
def impersonate(user)
|
53
|
+
escaped_id = URI.escape @account_id.to_s
|
54
|
+
escaped_user = URI.escape user
|
55
|
+
|
56
|
+
response = secure.post(
|
57
|
+
"/accounts/#{escaped_id}/users/#{escaped_user}/oauth_token.xml",
|
58
|
+
:action => 'create',
|
59
|
+
:description => application_name
|
60
|
+
)
|
61
|
+
|
62
|
+
token.token = response.string('//g:oauth-token')
|
63
|
+
token.secret = response.string('//g:oauth-token-secret')
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def query(params)
|
69
|
+
params.map {|k, v| "#{CGI.escape k.to_s}=#{CGI.escape v.to_s}" }.join('&')
|
70
|
+
end
|
71
|
+
|
72
|
+
def token
|
73
|
+
@token ||= OAuth::AccessToken.new @consumer
|
74
|
+
end
|
75
|
+
|
76
|
+
def load_account
|
77
|
+
response = plain.get("/accounts/#{account_id}.xml",
|
78
|
+
{ :action => 'get' })
|
79
|
+
Gliffy::Account.load(plain, response)
|
80
|
+
end
|
81
|
+
|
82
|
+
def init_consumer(key, secret)
|
83
|
+
OAuth::Consumer.new(key,
|
84
|
+
secret,
|
85
|
+
:site => Gliffy.web_root,
|
86
|
+
:scheme => :query_string)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|