Class: Twitter2MixiVoice::Mixi

Inherits:
Object
  • Object
show all
Defined in:
lib/mixi.rb

Overview

This class provides mixi functions.

Constant Summary collapse

VOICE_MAX_LENGTH =
150

Instance Method Summary collapse

Constructor Details

#initialize(email, password) ⇒ Mixi

Create Mixi class instance.

Raises:



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.

Raises:



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(message)
  
  # check parameter
  raise MixiException.new("Invalid 'message' parameter.") if message.nil? || message.empty? || message.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 = message
      form.click_button
    end
  rescue Exception => e
    raise MixiException.new(e.to_s)
  end
  
end