Class: XiamiRadio::User
- Inherits:
-
Object
- Object
- XiamiRadio::User
- 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
- #client ⇒ Object
-
#initialize ⇒ User
constructor
A new instance of User.
- #login? ⇒ Boolean
- #login_by_email(email, password) ⇒ Object
- #login_by_member_auth(member_auth) ⇒ Object
- #radio(**args) ⇒ Object
- #xiami_token ⇒ Object
Constructor Details
#initialize ⇒ User
Returns a new instance of User.
9 10 11 12 13 |
# File 'lib/xiami_radio/user.rb', line 9 def initialize = HTTP::CookieJar.new .load if File.exist? get_user_info end |
Instance Attribute Details
#cookie_jar ⇒ Object
Returns the value of attribute cookie_jar.
7 8 9 |
# File 'lib/xiami_radio/user.rb', line 7 def end |
#is_vip ⇒ Object (readonly)
Returns the value of attribute is_vip.
6 7 8 |
# File 'lib/xiami_radio/user.rb', line 6 def is_vip @is_vip end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
6 7 8 |
# File 'lib/xiami_radio/user.rb', line 6 def level @level end |
#nick_name ⇒ Object (readonly)
Returns the value of attribute nick_name.
6 7 8 |
# File 'lib/xiami_radio/user.rb', line 6 def nick_name @nick_name end |
#sign ⇒ Object (readonly)
Returns the value of attribute sign.
6 7 8 |
# File 'lib/xiami_radio/user.rb', line 6 def sign @sign end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
6 7 8 |
# File 'lib/xiami_radio/user.rb', line 6 def user_id @user_id end |
Instance Method Details
#client ⇒ Object
55 56 57 |
# File 'lib/xiami_radio/user.rb', line 55 def client @client ||= Client.new user: self end |
#login? ⇒ Boolean
19 20 21 |
# File 'lib/xiami_radio/user.rb', line 19 def login? !user_id.to_s.empty? end |
#login_by_email(email, password) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/xiami_radio/user.rb', line 23 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 } .save get_user_info end |
#login_by_member_auth(member_auth) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/xiami_radio/user.rb', line 43 def login_by_member_auth(member_auth) uri = client.uri path: '/index/home' .parse "member_auth=#{member_auth}; path=/; domain=.xiami.com", uri client.get uri, format: :head .save get_user_info end |
#radio(**args) ⇒ Object
15 16 17 |
# File 'lib/xiami_radio/user.rb', line 15 def radio(**args) XiamiRadio::Radio.new user: self, **args end |
#xiami_token ⇒ Object
51 52 53 |
# File 'lib/xiami_radio/user.rb', line 51 def xiami_token ..select { |c| c.name == '_xiamitoken' }.first&.value end |