gyazz 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,8 @@ module Gyazz
3
3
  class Page
4
4
 
5
5
  attr_reader :wiki, :name
6
+ alias_method :title, :name
7
+
6
8
  def initialize(name, wiki)
7
9
  @name = name
8
10
  @wiki = wiki
@@ -12,35 +14,37 @@ module Gyazz
12
14
  "#{@wiki.url}/#{URI.encode @name}"
13
15
  end
14
16
 
15
- def text
16
- @wiki.get("/#{URI.encode @wiki.name}/#{URI.encode @name}/text")
17
+ def text(opts={})
18
+ @wiki.get("/#{URI.encode @wiki.name}/#{URI.encode @name}/text", opts)
17
19
  end
18
20
 
19
- def text=(str_or_arr)
21
+ def text=(str_or_arr, opts={})
20
22
  data = str_or_arr.kind_of?(Array) ? str_or_arr.join("\n") : str_or_arr
21
- @wiki.post("/__write__",
22
- :body => {
23
- :name => @wiki.name,
24
- :title => @name,
25
- :data => data
26
- })
23
+ unless opts.has_key? :body
24
+ opts[:body] = {
25
+ :name => @wiki.name,
26
+ :title => @name,
27
+ :data => data
28
+ }
29
+ end
30
+ @wiki.post("/__write__", opts)
27
31
  end
28
32
 
29
- def data(query = {:version => 0})
30
- JSON.parse @wiki.get("/#{URI.encode @wiki.name}/#{URI.encode @name}/json", query)
33
+ def data(opts={:query => {:version => 0}})
34
+ JSON.parse @wiki.get("/#{URI.encode @wiki.name}/#{URI.encode @name}/json", opts)
31
35
  end
32
36
 
33
- def access
34
- JSON.parse @wiki.get("/#{URI.encode @wiki.name}/#{URI.encode @name}/__access")
37
+ def access(opts={})
38
+ JSON.parse @wiki.get("/#{URI.encode @wiki.name}/#{URI.encode @name}/__access", opts)
35
39
  end
36
40
 
37
- def modify
38
- JSON.parse @wiki.get("/#{URI.encode @wiki.name}/#{URI.encode @name}/__modify")
41
+ def modify(opts={})
42
+ JSON.parse @wiki.get("/#{URI.encode @wiki.name}/#{URI.encode @name}/__modify", opts)
39
43
  end
40
44
 
41
- def related_pages
45
+ def related_pages(opts={})
42
46
  url = "/#{URI.encode @wiki.name}/#{URI.encode @name}/related"
43
- JSON.parse(@wiki.get(url)).map{|name|
47
+ JSON.parse(@wiki.get(url, opts)).map{|name|
44
48
  Page.new name, @wiki
45
49
  }
46
50
  end
@@ -1,3 +1,3 @@
1
1
  module Gyazz
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
@@ -25,8 +25,9 @@ module Gyazz
25
25
  Page.new name, self
26
26
  end
27
27
 
28
- def get(path, query={})
29
- res = HTTParty.get "#{@host}#{path}", :query => query, :basic_auth => @basic_auth
28
+ def get(path, opts={})
29
+ opts[:basic_auth] = @basic_auth if @basic_auth and !opts.has_key?(:basic_auth)
30
+ res = HTTParty.get "#{@host}#{path}", opts
30
31
  case res.code
31
32
  when 200
32
33
  return res.body
@@ -35,8 +36,8 @@ module Gyazz
35
36
  end
36
37
  end
37
38
 
38
- def post(path, opts)
39
- opts[:basic_auth] = @basic_auth if @basic_auth
39
+ def post(path, opts={})
40
+ opts[:basic_auth] = @basic_auth if @basic_auth and !opts.has_key?(:basic_auth)
40
41
  res = HTTParty.post "#{@host}#{path}", opts
41
42
  case res.code
42
43
  when 200
@@ -46,8 +47,8 @@ module Gyazz
46
47
  end
47
48
  end
48
49
 
49
- def pages
50
- JSON.parse(self.get "/#{URI.encode @name}/__list").map{|i|
50
+ def pages(opts={})
51
+ JSON.parse(self.get "/#{URI.encode @name}/__list", opts).map{|i|
51
52
  Page.new(i[0], self)
52
53
  }
53
54
  end
@@ -5,6 +5,7 @@ class TestWikiAuth < MiniTest::Test
5
5
  def setup
6
6
  @wiki = Gyazz::Wiki.new 'test_auth'
7
7
  @wiki.host = ENV['GYAZZ_HOST'] if ENV.has_key? 'GYAZZ_HOST'
8
+ @auth = {:username => 'test_username', :password => 'test_password'}
8
9
  end
9
10
 
10
11
  def test_auth_fail
@@ -18,7 +19,7 @@ class TestWikiAuth < MiniTest::Test
18
19
  end
19
20
 
20
21
  def test_auth
21
- @wiki.auth = {:username => 'test_username', :password => 'test_password'}
22
+ @wiki.auth = @auth
22
23
  pages = @wiki.pages
23
24
  assert_equal pages.class, Array
24
25
  pages.each do |page|
@@ -37,8 +38,16 @@ class TestWikiAuth < MiniTest::Test
37
38
  assert_equal err.class, Gyazz::Error
38
39
  end
39
40
 
41
+ def test_manually_auth
42
+ pages = @wiki.pages(:basic_auth => @auth)
43
+ assert_equal pages.class, Array
44
+ pages.each do |page|
45
+ assert_equal page.class, Gyazz::Page
46
+ end
47
+ end
48
+
40
49
  def test_auth_page_get_set
41
- @wiki.auth = {:username => 'test_username', :password => 'test_password'}
50
+ @wiki.auth = @auth
42
51
  page = @wiki.page('aaa')
43
52
  body = ["foo", "bar", Time.now.to_s].join("\n")
44
53
  page.text = body
@@ -8,6 +8,10 @@ class TestPage < MiniTest::Test
8
8
  @page = @wiki.page('aaa')
9
9
  end
10
10
 
11
+ def test_title_name
12
+ assert_equal @page.title, @page.name
13
+ end
14
+
11
15
  def test_url
12
16
  host = ENV['GYAZZ_HOST'] || 'http://gyazz.com'
13
17
  assert_equal @page.url , "#{host}/#{@wiki.name}/#{@page.name}"
@@ -20,4 +20,12 @@ class TestWiki < MiniTest::Test
20
20
  end
21
21
  end
22
22
 
23
+ def test_pages_with_options
24
+ pages = @wiki.pages :timeout => 120
25
+ assert_equal pages.class, Array
26
+ pages.each do |page|
27
+ assert_equal page.class, Gyazz::Page
28
+ end
29
+ end
30
+
23
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gyazz
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-01-03 00:00:00.000000000 Z
13
+ date: 2014-01-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler