Class: Mixi::Community::Fetcher

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

Constant Summary collapse

DEFAULT_USER_AGENT =
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1'

Instance Method Summary collapse

Constructor Details

#initialize(user_id, password, user_agent = DEFAULT_USER_AGENT) ⇒ Fetcher

Returns a new instance of Fetcher.



139
140
141
142
143
144
145
# File 'lib/mixi-community.rb', line 139

def initialize user_id, password, user_agent = DEFAULT_USER_AGENT
  @user_id = user_id
  @password = password
  @agent = Mechanize.new
  @agent.user_agent = user_agent
  @agent.follow_meta_refresh = true
end

Instance Method Details

#get(uri) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/mixi-community.rb', line 146

def get(uri)
  raise "invalid arg" unless uri.host == 'mixi.jp'
  page_encoding = 'euc-jp'

  page = @agent.get(uri)
  page.encoding = page_encoding
   = page.form_with(name: 'login_form')
  if 
    .email = @user_id
    .password = @password
    .submit

    page = @agent.page
    page.encoding = page_encoding
  end
  page
end