Class: Timelog4r
- Inherits:
-
Object
- Object
- Timelog4r
- Includes:
- Utils
- Defined in:
- lib/timelog4r.rb,
lib/timelog4r/utils.rb,
lib/timelog4r/version.rb,
lib/timelog4r/xml_parser.rb,
lib/timelog4r/html_parser.rb
Overview
Timelog4r is TimelogAPI for ruby.
see example/*.rb
about TimelogAPI
http://timelog.jp/api.asp
Defined Under Namespace
Modules: HTML_Parser, Utils, VERSION, XML_Parser
Constant Summary collapse
- BaseAddress =
TimelogAPI’s BaseURI.
'http://api.timelog.jp/'
- WebAddress =
'http://timelog.jp/'
Instance Attribute Summary collapse
-
#agent ⇒ Object
- OPTIONAL
-
WEB Accessor Agent.
-
#password ⇒ Object
- REQUIRED
-
Set your Timelog PassWord.
-
#private_key ⇒ Object
- OPTIONAL
-
WEB Access used PrivateKey.
-
#use_accessor ⇒ Object
- REQUIRED
-
TimelogAPI Use-Flag.
-
#user_agent ⇒ Object
- OPTIONAL
-
Set your Program’s ‘UserAgent’.
-
#user_id ⇒ Object
- REQUIRED
-
Set your Timelog User-ID.
Instance Method Summary collapse
-
#get(url) ⇒ Object
:nodoc:.
-
#get_direct_messages(options = nil) ⇒ Object
- Description
-
get direct messages.
-
#get_fan_list(options = nil) ⇒ Object
- Description
-
get fan list.
-
#get_friend_list(options = nil) ⇒ Object
- Description
-
get friends list.
-
#get_friends_timeline(options = nil) ⇒ Object
- Description
-
get user and friends timeline.
-
#get_memo_clip(options = nil) ⇒ Object
- Description
-
get my memo-clips.
-
#get_memofriend_list(options = nil) ⇒ Object
- Description
-
get memofriend_list.
-
#get_my_timeline(options = nil) ⇒ Object
- Description
-
get my timeline.
-
#get_private_key ⇒ Object
- Description
-
get private key.(web accessor only.).
-
#get_profile(user_id = @user_id) ⇒ Object
- Description
-
get my profile.
-
#get_public_timeline(options = nil) ⇒ Object
- Description
-
get public timeline.
-
#get_reply_list(options = nil) ⇒ Object
- Description
-
get reply to my memos.
-
#get_tag_list(options = nil) ⇒ Object
- Description
-
get tag list.
-
#initialize(use_accessor = :web) ⇒ Timelog4r
constructor
Customized XML-Parser.
-
#join_group(group_id) ⇒ Object
- Description
-
join to group.
-
#joined?(group_id) ⇒ Boolean
- Description
-
this group joined?.
-
#leave_group(group_id) ⇒ Object
- Description
-
leave for group.
-
#login(account = @user_id, password = @password) ⇒ Object
- Description
-
login for timelog.jp.(use web only).
-
#login? ⇒ Boolean
- Description
-
timelog.jp logined?(use web only.).
-
#post(url, query) ⇒ Object
:nodoc:.
-
#send_message(text, to, res_id = nil, tags = nil) ⇒ Object
- Description
-
send a direct message to timelog-user.
-
#set_tags(text, tags) ⇒ Object
- Description
-
set tags to text.
-
#set_todo(text, group_id, time, res_id = nil, tags = nil) ⇒ Object
- Description
-
update memo type of todo.
-
#update(text, group_id = nil, res_id = nil, tags = nil) ⇒ Object
- Description
-
update memo.
-
#update_bookmark(text, group_id, uri, res_id = nil, tags = nil) ⇒ Object
- Description
-
update memo type of bookmark.
-
#update_good(text, group_id, res_id = nil, tags = nil) ⇒ Object
- Description
-
update memo type of good.
-
#update_news(text, group_id, res_id = nil, tags = nil) ⇒ Object
- Description
-
update memo type of news.
-
#update_vote(text, group_id, res_id = nil, tags = nil) ⇒ Object
- Description
-
update memo type of vote.
Methods included from Utils
#create_request, #create_uri, #http_access, #parse_options
Constructor Details
#initialize(use_accessor = :web) ⇒ Timelog4r
Customized XML-Parser. include XML_Parser
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/timelog4r.rb', line 42 def initialize(use_accessor = :web) #:nodoc: @user_agent = 'timelog4r' case use_accessor when :api @use_accessor = :api self.extend XML_Parser when :web @use_accessor = :web @agent = Mechanize.new @agent.user_agent = @user_agent self.extend HTML_Parser end end |
Instance Attribute Details
#agent ⇒ Object
- OPTIONAL
-
WEB Accessor Agent.
31 32 33 |
# File 'lib/timelog4r.rb', line 31 def agent @agent end |
#password ⇒ Object
- REQUIRED
-
Set your Timelog PassWord.
25 26 27 |
# File 'lib/timelog4r.rb', line 25 def password @password end |
#private_key ⇒ Object
- OPTIONAL
-
WEB Access used PrivateKey.
29 30 31 |
# File 'lib/timelog4r.rb', line 29 def private_key @private_key end |
#use_accessor ⇒ Object
- REQUIRED
-
TimelogAPI Use-Flag.
27 28 29 |
# File 'lib/timelog4r.rb', line 27 def use_accessor @use_accessor end |
#user_agent ⇒ Object
- OPTIONAL
-
Set your Program’s ‘UserAgent’.
21 22 23 |
# File 'lib/timelog4r.rb', line 21 def user_agent @user_agent end |
#user_id ⇒ Object
- REQUIRED
-
Set your Timelog User-ID.
23 24 25 |
# File 'lib/timelog4r.rb', line 23 def user_id @user_id end |
Instance Method Details
#get(url) ⇒ Object
:nodoc:
786 787 788 789 |
# File 'lib/timelog4r.rb', line 786 def get(url) #:nodoc: return false if @use_accessor.eql?(:api) return @agent.get(url) end |
#get_direct_messages(options = nil) ⇒ Object
- Description
-
get direct messages
- Params
-
options
:cnt => message_count [Fixnum]
[Hash] default nil
- Return
-
=> ‘Timelog … ’, :entries => […]
- RelatedMethods
-
Utils#parse_options Utils#create_uri Utils#create_request Utils#http_access XML_Parser#parse_timeline
387 388 389 390 391 392 393 394 395 |
# File 'lib/timelog4r.rb', line 387 def ( = nil) address = BaseAddress + 'direct_msg.asp' address += () if uri = create_uri(address) request = create_request(:get, uri, true) response = http_access(uri, request) result = parse_timeline(response) if response return result end |
#get_fan_list(options = nil) ⇒ Object
- Description
-
get fan list
- Params
-
options
:cnt => user_count(1-50 or all) [String], :ac => target_user [String]
[Hash] default nil
- Return
-
=> ‘Timelog … ’, :entries => […]
- RelatedMethods
-
Utils#parse_options Utils#create_uri Utils#create_request Utils#http_access XML_Parser#parse_user_list
298 299 300 301 302 303 304 305 306 |
# File 'lib/timelog4r.rb', line 298 def get_fan_list( = nil) address = BaseAddress + 'fan.asp' address += () if uri = create_uri(address) request = create_request(:get, uri, true) response = http_access(uri, request) result = parse_user_list(response) if response return result end |
#get_friend_list(options = nil) ⇒ Object
- Description
-
get friends list
- Params
-
options
:cnt => friend_count(1-50 or all) [String], :ac => target_user [String]
[Hash] default nil
- Return
-
=> ‘Timelog … ’, :entries => […]
- RelatedMethods
-
Utils#parse_options Utils#create_uri Utils#create_request Utils#http_access XML_Parser#parse_user_list
267 268 269 270 271 272 273 274 275 |
# File 'lib/timelog4r.rb', line 267 def get_friend_list( = nil) address = BaseAddress + 'friends.asp' address += () if uri = create_uri(address) request = create_request(:get, uri, true) response = http_access(uri, request) result = parse_user_list(response) if response return result end |
#get_friends_timeline(options = nil) ⇒ Object
- Description
-
get user and friends timeline
- Params
-
options
:cnt => entry_count [Fixnum], :since => entry_after_since [Time], :hc => favorites disp-flag(0|1) [Fixnum]
[Hash] default nil
- Return
-
=> ‘Timelog … ’, :entries => […]
- RelatedMethods
-
Utils#parse_options Utils#create_uri Utils#create_request Utils#http_access XML_Parser#parse_timeline
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/timelog4r.rb', line 123 def get_friends_timeline( = nil) case @use_accessor when :api address = BaseAddress + 'friends_msg.asp' address += () if uri = create_uri(address) request = create_request(:get, uri, true) response = http_access(uri, request) result = parse_timeline(response) if response when :web address = 'http://'+ @user_id +'.timelog.jp/home/' response = @agent.get(address) result = parse_timeline(response.body) if response end return result end |
#get_memo_clip(options = nil) ⇒ Object
- Description
-
get my memo-clips
- Params
-
options =
:cnt => entry_count [Fixnum], :hc => favorites disp-flag(0|1) [Fixnum]
[Hash] default nil
- Return
-
=> ‘Timelog … ’, :entries => {… }
- RelatedMethods
-
Utils#parse_options Utils#create_uri Utils#create_request Utils#http_access XML_Parser#parse_timeline
205 206 207 208 209 210 211 212 213 |
# File 'lib/timelog4r.rb', line 205 def get_memo_clip( = nil) address = BaseAddress + 'clip_msg.asp' address += () if uri = create_uri(address) request = create_request(:get, uri, true) response = http_access(uri, request) result = parse_timeline(response) if response return result end |
#get_memofriend_list(options = nil) ⇒ Object
- Description
-
get memofriend_list
- Params
-
options =
:cnt => entry_count(1-50 or all)[String], :ac => target_user[String]
[Hash] default nil
- Return
-
=> ‘Timelog …’, :entries => […]
- RelatedMethods
326 327 328 329 330 331 332 333 334 |
# File 'lib/timelog4r.rb', line 326 def get_memofriend_list( = nil) address = BaseAddress + 'memofriends.asp' address += () if uri = create_uri(address) request = create_request(:get, uri, true) response = http_access(uri, request) result = parse_user_list(response) if response return result end |
#get_my_timeline(options = nil) ⇒ Object
- Description
-
get my timeline
- Params
-
options
:cnt => entry_count [Fixnum], :stat => entry_tipe [String], :since => entry_after_since [Time], :tag => find_entries_from_tag [String], :hc => favorites disp-flag(0|1) [Fixnum]
[Hash] default nil
- Return
-
=> ‘Timelog … ’, :entries => […]
- RelatedMethods
-
Utils#parse_options Utils#create_uri Utils#create_request Utils#http_access XML_Parser#parse_timeline
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/timelog4r.rb', line 166 def get_my_timeline( = nil) case @user_accessor when :api address = BaseAddress + 'my_msg.asp' address += () if uri = create_uri(address) request = create_request(:get, uri, true) response = http_access(uri, request) result = parse_timeline(response) if response when :web address = 'http://'+ @user_id +'.timelog.jp/personal.asp' response = @agent.get(address) result = parse_timeline(response.body) if response end return result end |
#get_private_key ⇒ Object
- Description
-
get private key.(web accessor only.)
- Return
-
private key(String)
724 725 726 727 728 729 |
# File 'lib/timelog4r.rb', line 724 def get_private_key() home_view = 'http://'+ @user_id + '.timelog.jp/home/' home = @agent.get(home_view) main_form = home.forms.first return main_form['inp_key'] end |
#get_profile(user_id = @user_id) ⇒ Object
- Description
-
get my profile
- Return
-
=> ‘Timelog … ’, :user => {… }
- RelatedMethods
-
Utils#parse_options Utils#create_uri Utils#create_request Utils#http_access XML_Parser#parse_profile
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/timelog4r.rb', line 230 def get_profile(user_id = @user_id) case @use_accessor when :api address = BaseAddress + 'show.asp' uri = create_uri(address) request = create_request(:get, uri, true) response = http_access(uri, request) result = parse_profile(response) if response when :web address = 'http://'+ @user_id +'.timelog.jp/profile.asp' response = @agent.get(address) result = parse_profile(response.body) if response end return result end |
#get_public_timeline(options = nil) ⇒ Object
- Description
-
get public timeline
- Params
-
options
:cnt => entry_count [Fixnum], :stat => entry_type(:bm|:gn) [String], :since => entry_after_since [Time], :hc => favorites disp-flag(0|1) [Fixnum]
[Hash] default nil
- Return
-
=> ‘Timelog … ’, entries => […]
- RelatedMethods
-
Utils#parse_options Utils#create_uri Utils#create_request Utils#http_access XML_Parser#parse_timeline
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/timelog4r.rb', line 81 def get_public_timeline( = nil) result = nil case @use_accessor when :api address = BaseAddress + 'public_msg.asp' address += () if uri = create_uri(address) request = create_request(:get, uri) response = http_access(uri, request) result = parse_timeline(response) if response when :web address = 'http://'+@user_id+'.timelog.jp/home/public.asp' response = @agent.get(address) result = parse_timeline(response.body) if response end return result end |
#get_reply_list(options = nil) ⇒ Object
- Description
-
get reply to my memos
- Params
-
options
:cnt => entry_count [Fixnum], :hc => favorites disp-flag(0|1) [Fixnum]
[Hash] default nil
- Return
-
=> ‘Timelog … ’, :entries => […]
- RelatedMethods
-
Utils#parse_options Utils#create_uri Utils#create_request Utils#http_access XML_Parser#parse_timeline
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
# File 'lib/timelog4r.rb', line 418 def get_reply_list( = nil) case @use_accessor when :api address = BaseAddress + 'res_msg.asp' address += () if uri = create_uri(address) request = create_request(:get, uri, true) response = http_access(uri, request) result = parse_timeline(response) if response when :web address = 'http://'+ @user_id +'.timelog.jp/resmsg.asp' response = @agent.get(address) result = parse_timeline(response.body) if response end return result end |
#get_tag_list(options = nil) ⇒ Object
- Description
-
get tag list
- Params
-
options
:cnt => tag_count [Fixnum], :stat => sort from tag_count(asc|desc) [String]
[Hash] default nil
- Return
-
=> ‘Timelog … ’, :tags => […]
- RelatedMethods
-
Utils#parse_options Utils#create_uri Utils#create_request Utils#http_access XML_Parser#parse_tag_list
357 358 359 360 361 362 363 364 365 |
# File 'lib/timelog4r.rb', line 357 def get_tag_list( = nil) address = BaseAddress + 'tags.asp' address += () if uri = create_uri(address) request = create_request(:get, uri, true) response = http_access(uri, request) result = parse_tag_list(response) if response return result end |
#join_group(group_id) ⇒ Object
- Description
-
join to group.
- Argments
-
:group_id join to group. [String] (Requirement)
- Return
-
true (case of join to group success.)
761 762 763 764 765 766 |
# File 'lib/timelog4r.rb', line 761 def join_group(group_id) group_view = 'http://' + group_id + '.timelog.jp/' join_url = group_view + 'addfriend.asp?ac=' + group_id @agent.get(join_url) return true end |
#joined?(group_id) ⇒ Boolean
- Description
-
this group joined?
- Argments
-
:group_id check group_id [String] (Requiement)
- Return
-
true (case of this group joined.) false (case of this group not joined.)
743 744 745 746 747 748 |
# File 'lib/timelog4r.rb', line 743 def joined?(group_id) group_view = 'http://' + group_id + '.timelog.jp/' joined_element = 'li#del' group_page = @agent.get(group_view) return group_page.at(joined_element) ? true : false end |
#leave_group(group_id) ⇒ Object
- Description
-
leave for group.
- Argments
-
:group_id leave for group. (Requirement)
- Return
-
true (case of leave for group success.)
779 780 781 782 783 784 |
# File 'lib/timelog4r.rb', line 779 def leave_group(group_id) group_view = 'http://' + group_id + '.timelog.jp/' leave_url = group_view + 'delfriend.asp?ac=' + group_id @agent.get(leave_url) return true end |
#login(account = @user_id, password = @password) ⇒ Object
- Description
-
login for timelog.jp.(use web only)
- Params
-
:account login user’s account [String] defualt @user_id :password login user’s password [String] default @password
- Return
-
true (case of ‘login success.’) false (case of ‘login denny.’)
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 |
# File 'lib/timelog4r.rb', line 680 def login(account = @user_id, password = @password) login_view = WebAddress + 't_login.asp' login_url = WebAddress + 'login.asp' login_form = @agent.get(login_view).forms.first login_form['inp_ac'] = account login_form['inp_pw'] = password login_form['inp_red'] = login_view =begin if login_form.valid? then login_form.click_button(login_form.buttons.first) @private_key = get_private_key return true else return false end =end login_form.submit #click_button(login_form.buttons.first) @private_key = get_private_key return true end |
#login? ⇒ Boolean
- Description
-
timelog.jp logined?(use web only.)
- Return
-
true (case of ‘logined.’) false (case of ‘not logined.’)
710 711 712 713 714 |
# File 'lib/timelog4r.rb', line 710 def login?() home_view = 'http://'+ @user_id + '.timelog.jp/home/' home = @agent.get(home_view) return home.forms.first.name.eql?('frmBox') end |
#post(url, query) ⇒ Object
:nodoc:
791 792 793 794 |
# File 'lib/timelog4r.rb', line 791 def post(url, query) #:nodoc: return false if @use_accessor.eql?(:api) return @agent.post(url, query) end |
#send_message(text, to, res_id = nil, tags = nil) ⇒ Object
- Description
-
send a direct message to timelog-user.
- Params
-
:text memo’s body [String] :to send to timelog user_id [String] :res_id response to memo_id [String] default nil :tags update tags [Array] default nil
- Return
-
true (case of ‘send message success’) false (case of ‘send message failed’)
- RelatedMethods
-
update
531 532 533 534 |
# File 'lib/timelog4r.rb', line 531 def (text, to, res_id = nil, = nil) text = '/d @' + to + ' ' + text update(text, res_id, ) end |
#set_tags(text, tags) ⇒ Object
- Description
-
set tags to text.
- Params
-
:text memo’s body [String] :tags set tags [Array]
- Return
-
text [String]
448 449 450 451 |
# File 'lib/timelog4r.rb', line 448 def (text, ) text += '[' + .join(',') + ']' return text end |
#set_todo(text, group_id, time, res_id = nil, tags = nil) ⇒ Object
- Description
-
update memo type of todo.
- Params
-
:text memo’s body [String] :time todo end-time [Time] :res_id response to memo_id [String] default nil :tags update tags [Array] default nil
- Return
-
true (case of ‘update success’) false (case of ‘update failed’)
- RelatedMethods
-
update
556 557 558 559 560 561 562 |
# File 'lib/timelog4r.rb', line 556 def set_todo(text, group_id, time, res_id = nil, = nil) text = '/t ' + time.strftime('%Y%m%d%H%M') + ' ' + text + ' #' + group_id update(text, res_id, ) end |
#update(text, group_id = nil, res_id = nil, tags = nil) ⇒ Object
- Description
-
update memo. insert :text in ‘Timelog Command’ Support.
- Params
-
:text memo’s body [Stirng] :res_id response to memo_id [String] default nil :tags update tags [Array] default nil
- Return
-
true (case of ‘update success’) false (case of ‘update failed’)
- RelatedMethods
-
set_tags Utils#parse_options Utils#create_uri Utils#create_request Utils#http_access
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
# File 'lib/timelog4r.rb', line 477 def update(text, group_id = nil, res_id = nil, = nil) case @use_accessor when :api text = (text, ) if text += ' #'+group_id if group_id params = {:text => text} params[:remsgid] = res_id if res_id address = BaseAddress + 'new.asp' + (params) uri = create_uri(address) request = create_request(:post, uri, true) response = http_access(uri, request) return !response.nil? when :web post_view = 'http://'+@user_id+'.timelog.jp' post_url = WebAddress + '/home/postb.asb' post_form = @agent.get(post_view).forms.first text = (text, ) if post_form['inp_exm'] = '0' post_form['sel_Type'] = '0' post_form['inp_Public'] = '0' post_form['t'] = '1' post_form['inp_refresh'] = '0' post_form['inp_stag'] = '' # post_form['inp_gi'] = group_id ? group_id : '' post_form['inp_Grp'] = group_id ? group_id : '' post_form['inp_key'] = @private_key post_form['inp_remsgid'] = res_id ? res_id : '' post_form['inp_msg'] = text # message! post_form.submit end end |
#update_bookmark(text, group_id, uri, res_id = nil, tags = nil) ⇒ Object
- Description
-
update memo type of bookmark.
- Params
-
:text memo’s body [String] :uri bookmarks uri [URI] :res_id response to memo_id [String] default nil :tags update tags [Array] default nil
- Return
-
true (case of ‘update success’) false (case of ‘update failed’)
- RelatedMethods
-
update
584 585 586 587 588 |
# File 'lib/timelog4r.rb', line 584 def update_bookmark(text, group_id, uri, res_id = nil, = nil) text = '/b ' + uri.to_s + ' ' + text + ' #' + group_id update(text, res_id, ) end |
#update_good(text, group_id, res_id = nil, tags = nil) ⇒ Object
- Description
-
update memo type of good.
- Params
-
:text memo’s body [String] :res_id response to memo_id [String] default nil :tags update tags [Array] default nil
- Return
-
true (case of ‘update success’) false (case of ‘update failed’)
- RelatedMethods
-
update
609 610 611 612 613 |
# File 'lib/timelog4r.rb', line 609 def update_good(text, group_id, res_id = nil, = nil) text = '/g ' + text + " #" + group_id update(text, res_id, ) end |
#update_news(text, group_id, res_id = nil, tags = nil) ⇒ Object
- Description
-
update memo type of news.
- Params
-
:text memo’s body [String] :res_id response to memo_id [String] default nil :tags update tags [Array] default nil
- Return
-
true (case of ‘update success’) false (case of ‘update failed’)
- RelatedMethods
-
update
634 635 636 637 638 |
# File 'lib/timelog4r.rb', line 634 def update_news(text, group_id, res_id = nil, = nil) text = '/n ' + text + " #" + group_id update(text, res_id, ) end |
#update_vote(text, group_id, res_id = nil, tags = nil) ⇒ Object
- Description
-
update memo type of vote.
- Params
-
:text memo’s body [String] :res_id response to memo_id [String] default nil :tags update tags [Array] default nil
- Return
-
true (case of ‘update success’) false (case of ‘update failed’)
- RelatedMethods
-
update
659 660 661 662 663 |
# File 'lib/timelog4r.rb', line 659 def update_vote(text, group_id, res_id = nil, = nil) text = '/j ' + text + " #" + group_id update(text, res_id, ) end |