Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactoring of array parsing.

For whatever reason I was returning arrays of size 1 as objects
and not as arrays of size 1.  Changed this behavior and fixed tests
that were assuming this bad behavior. Yay.

Also some tests for getting documents in a folder
  • Loading branch information...
commit 0c6714de9414df7d6ceb98b98ff8092b92cfb639 1 parent ad7adea
David Copeland authored
13 lib/gliffy/handle.rb
View
@@ -72,7 +72,7 @@ def account_folders
# Returns account meta data
def account_get(show_users=true)
- make_request(:get,"#{account_url}.xml", :showUsers => show_users)
+ make_request(:get,"#{account_url}.xml", :showUsers => show_users)[0]
end
# Get users in your account
@@ -96,7 +96,7 @@ def document_delete
end
def document_get_metadata(document_id,show_revisions=:false)
- make_request(:get,document_url(document_id),:showRevisions => show_revisions)
+ make_request(:get,document_url(document_id),:showRevisions => show_revisions)[0]
end
# Get a document; returning the actual bytes
@@ -138,7 +138,8 @@ def folder_delete
end
# Get the documents in a folder
- def folder_documents
+ def folder_documents(path)
+ make_request(:get,"#{folders_url(path)}/documents.xml")
end
# Get users with access to the folder
@@ -179,6 +180,12 @@ def token_url; "#{user_url}/oauth_token.xml"; end
def document_url(id,type=:xml); "#{account_url}/documents/#{id}.#{type.to_s}"; end
def folders_url(path=''); "#{account_url}/folders/#{path}"; end
+ # Handles the mechanics of making the request
+ # [+method+] the gliffy "action"
+ # [+url+] the url, relative to the gliffy API root, no params/query string stuff
+ # [+params+] hash of parameters
+ # [+parse+] if true, request is parsed; set to false to get the raw result back
+ # [+link_only+] don't make a request just send the full link (useful for <img> tags)
def make_request(method,url,params=nil,parse=true,link_only=false)
update_token
if link_only
4 lib/gliffy/response.rb
View
@@ -98,14 +98,14 @@ class ArrayParser
def self.from_http_response(root,single_class,plural_name,single_name)
root = root[plural_name]
return nil if root.nil?
- if root[single_name].kind_of? Array
+ if root[single_name].kind_of?(Array)
list = Array.new
root[single_name].each do |item|
list << single_class.from_http_response(item)
end
list
else
- single_class.from_http_response(root[single_name])
+ [single_class.from_http_response(root[single_name])]
end
end
end
3  test/int_account.rb
View
@@ -39,7 +39,8 @@ def test_account_meta_data
end
def test_account_folders
- root_folder = @handle.account_folders
+ folders = @handle.account_folders
+ root_folder = folders[0]
assert_equal('ROOT',root_folder.name)
assert_equal(true,root_folder.is_default?)
assert_equal(0,root_folder.child_folders.size)
3  test/tc_account.rb
View
@@ -83,6 +83,7 @@ def test_account_with_one_user
}
}
}))
+ response = response[0]
assert_one_account(response)
assert_equal(1,response.users.size)
assert_equal(@user1_id,response.users[0].user_id)
@@ -100,6 +101,7 @@ def test_accounts_with_users
}
}
}))
+ response = response[0]
assert_one_account(response)
assert_equal(2,response.users.size)
assert_equal(@user1_id,response.users[0].user_id)
@@ -130,6 +132,7 @@ def test_accounts
}
}
}))
+ response = response[0]
assert_one_account(response)
end
2  test/tc_document.rb
View
@@ -147,6 +147,7 @@ def test_single_diagram
}
}
}))
+ response = response[0]
assert_document1(response)
end
@@ -159,6 +160,7 @@ def test_single_diagram_with_versions
}
}
}))
+ response = response[0]
assert_document3(response)
end
1  test/tc_folder.rb
View
@@ -85,6 +85,7 @@ def test_root_folder
}
}
}))
+ response = response[0]
assert_equal(@f2_id,response.folder_id)
assert_equal(@f2_name,response.name)
assert_equal(@f2_path,response.path)
34 test/tc_handle.rb
View
@@ -37,6 +37,10 @@ def setup
@handle = Gliffy::Handle.new(@api_root,@cred,AllGetHTTP.new)
end
+ def teardown
+ @s.shutdown
+ end
+
def test_bad_folder_users_request
assert_raises(BadResponseException) do
@handle.folder_users('a/b/c')
@@ -85,7 +89,8 @@ def test_account_admins
end
def test_account_folders
- root_folder = @handle.account_folders
+ folders = @handle.account_folders
+ root_folder = folders[0]
assert_equal('ROOT',root_folder.name)
assert_equal(true,root_folder.is_default?)
assert_equal(2,root_folder.child_folders.size)
@@ -140,19 +145,28 @@ def test_folders
end
def test_user_folders
- root_folder = @handle.user_folders('davetron5000')
- assert(2,root_folder.child_folders.size)
- assert(3,root_folder.child_folders[1].child_folders.size)
- assert('fauxml',root_folder.child_folders[1].child_folders[2].name)
+ folders = @handle.user_folders('davetron5000')
+ root_folder = folders[0]
+ assert_equal(2,root_folder.child_folders.size)
+ assert_equal(3,root_folder.child_folders[1].child_folders.size)
+ assert_equal('fauxml',root_folder.child_folders[1].child_folders[2].name)
- root_folder = @handle.user_folders('testuser@gliffy.com')
- assert(1,root_folder.child_folders.size)
- assert('tmp',root_folder.child_folders[0].name)
+ folders = @handle.user_folders('testuser@gliffy.com')
+ root_folder = folders[0]
+ assert_equal(1,root_folder.child_folders.size)
+ assert_equal('tmp',root_folder.child_folders[0].name)
end
- def teardown
- @s.shutdown
+ def test_folder_documents
+ documents = @handle.folder_documents('ROOT')
+ assert_equal(1,documents.size)
+ assert_equal('Booze DB',documents[0].name)
+
+ documents = @handle.folder_documents('ROOT/tmp')
+ assert_equal(2,documents.size)
+ assert_equal('Booze DB',documents[0].name)
+ assert_equal('Hounds Room',documents[1].name)
end
private
2  test/tc_user.rb
View
@@ -37,7 +37,7 @@ def test_one_user
}
}
}))
- assert_user1(response)
+ assert_user1(response[0])
end
def test_two_users
15 test/test_doc_root/accounts/101/folders/ROOT/documents.xml
View
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<response xmlns="http://www.gliffy.com" success="true">
+ <documents>
+ <document num-versions="2" id="1000003">
+ <name>Booze DB</name>
+ <mod-date>1215538283000</mod-date>
+ <create-date>1215538283000</create-date>
+ <published-date>1215538283000</published-date>
+ <owner id="208">
+ <username>moe</username>
+ <email>moe@BurnsODyne.apiuser.gliffy.com</email>
+ </owner>
+ </document>
+ </documents>
+</response>
25 test/test_doc_root/accounts/101/folders/ROOT/tmp/documents.xml
View
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<response xmlns="http://www.gliffy.com" success="true">
+ <documents>
+ <document num-versions="2" id="1000003">
+ <name>Booze DB</name>
+ <mod-date>1215538283000</mod-date>
+ <create-date>1215538283000</create-date>
+ <published-date>1215538283000</published-date>
+ <owner id="208">
+ <username>moe</username>
+ <email>moe@BurnsODyne.apiuser.gliffy.com</email>
+ </owner>
+ </document>
+ <document is-public="true" num-versions="4" id="1000000">
+ <name>Hounds Room</name>
+ <mod-date>1215538283000</mod-date>
+ <create-date>1215538283000</create-date>
+ <published-date>1215538283000</published-date>
+ <owner id="202">
+ <username>monty</username>
+ <email>monty@BurnsODyne.apiuser.gliffy.com</email>
+ </owner>
+ </document>
+ </documents>
+</response>
Please sign in to comment.
Something went wrong with that request. Please try again.