Class: GREE::Community::Fetcher
- Inherits:
-
Object
- Object
- GREE::Community::Fetcher
- Defined in:
- lib/gree-community.rb
Constant Summary collapse
- 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) ⇒ Fetcher
constructor
A new instance of Fetcher.
Constructor Details
#initialize(user_id, password) ⇒ Fetcher
Returns a new instance of Fetcher.
80 81 82 83 84 85 |
# File 'lib/gree-community.rb', line 80 def initialize user_id, password @user_id = user_id @password = password @agent = Mechanize.new @agent.user_agent = USER_AGENT end |
Instance Method Details
#get(uri) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/gree-community.rb', line 86 def get(uri) raise "invalid arg" unless uri.host == 'gree.jp' page_encoding = 'EUC-JP-MS' page = @agent.get(uri) page.encoding = page_encoding unless page.uri == uri login_form = page.form_with(name: 'login') raise "Login form not found: uri=#{uri} redirected=#{page.uri}" unless login_form login_uri = page.uri login_form.user_mail = @user_id login_form.user_password = @password login_form.submit page = @agent.page page.encoding = page_encoding raise "Login failed or something: uri=#{uri} login=#{login_uri} last=#{page.uri}" unless page.uri == uri end page end |