Class: XiamiRadio::Client
- Inherits:
-
Object
- Object
- XiamiRadio::Client
- Defined in:
- lib/xiami_radio/client.rb
Overview
There is a client as you saw
Constant Summary collapse
- HOST =
'https://www.xiami.com'.freeze
- LOGIN_HOST =
'https://login.xiami.com'.freeze
- HEADERS =
{ 'Accept' => '*/*', 'Accept-Encoding' => '*', 'Accept-Language' => 'en-US,en;q=0.8,zh;q=0.6,zh-TW;q=0.4', 'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36' }.freeze
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#http ⇒ Object
Returns the value of attribute http.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #get(uri, format: :json, headers: {}) ⇒ Object
- #init_http ⇒ Object
-
#initialize(headers: {}, user: nil, host: HOST) ⇒ Client
constructor
A new instance of Client.
- #post(uri, form_data, format: :json, headers: {}) ⇒ Object
- #uri(**args) ⇒ Object
Constructor Details
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
19 20 21 |
# File 'lib/xiami_radio/client.rb', line 19 def headers @headers end |
#http ⇒ Object
Returns the value of attribute http.
19 20 21 |
# File 'lib/xiami_radio/client.rb', line 19 def http @http end |
#user ⇒ Object
Returns the value of attribute user.
19 20 21 |
# File 'lib/xiami_radio/client.rb', line 19 def user @user end |
Instance Method Details
#get(uri, format: :json, headers: {}) ⇒ Object
32 33 34 35 36 |
# File 'lib/xiami_radio/client.rb', line 32 def get(uri, format: :json, headers: {}) request uri, format, headers do |_headers| @http.start { |http| http.request(Net::HTTP::Get.new uri, _headers) } end end |
#init_http ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/xiami_radio/client.rb', line 46 def init_http @http = Net::HTTP.new @uri.host, @uri.port # -- OR -- # @http = Net::HTTP.new(@uri.host, @uri.port, '127.0.0.1', '8888') # @http.verify_mode = ::OpenSSL::SSL::VERIFY_NONE @http.use_ssl = @uri.scheme == 'https' end |
#post(uri, form_data, format: :json, headers: {}) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/xiami_radio/client.rb', line 38 def post(uri, form_data, format: :json, headers: {}) request uri, format, headers do |_headers| req = Net::HTTP::Post.new uri, _headers req.set_form_data form_data @http.start { |http| http.request req } end end |
#uri(**args) ⇒ Object
28 29 30 |
# File 'lib/xiami_radio/client.rb', line 28 def uri(**args) @uri.class.build scheme: @uri.scheme, host: @uri.host, **args end |