Class: Gyazz::Page
- Inherits:
-
Object
- Object
- Gyazz::Page
- Defined in:
- lib/gyazz/page.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
(also: #title)
readonly
Returns the value of attribute name.
-
#wiki ⇒ Object
readonly
Returns the value of attribute wiki.
Instance Method Summary collapse
- #access(opts = {}) ⇒ Object
- #data(opts = {:query => {:version => 0}}) ⇒ Object
-
#initialize(name, wiki) ⇒ Page
constructor
A new instance of Page.
- #modify(opts = {}) ⇒ Object
- #related_pages(opts = {}) ⇒ Object
- #text(opts = {}) ⇒ Object
- #text=(str_or_arr, opts = {}) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(name, wiki) ⇒ Page
Returns a new instance of Page.
8 9 10 11 |
# File 'lib/gyazz/page.rb', line 8 def initialize(name, wiki) @name = name @wiki = wiki end |
Instance Attribute Details
#name ⇒ Object (readonly) Also known as: title
Returns the value of attribute name.
5 6 7 |
# File 'lib/gyazz/page.rb', line 5 def name @name end |
#wiki ⇒ Object (readonly)
Returns the value of attribute wiki.
5 6 7 |
# File 'lib/gyazz/page.rb', line 5 def wiki @wiki end |
Instance Method Details
#access(opts = {}) ⇒ Object
37 38 39 |
# File 'lib/gyazz/page.rb', line 37 def access(opts={}) JSON.parse @wiki.get("/#{URI.encode @wiki.name}/#{URI.encode @name}/__access", opts) end |
#data(opts = {:query => {:version => 0}}) ⇒ Object
33 34 35 |
# File 'lib/gyazz/page.rb', line 33 def data(opts={:query => {:version => 0}}) JSON.parse @wiki.get("/#{URI.encode @wiki.name}/#{URI.encode @name}/json", opts) end |
#modify(opts = {}) ⇒ Object
41 42 43 |
# File 'lib/gyazz/page.rb', line 41 def modify(opts={}) JSON.parse @wiki.get("/#{URI.encode @wiki.name}/#{URI.encode @name}/__modify", opts) end |
#related_pages(opts = {}) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/gyazz/page.rb', line 45 def (opts={}) url = "/#{URI.encode @wiki.name}/#{URI.encode @name}/related" JSON.parse(@wiki.get(url, opts)).map{|name| Page.new name, @wiki } end |
#text(opts = {}) ⇒ Object
17 18 19 |
# File 'lib/gyazz/page.rb', line 17 def text(opts={}) @wiki.get("/#{URI.encode @wiki.name}/#{URI.encode @name}/text", opts) end |
#text=(str_or_arr, opts = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/gyazz/page.rb', line 21 def text=(str_or_arr, opts={}) data = str_or_arr.kind_of?(Array) ? str_or_arr.join("\n") : str_or_arr unless opts.has_key? :body opts[:body] = { :name => @wiki.name, :title => @name, :data => data } end @wiki.post("/__write__", opts) end |
#url ⇒ Object
13 14 15 |
# File 'lib/gyazz/page.rb', line 13 def url "#{@wiki.url}/#{URI.encode @name}" end |