Class: Gyazz::Wiki

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Wiki

Returns a new instance of Wiki.



7
8
9
10
# File 'lib/gyazz/wiki.rb', line 7

def initialize(name)
  @name = name
  @host = 'http://gyazz.com'
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/gyazz/wiki.rb', line 5

def host
  @host
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/gyazz/wiki.rb', line 5

def name
  @name
end

Instance Method Details

#auth=(opts) ⇒ Object



20
21
22
# File 'lib/gyazz/wiki.rb', line 20

def auth=(opts)
  @basic_auth = opts
end

#get(path, query = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/gyazz/wiki.rb', line 28

def get(path, query={})
  res = HTTParty.get "#{@host}#{path}", :query => query, :basic_auth => @basic_auth
  case res.code
  when 200
    return res.body
  else
    raise Gyazz::Error, res.body
  end
end

#page(name) ⇒ Object



24
25
26
# File 'lib/gyazz/wiki.rb', line 24

def page(name)
  Page.new name, self
end

#pagesObject



49
50
51
52
53
# File 'lib/gyazz/wiki.rb', line 49

def pages
  JSON.parse(self.get "/#{URI.encode @name}/__list").map{|i|
    Page.new(i[0], self)
  }
end

#post(path, opts) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/gyazz/wiki.rb', line 38

def post(path, opts)
  opts[:basic_auth] = @basic_auth if @basic_auth
  res = HTTParty.post "#{@host}#{path}", opts
  case res.code
  when 200
    return res.body
  else
    raise Gyazz::Error, res.body
  end
end

#urlObject



12
13
14
# File 'lib/gyazz/wiki.rb', line 12

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