Class: Gyazz::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/gyazz/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (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

#wikiObject (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


45
46
47
48
49
50
# File 'lib/gyazz/page.rb', line 45

def related_pages(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

#urlObject



13
14
15
# File 'lib/gyazz/page.rb', line 13

def url
  "#{@wiki.url}/#{URI.encode @name}"
end