Class: GREE::Community::Fetcher

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(user_id, password) ⇒ Fetcher

Returns a new instance of Fetcher.



77
78
79
80
81
82
# File 'lib/gree-community.rb', line 77

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



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/gree-community.rb', line 83

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
     = page.form_with(name: 'login')
    raise "Login form not found: uri=#{uri} redirected=#{page.uri}" unless 

     = page.uri

    .user_mail = @user_id
    .user_password = @password
    .submit

    page = @agent.page
    page.encoding = page_encoding

    raise "Login failed or something: uri=#{uri} login=#{} last=#{page.uri}" unless page.uri == uri
  end
  page
end