Class: Mi::Service::Mina
- Inherits:
-
Object
- Object
- Mi::Service::Mina
- Defined in:
- lib/mi/service/mina.rb
Constant Summary collapse
- DEFAULT_HEADERS =
{ "User-Agent": "MiHome/6.0.103 (com.xiaomi.mihome; build:6.0.103.1; iOS 14.4.0) Alamofire/6.0.103 MICO/iOSApp/appStore/6.0.103" }.freeze
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Returns the value of attribute account.
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
Instance Method Summary collapse
- #device_list(master = 0) ⇒ Object
-
#initialize(account, debug: false) ⇒ Mina
constructor
A new instance of Mina.
- #message_list(device_id:, hardware:, timestamp: Time.now.to_i * 1000, limit: 2) ⇒ Object
- #player_get_status(device_id) ⇒ Object
- #player_pause(device_id) ⇒ Object
- #player_stop(device_id) ⇒ Object
- #text_to_speech(device_id, text) ⇒ Object
Constructor Details
#initialize(account, debug: false) ⇒ Mina
Returns a new instance of Mina.
21 22 23 24 |
# File 'lib/mi/service/mina.rb', line 21 def initialize(account, debug: false) @debug = debug @account = account end |
Instance Attribute Details
#account ⇒ Object (readonly)
Returns the value of attribute account.
15 16 17 |
# File 'lib/mi/service/mina.rb', line 15 def account @account end |
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
15 16 17 |
# File 'lib/mi/service/mina.rb', line 15 def debug @debug end |
Instance Method Details
#device_list(master = 0) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mi/service/mina.rb', line 26 def device_list(master = 0) sid = "micoapi" url = "https://api2.mina.mi.com/admin/v2/device_list?master=#{master}" request_id = "app_ios_#{Mi::Utils.get_random(30)}" url += "&requestId=#{request_id}" client = Faraday.new(url) do |f| f.response :logger if debug f.headers = DEFAULT_HEADERS.merge("Cookie" => Mi::Utils.(account.(sid))) end response = client.get(url) JSON.parse(response.body)["data"] end |
#message_list(device_id:, hardware:, timestamp: Time.now.to_i * 1000, limit: 2) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/mi/service/mina.rb', line 125 def (device_id:, hardware:, timestamp: Time.now.to_i * 1000, limit: 2) sid = "micoapi" url = "https://userprofile.mina.mi.com/device_profile/v2/conversation?source=dialogu&hardware=#{hardware}×tamp=#{}&limit=#{limit}" client = Faraday.new(url) do |f| f.response :logger if debug f.headers = DEFAULT_HEADERS.merge( "Cookie" => Mi::Utils.(account.(sid).merge("deviceId" => device_id)) ) end response = client.get(url) JSON.parse(response.body) end |
#player_get_status(device_id) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/mi/service/mina.rb', line 104 def player_get_status(device_id) sid = "micoapi" url = "https://api2.mina.mi.com/remote/ubus" request_id = "app_ios_#{Mi::Utils.get_random(30)}" data = { "requestId" => request_id, "deviceId" => device_id, "method" => "player_get_play_status", "path" => "mediaplayer", "message" => { media: "app_ios" }.to_json } client = Faraday.new(url) do |f| f.response :logger if debug f.request :url_encoded f.headers = DEFAULT_HEADERS.merge("Cookie" => Mi::Utils.(account.(sid))) end response = client.post(url, data) JSON.parse(response.body) end |
#player_pause(device_id) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/mi/service/mina.rb', line 62 def player_pause(device_id) sid = "micoapi" url = "https://api2.mina.mi.com/remote/ubus" request_id = "app_ios_#{Mi::Utils.get_random(30)}" data = { "requestId" => request_id, "deviceId" => device_id, "method" => "player_play_operation", "path" => "mediaplayer", "message" => { action: "pause", media: "app_ios" }.to_json } client = Faraday.new(url) do |f| f.response :logger if debug f.request :url_encoded f.headers = DEFAULT_HEADERS.merge("Cookie" => Mi::Utils.(account.(sid))) end response = client.post(url, data) JSON.parse(response.body) end |
#player_stop(device_id) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/mi/service/mina.rb', line 83 def player_stop(device_id) sid = "micoapi" url = "https://api2.mina.mi.com/remote/ubus" request_id = "app_ios_#{Mi::Utils.get_random(30)}" data = { "requestId" => request_id, "deviceId" => device_id, "method" => "player_play_operation", "path" => "mediaplayer", "message" => { action: "stop", media: "app_ios" }.to_json } client = Faraday.new(url) do |f| f.response :logger if debug f.request :url_encoded f.headers = DEFAULT_HEADERS.merge("Cookie" => Mi::Utils.(account.(sid))) end response = client.post(url, data) JSON.parse(response.body) end |
#text_to_speech(device_id, text) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/mi/service/mina.rb', line 41 def text_to_speech(device_id, text) sid = "micoapi" url = "https://api2.mina.mi.com/remote/ubus" request_id = "app_ios_#{Mi::Utils.get_random(30)}" data = { "requestId" => request_id, "deviceId" => device_id, "method" => "text_to_speech", "path" => "mibrain", "message" => { text: text }.to_json } client = Faraday.new(url) do |f| f.response :logger if debug f.request :url_encoded f.headers = DEFAULT_HEADERS.merge("Cookie" => Mi::Utils.(account.(sid))) end response = client.post(url, data) JSON.parse(response.body) end |