class Gyazz::Wiki

Attributes

host[R]
name[R]

Public Class Methods

new(name) click to toggle source
# File lib/gyazz/wiki.rb, line 7
def initialize(name)
  @name = name
  @host = 'http://gyazz.com'
end

Public Instance Methods

auth=(opts) click to toggle source
# File lib/gyazz/wiki.rb, line 20
def auth=(opts)
  @basic_auth = opts
end
get(path, opts={}) click to toggle source
# File lib/gyazz/wiki.rb, line 28
def get(path, opts={})
  opts[:basic_auth] = @basic_auth if @basic_auth and !opts.has_key?(:basic_auth)
  res = HTTParty.get "#{@host}#{path}", opts
  case res.code
  when 200
    return res.body
  else
    raise Gyazz::Error, res.body
  end
end
host=(host) click to toggle source
# File lib/gyazz/wiki.rb, line 16
def host=(host)
  @host = host
end
page(name) click to toggle source
# File lib/gyazz/wiki.rb, line 24
def page(name)
  Page.new name, self
end
pages(opts={}) click to toggle source
# File lib/gyazz/wiki.rb, line 50
def pages(opts={})
  JSON.parse(self.get "/#{URI.encode @name}/__list", opts).map{|i|
    Page.new(i[0], self)
  }
end
post(path, opts={}) click to toggle source
# File lib/gyazz/wiki.rb, line 39
def post(path, opts={})
  opts[:basic_auth] = @basic_auth if @basic_auth and !opts.has_key?(:basic_auth)
  res = HTTParty.post "#{@host}#{path}", opts
  case res.code
  when 200
    return res.body
  else
    raise Gyazz::Error, res.body
  end
end
url() click to toggle source
# File lib/gyazz/wiki.rb, line 12
def url
  "#{@host}/#{URI.encode @name}"
end