Class: Listmonk::Client
- Inherits:
-
Object
- Object
- Listmonk::Client
- Defined in:
- lib/listmonk/client.rb,
sig/listmonk.rbs
Constant Summary collapse
- RESOURCE_NAMES =
%i[ miscellaneous settings admin logs subscribers bounces lists imports campaigns media templates transactional maintenance public ].freeze
Instance Attribute Summary collapse
-
#base_url ⇒ String
readonly
Returns the value of attribute base_url.
Instance Method Summary collapse
- #admin ⇒ Object
- #bounces ⇒ Object
- #campaigns ⇒ Object
- #file_part(file, content_type: "application/octet-stream", filename: nil) ⇒ Object
- #imports ⇒ Object
-
#initialize(base_url:, username: nil, token: nil, auth: :basic, timeout: 30, open_timeout: 10, connection: nil) ⇒ Client
constructor
A new instance of Client.
- #lists ⇒ Object
- #logs ⇒ Object
- #maintenance ⇒ Object
- #media ⇒ Object
- #miscellaneous ⇒ Object
- #public ⇒ Object
- #request(method, path, params: nil, json: nil, body: nil, headers: {}) ⇒ Response
- #settings ⇒ Object
- #subscribers ⇒ Object
- #templates ⇒ Object
- #transactional ⇒ Object
Constructor Details
#initialize(base_url:, username: nil, token: nil, auth: :basic, timeout: 30, open_timeout: 10, connection: nil) ⇒ Client
Returns a new instance of Client.
18 19 20 21 22 |
# File 'lib/listmonk/client.rb', line 18 def initialize(base_url:, username: nil, token: nil, auth: :basic, timeout: 30, open_timeout: 10, connection: nil) @base_url = normalize_base_url(base_url) @connection = connection || build_connection(username, token, auth, timeout, open_timeout) end |
Instance Attribute Details
#base_url ⇒ String (readonly)
Returns the value of attribute base_url.
16 17 18 |
# File 'lib/listmonk/client.rb', line 16 def base_url @base_url end |
Instance Method Details
#admin ⇒ Object
51 |
# File 'sig/listmonk.rbs', line 51
def admin: () -> untyped
|
#bounces ⇒ Object
54 |
# File 'sig/listmonk.rbs', line 54
def bounces: () -> untyped
|
#campaigns ⇒ Object
57 |
# File 'sig/listmonk.rbs', line 57
def campaigns: () -> untyped
|
#file_part(file, content_type: "application/octet-stream", filename: nil) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/listmonk/client.rb', line 58 def file_part(file, content_type: "application/octet-stream", filename: nil) return file if file.is_a?(Faraday::Multipart::FilePart) filename ||= File.basename(file.respond_to?(:path) ? file.path : file.to_s) Faraday::Multipart::FilePart.new(file, content_type, filename) end |
#imports ⇒ Object
56 |
# File 'sig/listmonk.rbs', line 56
def imports: () -> untyped
|
#lists ⇒ Object
55 |
# File 'sig/listmonk.rbs', line 55
def lists: () -> untyped
|
#logs ⇒ Object
52 |
# File 'sig/listmonk.rbs', line 52
def logs: () -> untyped
|
#maintenance ⇒ Object
61 |
# File 'sig/listmonk.rbs', line 61
def maintenance: () -> untyped
|
#media ⇒ Object
58 |
# File 'sig/listmonk.rbs', line 58
def media: () -> untyped
|
#miscellaneous ⇒ Object
49 |
# File 'sig/listmonk.rbs', line 49
def miscellaneous: () -> untyped
|
#public ⇒ Object
62 |
# File 'sig/listmonk.rbs', line 62
def public: () -> untyped
|
#request(method, path, params: nil, json: nil, body: nil, headers: {}) ⇒ Response
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/listmonk/client.rb', line 33 def request(method, path, params: nil, json: nil, body: nil, headers: {}) raw = @connection.run_request(method, clean_path(path), nil, headers) do |request| request.params.update(compact(params)) if params if json.nil? request.body = body else request.headers["Content-Type"] = "application/json" request.body = JSON.generate(json) end end response = Response.new( status: raw.status, headers: raw.headers.to_h, body: parse_body(raw.body, raw.headers["content-type"]) ) raise_http_error(response) unless response.success? response rescue Faraday::TimeoutError => e raise TimeoutError, e. rescue Faraday::ConnectionFailed => e raise ConnectionError, e. end |
#settings ⇒ Object
50 |
# File 'sig/listmonk.rbs', line 50
def settings: () -> untyped
|
#subscribers ⇒ Object
53 |
# File 'sig/listmonk.rbs', line 53
def subscribers: () -> untyped
|
#templates ⇒ Object
59 |
# File 'sig/listmonk.rbs', line 59
def templates: () -> untyped
|
#transactional ⇒ Object
60 |
# File 'sig/listmonk.rbs', line 60
def transactional: () -> untyped
|