Class: Twitter2MixiVoice::Mixi
- Inherits:
-
Object
- Object
- Twitter2MixiVoice::Mixi
- Defined in:
- lib/mixi.rb
Overview
This class provides mixi functions.
Constant Summary collapse
- VOICE_MAX_LENGTH =
150
Instance Method Summary collapse
-
#initialize(email, password) ⇒ Mixi
constructor
Create Mixi class instance.
-
#post_voice(message) ⇒ Object
Post mixi voice.
Constructor Details
#initialize(email, password) ⇒ Mixi
Create Mixi class instance.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mixi.rb', line 29 def initialize(email, password) # check parameter. raise MixiException.new("Invalid 'email' parameter .") if email.nil? || email.empty? raise MixiException.new("Invalid 'password' parameter .") if password.nil? || password.empty? # login to mixi. begin @agent = WWW::Mechanize.new @agent.get("http://mixi.jp") @agent.page.form_with(:name => "login_form") do |form| form.field_with(:name => "email").value = email form.field_with(:name => "password").value = password form.submit end rescue Exception => e raise MixiException.new(e.to_s) end # check login error. error = @agent.page.at("div#errorArea") unless error.nil? raise MixiException.new(error.inner_text) end end |
Instance Method Details
#post_voice(message) ⇒ Object
Post mixi voice.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/mixi.rb', line 58 def post_voice() # check parameter raise MixiException.new("Invalid 'message' parameter.") if .nil? || .empty? || .split(//u).length > VOICE_MAX_LENGTH # post voice begin @agent.get("http://mixi.jp/recent_echo.pl") @agent.page.form_with(:action => "add_echo.pl") do |form| form.field_with(:name => "body").value = form. end rescue Exception => e raise MixiException.new(e.to_s) end end |