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_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

Returns a new instance of FaradayConnection.

Parameters:

  • client (Base)

    client data



995
996
997
998
999
1000
1001
1002
1003
1004
# File 'lib/maimai_net/client.rb', line 995

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
    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



1008
1009
1010
1011
1012
# File 'lib/maimai_net/client.rb', line 1008

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



1015
1016
1017
1018
1019
# File 'lib/maimai_net/client.rb', line 1015

def logout
  exclude_middlewares :follow_redirects do
    super
  end
end

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

This method is abstract.

sends request to given connection object

Parameters:

  • method (Symbol, String)

    request method

  • url (URI)

    request path

  • data (String, Object)

    request body

  • opts (Hash{Symbol => Object})
  • response_page (Hash)

    a customizable set of options

  • response (Hash)

    a customizable set of options

Returns:



1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
# File 'lib/maimai_net/client.rb', line 1022

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