Class: MaimaiNet::Client::FaradayConnection

Inherits:
Connection
  • Object
show all
Defined in:
lib/maimai_net/client.rb

Instance Method Summary collapse

Methods inherited from Connection

#fetch_and_submit_form, #finale_archive, #home, inherited, method_added, #music_record_info, #on_error, #on_login_error, #on_login_expired_error, #on_login_request, #photo_album, #player_data, #recent_play_details, #recent_play_info, #recent_plays

Methods included from ConnectionSupportUserFavorite

#get_favorites, #get_songs, #set_favorites

Methods included from ConnectionSupportUserOption

#get_gameplay_settings, #set_gameplay_settings

Methods included from ConnectionSupportSongList

#song_list, #song_list_by_custom, #song_list_by_genre, #song_list_by_level, #song_list_by_title, #song_list_by_version

Constructor Details

#initialize(client) ⇒ FaradayConnection



1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
# File 'lib/maimai_net/client.rb', line 1018

def initialize(client)
  super
  info = client.class.region_info

  @conn = Faraday.new(url: info[:base_host]) do |builder|
    builder.request  :url_encoded
    builder.response :follow_redirects, limit: 5
    builder.use      :cookie_jar, jar: client.cookies
  end
end

Instance Method Details

#log!void

This method returns an undefined value.

insert logging middleware into the connector, replaces if necessary



1031
1032
1033
1034
1035
# File 'lib/maimai_net/client.rb', line 1031

def log!
  replace_connector do |builder|
    builder.response :logger, nil, headers: false, bodies: false, log_level: :info
  end
end

#logoutvoid

This method returns an undefined value.

logs out current session



1038
1039
1040
1041
1042
# File 'lib/maimai_net/client.rb', line 1038

def logout
  exclude_middlewares :follow_redirects do
    super
  end
end

#send_request(method, url, data, **opts) ⇒ Model::Base, void

This method is abstract.

sends request to given connection object



1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
# File 'lib/maimai_net/client.rb', line 1045

def send_request(method, url, data, **opts)
  body = Faraday::METHODS_WITH_BODY.include?(method) ? data : nil

  resp = @conn.run_request(
    method.to_s.downcase.to_sym, url,
    body, nil,
  ) do |req|
    req.params.update(data) if Faraday::METHODS_WITH_QUERY.include?(method) && Hash === data
  end

  process_response(
    url: resp.env.url,
    body: resp.body,
    request_options: opts,
  )
end