Class: MailchimpAPI::URIBuilder Private

Inherits:
Object
  • Object
show all
Defined in:
lib/mailchimp-api/uri_builder.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Internal class for building and manipulating URIs

Class Method Summary collapse

Class Method Details

.call(url:, path:, query:) ⇒ URI

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Builds a URI from base URL, path, and query parameters

Examples:

URIBuilder.call(
  url: "https://api.mailchimp.com/3.0",
  path: "lists",
  query: { count: 10 }
)

Parameters:

  • url (String)

    Base URL

  • path (String)

    Path to append to URL

  • query (Hash, nil)

    Optional query parameters

Returns:

  • (URI)

    Built URI with query parameters



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mailchimp-api/uri_builder.rb', line 19

def call(url:, path:, query:)
  uri =
    if path.start_with?("/")
      call(url: url, path: path[1, path.size - 1], query: nil)
    elsif path.start_with?("0", "1", "2", "3", "4", "5", "6", "7", "8", "9")
      URI.join(url, "/" + path)
    else
      URI.join(url, path)
    end

  add_query_params(uri, query)
  uri
end