miby 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ task :default => :rdoc
2
+
3
+ task :rdoc do
4
+ sh "rdoc -c UTF-8 -m lib/miby.rb -S -t miby --exclude fake_mixi --exclude test"
5
+ end
6
+
7
+
@@ -0,0 +1,160 @@
1
+ = miby : Mixi from Ruby
2
+
3
+
4
+ ((*警告*))
5
+ このバージョン(0.0.x)のMibyは完全なテスト版です。実用に耐える機能は備えていません。
6
+ 自分のソフトウェアに組み込んだり、日常的利用することは大変危険です。もちろん、利用により何らかの被害や損害が出た場合も一切保証しません。
7
+
8
+
9
+ == Mibyとは?
10
+ Miby(みびぃ) は Ruby から mixi の日記を操作するライブラリです。
11
+ マイミクの日記リストを取得したり、自分の日記を書く事ができます。
12
+
13
+ === 目的
14
+ Emacsからmixiの日記の読み書きを行う事を目標に作成した Mixi for Emacs(未公開) が原型です。
15
+ Mixiとやり取りするバックエンド部分をライブラリ化しました。
16
+ 自作のツール等でmixiのページ情報が必要な時に使われる事を想定しています。
17
+
18
+ === できる事
19
+ * mixiへのログイン
20
+ * 日記の追加
21
+ * マイミクの最新日記一覧
22
+ * 日記の表示・コメントの追加
23
+ * 新着コメントの確認
24
+
25
+ === できない事
26
+ * mixiからのログアウト
27
+ * 日記: アイコン・タグの挿入
28
+ * 日記: 写真の追加
29
+ * 日記: 日記公開範囲の指定
30
+ * マイミク日記リスト: 外部サイトの日記
31
+ * プロフィール・メッセージ・動画・フォト・ミュージック・レビュー・ニュース 全般
32
+ * その他 諸々
33
+
34
+ == 更新情報
35
+ * 2008/01/25: miby-0.0.1
36
+
37
+ == 必要なソフトウェア
38
+ * [Ruby 1.8.x 以上](http://ruby-lang.org)
39
+ * [Hpricot](http://code.whytheluckystiff.net/hpricot/)
40
+
41
+
42
+ == 導入
43
+ === ダウンロード
44
+ RubyForgeのプロジェクトページからダウンロードできます。
45
+
46
+ * [RUBYFORGE:miby](http://rubyforge.org/projects/miby/)
47
+
48
+ === インストール
49
+ MibyはRubyGemsに対応しています。gemを使って以下のようにインストールできます。
50
+
51
+ # gem install miby-x.x.x.gem
52
+
53
+ gemを利用しない場合は、解凍したファイルをそのまま適当にコピーして利用してください(gemファイルはtarアーカイブです)。
54
+
55
+ // gemはディレクトリを掘らないので自分で掘ります
56
+ # mkdir miby
57
+ # mv miby-x.x.x.gem
58
+ # cd miby
59
+ # tar xvf miby-x.x.x.gem
60
+ // ファイルは data.tar.gz にアーカイブされています。
61
+ # tar zxvf data.tar.gz
62
+ # cp -r ../miby 任意のパス
63
+
64
+ === 設定
65
+ miby.conf.sample をコピーして必要な設定を行ってください。
66
+ 設定は @name = "val" 形式です。
67
+
68
+ # mbiy.conf.sample miby.conf
69
+
70
+ ==== 設定項目
71
+ :http_address
72
+ mixiのアドレス。通常は mixi.jp
73
+ :http_port
74
+ ポート番号。通常は80。
75
+ :proxy_host
76
+ PROXYを使う場合のホスト名。使用しない場合はnil。
77
+ :proxy_port
78
+ PROXYを使う場合のポート番号。使用しない場合はnil。
79
+
80
+
81
+ === ログイン管理
82
+ mixiは一般的なWEBサイトと同様にCookieを使ってユーザのログイン処理を行っています。
83
+
84
+ Mibyでは必要に応じて自動でログインを行います(要メールアドレス・パスワード)。
85
+ 一度ログインすると etc/user.yaml というファイルにCookieを保存してmixiとのセッションに利用しています。
86
+ 他のユーザでログインする場合やうまくページを取得できない場合はこの user.yaml を削除してください。
87
+
88
+ == 使い方
89
+ === 基本的な使い方
90
+ Mibyには試験用のクライアントとして bin/miby が付属しています。
91
+ 動作確認などにはこの試験クライアントを使ってください。
92
+ bin/miby は Miby::Mixi のインスタンスを生成して引数のメソッドを発行するだけです。例えば以下のように実行するとマイミクの最新日記リストを取得して各アイテムの内容を標準出力に表示します。
93
+
94
+ $ ruby bin/miby friend_diary
95
+ ----------item list-----------
96
+ page name: friend_diary
97
+ item size: 50
98
+ name: hoge title:test diary date::Fri Jan 04 10:32:00 + id:0000000 owner_id:00000
99
+ ...デフォルトでは先頭から5アイテム表示
100
+
101
+ 引数なしで実行すると簡単なヘルプを表示します。
102
+ 0.0.1
103
+ command:
104
+ list_diary 自分の日記リスト
105
+ friend_diary マイミクの最新日記リスト
106
+ view_diary_diary id owner_id 日記ID(ID)とMixiID(owner_id)を指定して日記本文
107
+ view_diary_comment id owner_id 日記ID(ID)とMixiID(owner_id)を指定して日記コメント
108
+
109
+ ライブラリの使い方はdoc/index以下のrdocドキュメントを参照してください。
110
+
111
+ == ファイル構成
112
+ ChangeLog
113
+ Rakefile
114
+ Readme.rd(このファイル)
115
+ bin/
116
+ `-- miby(試験用mibyクライアント)
117
+ doc/
118
+ etc/
119
+ |-- miby.conf
120
+ |-- pagedb.yaml(ページ定義データベース(YAML))
121
+ |-- test_miby.conf
122
+ |-- test_pagedb.yaml
123
+ |-- test_user.yaml
124
+ `-- user.yaml(ユーザーcookie情報(YAML))
125
+ exam/
126
+ lib/
127
+ |-- base.rb
128
+ |-- config.rb
129
+ |-- http.rb
130
+ |-- miby.rb
131
+ |-- mixi.rb
132
+ |-- page.rb
133
+ |-- pagedb.rb
134
+ `-- user.rb
135
+ test/
136
+ |-- test_config.rb
137
+ |-- test_http.rb
138
+ |-- test_mixi.rb
139
+ |-- test_page.rb
140
+ |-- test_pagedb.rb
141
+ |-- test_setup.rb
142
+ `-- test_user.rb
143
+
144
+
145
+ == 既存の問題
146
+ mixiの仕様が変更されると利用できなくなります。
147
+
148
+ == 関連リンク集
149
+ * [mixi](http://mixi.jp) - SNS
150
+
151
+ == ライブラリドキュメント
152
+ doc/index.html を参照してください。
153
+ doc/ がない場合は トップディレクトリで rake コマンドを実行してください。
154
+ $ rake
155
+
156
+ == 開発先
157
+ RubyForge.org で開発しています。
158
+ * [RUBYFORGE:miby](http://rubyforge.org/projects/miby/)
159
+
160
+
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/ruby -Ku
2
+ $:.push File.dirname(__FILE__) + '/../lib'
3
+ require 'miby'
4
+ # = miby簡易クライアント
5
+ # Miby::Mixyに登録されている get, post 系のメソッドをテストします。
6
+
7
+ miby = Miby::Miby.new
8
+ puts Miby::VERSION
9
+
10
+ def usage
11
+ puts <<-EOL
12
+ command:
13
+ list_diary 自分の日記リスト
14
+ friend_diary [page_count] マイミクの最新日記リスト
15
+ view_diary_diary id owner_id 日記ID(ID)とMixiID(owner_id)を指定して日記本文
16
+ view_diary_comment id owner_id 日記ID(ID)とMixiID(owner_id)を指定して日記コメント
17
+
18
+
19
+ 詳細は etc/pagedb.yaml と lib/mixi.rb を確認してください。
20
+ options:
21
+ page_count: ページ数
22
+
23
+ example
24
+ # #{$0} friend_diary
25
+ # #{$0} view_diary_diary 1000000 1000
26
+ EOL
27
+ exit
28
+ end
29
+
30
+
31
+ usage if ARGV[0].nil?
32
+ command = ARGV.shift ; puts command
33
+ page = miby.get_page(command, *ARGV)
34
+ items = page.to_a
35
+
36
+
37
+ puts "item list".center(30, "-")
38
+ puts "page name: #{command}"
39
+ puts "item size: #{items.size}"
40
+ items[0..4].each do |item|
41
+ item.each do |key,value|
42
+ print "#{key}:#{value.to_s.gsub("\n","")[0..20]} "
43
+ end
44
+ print "\n"
45
+ end
46
+
47
+
48
+
49
+
50
+
@@ -0,0 +1,201 @@
1
+ #ページ定義データベース(YAML)
2
+ #name: # 定義名
3
+ # path: # パス(FQDN以降)
4
+ # method: # メソッド(デフォはget)
5
+ # params: # 必要なURLパラメータ(配列)
6
+ # - param # パラメータ名
7
+ # params_opt: # オプションのパラメータ
8
+ # css_selecters: # 選択するCSS(配列)
9
+ # - div.title
10
+ # regexp:(.*?) # 選択したCSSからデータを取得する為の正規表現。(後方参照を取得)
11
+ # variables: # 取得した後方参照を配列に格納する時の名前(配列)
12
+ # - body
13
+ login:
14
+ path: login.pl
15
+ method: post
16
+ params:
17
+ - email
18
+ - password
19
+ - next_url
20
+ css_selectors: meta
21
+ regexp: http-equiv="(.*?)"
22
+
23
+ # home
24
+ # ログインできてないと action="login" のフォームが表示される
25
+ # ログインしているかどうかのチェック用
26
+ home_form:
27
+ path: home.pl
28
+ css_selectors: form
29
+ regexp: action="(.*?)"
30
+
31
+ # 新着メッセージ
32
+ home_new_comment:
33
+ path: home.pl
34
+ css_selectors:
35
+ - div.contents
36
+ - ul
37
+ - dd
38
+ regexp: view_diary.pl\?id=(\d+?)&
39
+
40
+ # 日記リスト
41
+ # id がない場合は自分の日記
42
+ list_diary:
43
+ caption: 日記リスト
44
+ path: list_diary.pl
45
+ params_opt:
46
+ - id
47
+ css_selectors:
48
+ - div.listDiaryTitle
49
+ - dl.clearfix
50
+ regexp: <a.*?id=(\d+?)&.*?>(.*?)<.*?<dd>(.*?)<
51
+ variables:
52
+ - id
53
+ - title
54
+ - date
55
+
56
+
57
+ view_diary_diary:
58
+ caption: 日記本文
59
+ path: view_diary.pl
60
+ params:
61
+ - id
62
+ - owner_id
63
+ css_selectors:
64
+ - div.viewDiaryBox
65
+ regexp: <dt>(.*?)<.*<dd>(.*?)<\/dd>.*id="diary_body"*?>(.*?)<\/div>
66
+ variables:
67
+ - title
68
+ - date
69
+ - body
70
+
71
+ view_diary_comment:
72
+ caption: 日記のコメント部分
73
+ path: view_diary.pl
74
+ css_selectors: dl.commentList01
75
+ params:
76
+ - id
77
+ - owner_id
78
+ regexp: show_friend.pl.*?>(.*?)<.*?commentTitleDate">(.*?)<\/span.*?<dd>(.*?)<\/dd>
79
+ variables:
80
+ - name
81
+ - date
82
+ - body
83
+
84
+ new_friend_diary:
85
+ caption: マイミクの最新日記リスト
86
+ path: new_friend_diary.pl
87
+ css_selectors:
88
+ - ul.entryList01
89
+ - li
90
+ regexp: <dt>(.*?)<\/dt>.*?id=(\d+).*?owner_id=(\d+)">(.*?)<\/a>\s\((.*?)\)
91
+ variables:
92
+ - date
93
+ - id
94
+ - owner_id
95
+ - title
96
+ - name
97
+
98
+
99
+ new_friend_diary_next_page_param:
100
+ cation: マイミクの最新日記リスト:次ページへのデータ
101
+ path: new_friend_diary.pl
102
+ params_opt:
103
+ - page
104
+ - direction
105
+ - position
106
+ - post_key
107
+ css_selectors:
108
+ - div.pageNavigation01
109
+ - div.pageList02
110
+ - li
111
+ regexp: <li>.*?page=(.*?)&direction=(.*?)&position=(.*?)&post_key=(.*?)">.*?</li>
112
+ variables:
113
+ - page
114
+ - direction
115
+ - position
116
+ - post_key
117
+
118
+
119
+
120
+ # コメント履歴
121
+ new_comment:
122
+ path: new_comment.pl
123
+ css_selectors:
124
+ - li.odd
125
+ - dl
126
+ regexp: <dt>(.*?)<\/dt>.*?id=(.*?)&owner_id=(.*)&.*?=(\d+?)">(.*?)<\/a.*?\((.*?)\)
127
+ variables:
128
+ - date
129
+ - id
130
+ - owner_id
131
+ - comment_count
132
+ - title
133
+ - name
134
+
135
+ # 足跡
136
+ show_log:
137
+ path: show_log.pl
138
+ css_selectors:
139
+ - ul.log
140
+ - li
141
+ regexp: <li style=.*?>(.*?)<.*?>(.*?)</
142
+ variables:
143
+ - date
144
+ - name
145
+
146
+
147
+ # マイミクリスト
148
+ list_friend:
149
+ path: list_friend.pl
150
+ params_opt:
151
+ - page
152
+ - id
153
+ css_selectors:
154
+ - div.iconList03
155
+ - li
156
+ regexp: <a.*?id=(.*?)".*?title="(.*?)"
157
+ variables:
158
+ - id
159
+ - name
160
+
161
+
162
+ # コメントの追加
163
+ add_comment:
164
+ path: add_comment.pl
165
+ method: post
166
+ params:
167
+ - diary_id
168
+ - owner_id
169
+ - comment_body
170
+ css_selectors:
171
+ - div.alertArea
172
+ - p
173
+ regexp: 書き込みが完了しました。
174
+
175
+ # 日記の書き込み
176
+ add_diary:
177
+ path: add_diary.pl
178
+ method: post
179
+ params:
180
+ - id # owner_id
181
+ - diary_title
182
+ - diary_body
183
+ - submit
184
+ css_selectors:
185
+ - div.alertArea
186
+ - p
187
+ regexp: 書き込みが完了しました。
188
+
189
+ # 日記の編集
190
+ edit_diary:
191
+ path: edit_diary.pl
192
+ method: post
193
+ params:
194
+ - id
195
+ - diary_title
196
+ - diary_body
197
+ - submit
198
+ css_selectors:
199
+ - div.alertArea
200
+ - p
201
+ regexp: 編集が完了しました。
@@ -0,0 +1,202 @@
1
+ #ページ定義データベース(YAML)
2
+ #name: # 定義名
3
+ # path: # パス(FQDN以降)
4
+ # method: # メソッド(デフォはget)
5
+ # params: # 必要なURLパラメータ(配列)
6
+ # - param # パラメータ名
7
+ # params_opt: # オプションのパラメータ
8
+ # css_selecters: # 選択するCSS(配列)
9
+ # - div.title
10
+ # regexp:(.*?) # 選択したCSSからデータを取得する為の正規表現。(後方参照を取得)
11
+ # variables: # 取得した後方参照を配列に格納する時の名前(配列)
12
+ # - body
13
+ login:
14
+ path: login.pl
15
+ method: post
16
+ params:
17
+ - email
18
+ - password
19
+ - next_url
20
+ css_selectors: meta
21
+ regexp: http-equiv="(.*?)"
22
+
23
+ # home
24
+ # ログインできてないと action="login" のフォームが表示される
25
+ # ログインしているかどうかのチェック用
26
+ home_form:
27
+ path: home.pl
28
+ css_selectors: form
29
+ regexp: action="(.*?)"
30
+
31
+ # 新着メッセージ
32
+ home_new_comment:
33
+ path: home.pl
34
+ css_selectors:
35
+ - div.contents
36
+ - ul
37
+ - dd
38
+ regexp: view_diary.pl\?id=(\d+?)&
39
+
40
+ # 日記リスト
41
+ # id がない場合は自分の日記
42
+ list_diary:
43
+ path: list_diary.pl
44
+ params_opt:
45
+ - id
46
+ css_selectors:
47
+ - div.listDiaryTitle
48
+ - dl.clearfix
49
+ regexp: <a.*?id=(\d+?)&.*?>(.*?)<.*?<dd>(.*?)<
50
+ variables:
51
+ - id
52
+ - title
53
+ - date
54
+
55
+ # 日記本文
56
+ view_diary_diary:
57
+ path: main/view_diary
58
+ params:
59
+ - id
60
+ - owner_id
61
+ css_selectors:
62
+ - div.viewDiaryBox
63
+ regexp: <dt>(.*?)<.*<dd>(.*?)<\/dd>.*id="diary_body"*?>(.*?)<\/div>
64
+ variables:
65
+ - title
66
+ - date
67
+ - body
68
+
69
+ # 日記のコメント部分
70
+ view_diary_comment:
71
+ path: view_diary
72
+ css_selectors: dl.commentList01
73
+ params:
74
+ - id
75
+ - owner_id
76
+ regexp: show_friend.pl.*?>(.*?)<.*?commentTitleDate">(.*?)<\/span.*?<dd>(.*?)<\/dd>
77
+ variables:
78
+ - name
79
+ - date
80
+ - body
81
+
82
+ new_friend_diary:
83
+ caption: マイミクの最新日記リスト
84
+ path: main/new_friend_diary
85
+ css_selectors:
86
+ - ul.entryList01
87
+ - li
88
+ regexp: <dt>(.*?)<\/dt>.*?id=(\d+).*?owner_id=(\d+)">(.*?)<\/a>\s\((.*?)\)
89
+ variables:
90
+ - date
91
+ - id
92
+ - owner_id
93
+ - title
94
+ - name
95
+
96
+
97
+ new_friend_diary_next_page_param:
98
+ cation: マイミクの最新日記リスト:次ページへのデータ
99
+ path: main/new_friend_diary
100
+ params_opt:
101
+ - page
102
+ - direction
103
+ - position
104
+ - post_key
105
+ css_selectors:
106
+ - div.pageNavigation01
107
+ - div.pageList02
108
+ - li
109
+ regexp: <li>.*?page=(.*?)&direction=(.*?)&position=(.*?)&post_key=(.*?)">.*?</li>
110
+ variables:
111
+ - page
112
+ - direction
113
+ - position
114
+ - post_key
115
+ #a href=new_friend_diary.pl?page=3&direction=next&position=102&post_key=c7b37a5df844537157fdd9e56643d0f2>
116
+
117
+ # params_opt:
118
+ # - page
119
+ # - direction
120
+ # - position
121
+ # - post_key
122
+ # css_selectors_opt:
123
+ # - div.pageNavigation01
124
+ # - div.pageList02
125
+ # - li
126
+ # regexp_opt: <li>.*?page=(.*?)&direction=next&position=(.*?)&post_key=(.*?)">.*</li>
127
+ # variables_opt:
128
+ # - page
129
+ # - direction
130
+ # - position
131
+ # - post_key
132
+ # #<a href="new_friend_diary.pl?page=2&direction=next&position=50&post_key=afc823efeee833048e453c93911f057c
133
+
134
+
135
+
136
+
137
+ # コメント履歴
138
+ new_comment:
139
+ path: new_comment.pl
140
+ css_selectors:
141
+ - li.odd
142
+ - dl
143
+ regexp: <dt>(.*?)<\/dt>.*?id=(.*?)&owner_id=(.*)&.*?=(\d+?)">(.*?)<\/a.*?\((.*?)\)
144
+ variables:
145
+ - date
146
+ - id
147
+ - owner_id
148
+ - comment_count
149
+ - title
150
+ - name
151
+
152
+ # 足跡
153
+ show_log:
154
+ path: show_log.pl
155
+ css_selectors:
156
+ - ul.log
157
+ - li
158
+ regexp: <li style=.*?>(.*?)<.*?>(.*?)</
159
+ variables:
160
+ - date
161
+ - name
162
+
163
+ # コメントの追加
164
+ add_comment:
165
+ path: add_comment.pl
166
+ method: post
167
+ params:
168
+ - diary_id
169
+ - owner_id
170
+ - comment_body
171
+ css_selectors:
172
+ - div.alertArea
173
+ - p
174
+ regexp: 書き込みが完了しました。
175
+
176
+ # 日記の書き込み
177
+ add_diary:
178
+ path: add_diary.pl
179
+ method: post
180
+ params:
181
+ - id # owner_id
182
+ - diary_title
183
+ - diary_body
184
+ - submit
185
+ css_selectors:
186
+ - div.alertArea
187
+ - p
188
+ regexp: 書き込みが完了しました。
189
+
190
+ # 日記の編集
191
+ edit_diary:
192
+ path: edit_diary.pl
193
+ method: post
194
+ params:
195
+ - id
196
+ - diary_title
197
+ - diary_body
198
+ - submit
199
+ css_selectors:
200
+ - div.alertArea
201
+ - p
202
+ regexp: 編集が完了しました。