Class: Mixi::Community::Fetcher
- Inherits:
-
Object
- Object
- Mixi::Community::Fetcher
- 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
- #get(uri) ⇒ Object
-
#initialize(user_id, password, user_agent = DEFAULT_USER_AGENT) ⇒ Fetcher
constructor
A new instance of Fetcher.
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. = 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 login_form = page.form_with(name: 'login_form') if login_form login_form.email = @user_id login_form.password = @password login_form.submit page = @agent.page page.encoding = page_encoding end page end |