Wassruby 0.0.7 → 0.0.8

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.
data/example/example.rb CHANGED
@@ -1,4 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
1
 
3
2
  require 'wassr'
4
3
 
@@ -0,0 +1,15 @@
1
+
2
+ require 'wassruby'
3
+
4
+ #Get a new message of user
5
+ puts WWW::Wassr.get :user_show, "staff"
6
+
7
+ # Module Function : get(key, id = nil) -> Array | Bool
8
+ # [PARAM] key:
9
+ #
10
+ # :public_timeline,:user_timeline,:user_show,:new_channel
11
+ # :channel_check,:sl_timeline,:user_channel_list :todo_list
12
+
13
+ #Return New Channel list (array object)
14
+ val = WWW::Wassr.get :new_channel
15
+ puts val #Return an array object
data/lib/wassruby.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  #= Simple Wassr Client
2
2
  #Authors:: Takuya Mannami
3
- #Version:: 0.0.7 (2009/11/24)
3
+ #Version:: 0.0.8 (2009/11/24)
4
4
  #License:: MIT License
5
5
 
6
6
  # -*- coding: utf-8 -*-
@@ -8,17 +8,25 @@
8
8
  require 'open-uri'
9
9
  require 'net/http'
10
10
  require 'cgi'
11
- require 'json' #NOTE : RUBY_VERSION > '1.9'
11
+ require 'rss'
12
+ require 'json'
12
13
 
13
14
  module WWW
14
15
  class Wassr
15
- VERSION = '0.0.7'
16
+ VERSION = '0.0.8'
16
17
  WASSR = "api.wassr.jp"
17
18
  WASSR_RUBY = "Wassruby"
18
19
  WASSR_API_URL = {
19
- :UPDATE => "/statuses/update.json?status=",
20
- :PUBLIC_TIMELINE => "/statuses/public_timeline.json",
21
- :USER_TIMELINE => "/statuses/user_timeline.json?id=",
20
+ :UPDATE => "/statuses/update.json?status=",
21
+ :PUBLIC_TIMELINE => "/statuses/public_timeline.json",
22
+ :USER_TIMELINE => "/statuses/user_timeline.json?id=",
23
+ :USER_SHOW => "/statuses/show.json?id=",
24
+ :NEW_CHANNEL => "/channel/list.rss",
25
+ :CHANNEL_CHECK => "/channel/exists.json?name_en=",
26
+ :USER_CHANNEL_LIST => "/channel_user/user_list.json?login_id=",
27
+ :SL_TIMELINE => "/statuses/sl_timeline.json",
28
+ :TODO_UPDATE => "/todo/add.json?body=",
29
+ :TODO_LIST => "/todo/list.json?page=1&done_fg=0",
22
30
  }
23
31
 
24
32
  def initialize(login_id, password)
@@ -32,26 +40,51 @@ module WWW
32
40
  block.call(self.new(login_id, password))
33
41
  end
34
42
 
35
- def get_res_body_json(api_add)
36
- JSON.parse(Net::HTTP.new(WASSR, 80).get(api_add).body)
43
+ def get_res_body_json(api_add, id="")
44
+ JSON.parse(Net::HTTP.new(WASSR, 80).get(WASSR_API_URL[api_add] << id).body)
37
45
  end
38
46
 
39
- def get(key, user_id="")
47
+ def get_res_body_rss(api_add, id="")
48
+ RSS::Parser.parse(Net::HTTP.new(WASSR, 80).get(WASSR_API_URL[api_add] << id).body)
49
+ end
50
+
51
+ def get(key, id=nil)
40
52
  case key
41
53
  when :public_timeline
42
- get_res_body_json(WASSR_API_URL[:PUBLIC_TIMELINE])
54
+ get_res_body_json(:PUBLIC_TIMELINE)
43
55
  when :user_timeline
44
- get_res_body_json(WASSR_API_URL[:USER_TIMELINE] << user_id)
56
+ get_res_body_json(:USER_TIMELINE, id) if id != nil
57
+ when :user_show #get new one message of user
58
+ get_res_body_json(:USER_SHOW, id) if id != nil
59
+ when :new_channel
60
+ get_res_body_rss(:NEW_CHANNEL)
61
+ when :channel_check
62
+ get_res_body_json(:CHANNEL_CHECK, id) if id != nil
63
+ when :sl_timeline
64
+ get_res_body_json(:SL_TIMELINE)
65
+ when :user_channel_list
66
+ get_res_body_json(:USER_CHANNEL_LIST, id) if id != nil
67
+ when :todo_list
68
+ get_res_body_json(:TODO_LIST)
45
69
  end
46
70
  end
47
71
  end
48
-
49
- def post(message)
50
- req = Net::HTTP::Post.new(WASSR_API_URL[:UPDATE] <<
51
- CGI.escape(message) <<
72
+
73
+ def post!(api_key, val)
74
+ req = Net::HTTP::Post.new(WASSR_API_URL[api_key] << CGI.escape(val) <<
52
75
  "&source=" << WASSR_RUBY)
76
+ req[:user_agent] = WASSR_RUBY
53
77
  req.basic_auth(@login_id, @password)
54
78
  res = @http.request(req)
55
79
  end
80
+
81
+ def post(key, val="")
82
+ case key
83
+ when :update
84
+ post!(:UPDATE, val)
85
+ when :todo_update
86
+ post!(:TODO_UPDATE, val)
87
+ end
88
+ end
56
89
  end
57
90
  end
data/test/test1.rb ADDED
@@ -0,0 +1,72 @@
1
+
2
+ require 'test/unit'
3
+ require 'wassruby'
4
+
5
+ class Wassr_Test < Test::Unit::TestCase
6
+ def setup
7
+ @client = WWW::Wassr.new("hoge","hoge")
8
+ @wassr_api_channel = "wassr_api"
9
+ @wassr_staff = "staff"
10
+ end
11
+
12
+ def get(key, val="")
13
+ WWW::Wassr.get(key, val)
14
+ end
15
+
16
+ def test_setup_client1
17
+ assert_not_nil(@client)
18
+ end
19
+
20
+ def test_setup_client2
21
+ assert(@client.instance_variable_get(:@login_id))
22
+ end
23
+
24
+ def test_setup_client3
25
+ assert(@client.instance_variable_get(:@password))
26
+ end
27
+
28
+ def test_setup_client4
29
+ assert(@client.instance_variable_get(:@http))
30
+ end
31
+
32
+ def test_const1
33
+ assert_equal(WWW::Wassr.const_get(:WASSR), "api.wassr.jp")
34
+ end
35
+
36
+ def test_client
37
+ assert_instance_of(WWW::Wassr, @client)
38
+ end
39
+
40
+ def test_public_timeline
41
+ assert(get(:public_timeline))
42
+ end
43
+
44
+ def test_user_timeline
45
+ assert(get(:user_timeline, @wassr_staff))
46
+ end
47
+
48
+ def test_user_show
49
+ assert(get(:user_show, @wassr_staff))
50
+ end
51
+
52
+ def test_new_channel
53
+ assert(get(:new_channel))
54
+ end
55
+
56
+ def test_channel_check
57
+ assert(get(:channel_check, @wassr_api_channel))
58
+ end
59
+
60
+ def test_sl_timeline
61
+ assert(get(:sl_timeline))
62
+ end
63
+
64
+ def test_user_channel_list
65
+ assert(get(:user_channel_list, @wassr_staff))
66
+ end
67
+
68
+ def test_start
69
+ assert(WWW::Wassr.new("hoge","hoge"){|client| client })
70
+ end
71
+ end
72
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Wassruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takuya Mannami
@@ -13,7 +13,7 @@ date: 2009-11-24 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: README
16
+ description: A Simple Wassr Client
17
17
  email: mtakuya@users.sourceforge.jp
18
18
  executables: []
19
19
 
@@ -24,7 +24,9 @@ extra_rdoc_files:
24
24
  files:
25
25
  - lib/wassruby.rb
26
26
  - example/example.rb
27
+ - example/example2.rb
27
28
  - README.txt
29
+ - test/test1.rb
28
30
  has_rdoc: true
29
31
  homepage: http://wassruby.rubyforge.org/
30
32
  licenses:
@@ -53,6 +55,6 @@ rubyforge_project: Wassruby
53
55
  rubygems_version: 1.3.5
54
56
  signing_key:
55
57
  specification_version: 3
56
- summary: A Simple Wassr Client
57
- test_files: []
58
-
58
+ summary: A Simple Wassr Client (RUBY_VERSIN > 1.9.0)
59
+ test_files:
60
+ - test/test1.rb