Class: XiamiRadio::User
- Inherits:
-
Object
- Object
- XiamiRadio::User
- Includes:
- Singleton
- Defined in:
- lib/xiami_radio/user.rb
Overview
There is a user as you saw
Instance Attribute Summary collapse
-
#cookie_jar ⇒ Object
Returns the value of attribute cookie_jar.
-
#is_vip ⇒ Object
readonly
Returns the value of attribute is_vip.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#nick_name ⇒ Object
readonly
Returns the value of attribute nick_name.
-
#sign ⇒ Object
readonly
Returns the value of attribute sign.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
Instance Method Summary collapse
-
#initialize ⇒ User
constructor
A new instance of User.
- #login? ⇒ Boolean
- #login_by_email(email, password) ⇒ Object
- #login_by_member_auth(member_auth) ⇒ Object
- #xiami_token ⇒ Object
Constructor Details
#initialize ⇒ User
Returns a new instance of User.
11 12 13 14 15 |
# File 'lib/xiami_radio/user.rb', line 11 def initialize @cookie_jar = HTTP::CookieJar.new @cookie_jar.load if File.exist? get_user_info end |
Instance Attribute Details
#cookie_jar ⇒ Object
Returns the value of attribute cookie_jar.
9 10 11 |
# File 'lib/xiami_radio/user.rb', line 9 def @cookie_jar end |
#is_vip ⇒ Object (readonly)
Returns the value of attribute is_vip.
8 9 10 |
# File 'lib/xiami_radio/user.rb', line 8 def is_vip @is_vip end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
8 9 10 |
# File 'lib/xiami_radio/user.rb', line 8 def level @level end |
#nick_name ⇒ Object (readonly)
Returns the value of attribute nick_name.
8 9 10 |
# File 'lib/xiami_radio/user.rb', line 8 def nick_name @nick_name end |
#sign ⇒ Object (readonly)
Returns the value of attribute sign.
8 9 10 |
# File 'lib/xiami_radio/user.rb', line 8 def sign @sign end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
8 9 10 |
# File 'lib/xiami_radio/user.rb', line 8 def user_id @user_id end |
Instance Method Details
#login? ⇒ Boolean
17 18 19 |
# File 'lib/xiami_radio/user.rb', line 17 def login? !user_id.to_s.empty? end |
#login_by_email(email, password) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/xiami_radio/user.rb', line 21 def login_by_email(email, password) page_uri = login_client.uri(path: '/member/login') form_uri = login_client.uri(path: '/passport/login') login_client.get page_uri, format: :html form_data = { _xiamitoken: xiami_token, done: 'http%3A%2F%2Fwww.xiami.com%2F%2F', verifycode: '', account: email, pw: password, submit: '登录' } login_client.post form_uri, form_data, headers: { 'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8', 'Referer' => page_uri.to_s } @cookie_jar.save get_user_info end |
#login_by_member_auth(member_auth) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/xiami_radio/user.rb', line 41 def login_by_member_auth(member_auth) uri = client.uri path: '/index/home' @cookie_jar.parse "member_auth=#{member_auth}; path=/; domain=.xiami.com", uri client.get uri, format: :head @cookie_jar.save get_user_info end |
#xiami_token ⇒ Object
49 50 51 |
# File 'lib/xiami_radio/user.rb', line 49 def xiami_token ..select { |c| c.name == '_xiamitoken' }.first&.value end |