Browse files

various tweaks to the knowledge base and increase in minor version

  • Loading branch information...
1 parent 48a04a2 commit 9d060efee7d310b9989e976744ecac44d6872886 @adamcooke adamcooke committed Jun 15, 2012
View
21 README.md
@@ -199,32 +199,23 @@ knowledge_bases = sirportly.knowledge_bases.first
kb_with_pages = sirportly.knowledge_base(knowledge_bases.first.attributes['id'])
```
-### Pages
+### Knowledge Base Pages
A page object contains an array of child pages.
```ruby
kb = sirportly.knowledge_base(kb_id)
-page = kb.pages.first
-page.attributes
-=> {"id"=>672, "title"=>"Test 2", "permalink"=>"test-2", "full_permalink"=>"test-2", "position"=>2, "children"=>[#<Sirportly::Page {"id"=>673, "title"=>"Child 1", "permalink"=>"child-1", "full_permalink"=>"child-1", "position"=>1, "children"=>[#<Sirportly::Page {"id"=>674, "title"=>"Subchild 1", "permalink"=>"subchild-1", "full_permalink"=>"subchild-1", "position"=>1, "children"=>[]}>]}>]}
-page.has_children?
-=> true
-page.children
-=> [#<Sirportly::Page:0x007fb1c991f1e0>]
+kb.tree #=> Array of KnowledgeBasePage objects
+page = kb.page('path/to/page') #=> A KnowledgeBasePage object
+page.children #=> Array of KnowledgeBasePage objects
+
```
The API does not support knowledge base creation, but it does support create page creation.
```ruby
-page_attributes = {
- :title => 'My Title',
- :content => 'Markdown *formatted* content'
-}
-
kb = sirportly.knowledge_bases.first
-kb.create_page page_attributes
-=> #<Sirportly::Page:0x007ff233970d88>
+kb.create_page(:title => 'My Title', :content => 'Content here') #=> #<Sirportly::Page:0x007ff233970d88>
```
TODO: Child page creation.
View
4 lib/sirportly.rb
@@ -16,7 +16,7 @@
require 'sirportly/data_objects/escalation_path'
require 'sirportly/data_objects/filter'
require 'sirportly/data_objects/knowledge_base'
-require 'sirportly/data_objects/page'
+require 'sirportly/data_objects/knowledge_base_page'
require 'sirportly/data_objects/priority'
require 'sirportly/data_objects/sla'
require 'sirportly/data_objects/status'
@@ -26,7 +26,7 @@
require 'sirportly/data_objects/user'
module Sirportly
- VERSION = '1.1.7'
+ VERSION = '1.2.0'
class << self
View
26 lib/sirportly/data_objects/knowledge_base.rb
@@ -1,31 +1,29 @@
module Sirportly
- class KnowledgeBase < DataObject
+ class KnowledgeBase < DataObject
+
self.collection_path = 'knowledge/list'
- self.member = {:path => 'knowledge/tree', :param => :kb}
- self.maps = {'children' => 'Page'}
- ## Workaround for a Sirportly bug
- ## Currently SP wraps the result in an array
def self.find(client, query)
- raise Sirportly::Error, "This object does not support finding objects" unless member.is_a?(Hash)
- result = client.request(member[:path], {member[:param] => query})
- ## Notice .first here
- self.new(client, result.first)
+ result = client.request("knowledge/list").select { |i| i['id'] == query.to_i}.first
+ self.new(client, result)
+ end
+
+ def page(path)
+ KnowledgeBasePage.new(client, client.request('knowledge/page', :kb => attributes['id'], :path => path))
end
- def pages
- self.children
+ def tree
+ client.request('knowledge/tree', :kb => attributes['id']).map { |i| KnowledgeBasePage.new(client, i) }
end
- ## Creates a new page associated with this knowledge base
- ## Returns a Page object
def create_page(params = {})
params.merge!({:kb => self.attributes['id']})
if req = @client.request('knowledge/add_page', params)
- Page.new @client, req
+ KnowledgeBasePage.new(@client, req)
else
false
end
end
+
end
end
View
10 lib/sirportly/data_objects/knowledge_base_page.rb
@@ -0,0 +1,10 @@
+module Sirportly
+ class KnowledgeBasePage < DataObject
+ self.maps = {'children' => 'KnowledgeBasePage'}
+
+ def has_children?
+ !self.children.empty?
+ end
+
+ end
+end
View
9 lib/sirportly/data_objects/page.rb
@@ -1,9 +0,0 @@
-module Sirportly
- class Page < DataObject
- self.maps = {'children' => 'Page'}
-
- def has_children?
- !self.children.empty?
- end
- end
-end

0 comments on commit 9d060ef

Please sign in to comment.