The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Mslm::Common - Perl module containing common functions for API interactions

SYNOPSIS

  use Mslm::Common;

  # Create a new instance
  my $common = Mslm::Common->new(
      http_client => $http_client,
      base_url    => $base_url,
      user_agent  => $user_agent,
      api_key     => $api_key
  );

  # Set base URL
  $common->set_base_url('https://example.com');

  # Set HTTP client
  $common->set_http_client($custom_LWP_UserAgent);

  # Set user agent
  $common->set_user_agent('my-custom-agent/1.0');

  # Set API key
  $common->set_api_key('my-api-key');

DESCRIPTION

The Mslm::Common module contains common functions for handling API interactions such as setting base URL, HTTP client, user agent, and API key.

METHODS

new

Creates a new instance of Mslm::Common.

Arguments

  • %opts (hash) - Optional parameters. You can pass in the following opts: base_url, user_agent, api_key, and http_client. These settings can also be done via the setter functions named: set_base_url, set_user_agent, set_api_key, set_http_client.

set_base_url

Sets the base URL for API requests.

Arguments

  • $base_url_str (string) - The base URL to be set for API requests.

set_http_client

Sets the HTTP client for making requests.

Arguments

  • $http_client (LWP::UserAgent) - The HTTP client to be set.

set_user_agent

Sets the user agent for API requests.

Arguments

  • $user_agent (string) - The user agent string to be set.

set_api_key

Sets the API key for authentication.

Arguments

  • $api_key (string) - The API key to be set.

prepare_url

Prepares the URL for making API requests.

Arguments

  • $urlPath (string) - The path for the API request.

  • $qp (hash reference) - Query parameters for the API request.

  • %opts (hash) - Optional parameters. You can pass in the following opts: base_url, api_key, and disable_url_encoding. These options will only work for the current request.

req_and_resp

Performs the API request and fetches the response.

Arguments

  • $http_client (LWP::UserAgent) - The HTTP client to be used for the request.

  • $method (string) - The HTTP method for the request.

  • $reqUrl (string) - The URL for the request.

  • $data (bytes)- Data to be sent with the request (if any). Must be a string of bytes.

  • %opts (hash) - Optional parameters. You can pass in the opt: user_agent.

AUTHOR

Mslm, <usama.liaqat@mslm.io>

COPYRIGHT AND LICENSE

Copyright (c) 2022-now mslm. All rights reserved.