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 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
- doc.name
17
- doc.editor(RETURN_TO, RETURN_BUTTON_TEXT)
18
- doc.png.full
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/facade'
5
- require 'gliffy/api/response'
6
- require 'gliffy/account'
7
- require 'gliffy/document'
8
- require 'gliffy/document_png'
9
- require 'gliffy/folder'
10
-
11
- require 'gliffy/oauth/helper'
12
-
13
- module Gliffy
14
- class << self
15
- def default_application_name
16
- "Gliffy Ruby Gem"
17
- end
18
-
19
- # some calls (e.g. OAuth token generation) should be done through
20
- # secure HTTPS; other calls (e.g. actions performed by
21
- # non-privileged accounts) should be done though plain HTTP
22
- #
23
- # We're using protocol-relative URL here.
24
- def api_root
25
- '//www.gliffy.com/api/1.0'
26
- end
27
-
28
- # We're using protocol-relative (//hosrname/path/ format) URL here.
29
- def web_root
30
- '//www.gliffy.com'
31
- end
32
- end
33
- end
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
@@ -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