diff --git a/lib/mailerlite/automations/automations.rb b/lib/mailerlite/automations/automations.rb index 1889e69..00baa3e 100644 --- a/lib/mailerlite/automations/automations.rb +++ b/lib/mailerlite/automations/automations.rb @@ -25,7 +25,7 @@ def get(limit: nil, page: nil, filter: {}) params['filter[group]'] = filter[:group] if filter.key?(:group) params['limit'] = limit if limit params['page'] = page if page - uri = URI("#{API_URL}/automations") + uri = URI("#{MAILERLITE_API_URL}/automations") uri.query = URI.encode_www_form(params.compact) client.http.get(uri) end @@ -35,7 +35,7 @@ def get(limit: nil, page: nil, filter: {}) # @param automation_id [String] the ID of the Automation to fetch # @return [HTTP::Response] the response from the API def fetch(automation_id) - client.http.get("#{API_URL}/automations/#{automation_id}") + client.http.get("#{MAILERLITE_API_URL}/automations/#{automation_id}") end # get_subscriber_activity the subscriber activity for specified Automation @@ -54,7 +54,7 @@ def get_subscriber_activity(automation_id:, filter: {}, page: nil, limit: nil) params['filter[keyword]'] = filter[:keyword] if filter.key?(:keyword) params['page'] = page if page params['limit'] = limit if limit - uri = URI("#{API_URL}/automations/#{automation_id}/activity") + uri = URI("#{MAILERLITE_API_URL}/automations/#{automation_id}/activity") uri.query = URI.encode_www_form(params.compact) client.http.get(uri) end diff --git a/lib/mailerlite/batch/batch.rb b/lib/mailerlite/batch/batch.rb index a5db28e..2c95cbc 100644 --- a/lib/mailerlite/batch/batch.rb +++ b/lib/mailerlite/batch/batch.rb @@ -18,7 +18,7 @@ def initialize(client: MailerLite::Client.new) # @return [HTTP::Response] the response from the API def request(requests:) params = { requests: requests } - client.http.post("#{API_URL}/batch", body: params.to_json) + client.http.post("#{MAILERLITE_API_URL}/batch", body: params.to_json) end end end diff --git a/lib/mailerlite/campaigns/campaigns.rb b/lib/mailerlite/campaigns/campaigns.rb index f7143db..e08ee11 100644 --- a/lib/mailerlite/campaigns/campaigns.rb +++ b/lib/mailerlite/campaigns/campaigns.rb @@ -24,7 +24,7 @@ def get(filter:, limit: nil, page: nil) params['filter[type]'] = filter[:type] if filter.key?(:type) params['limit'] = limit if limit params['page'] = page if page - uri = URI("#{API_URL}/campaigns") + uri = URI("#{MAILERLITE_API_URL}/campaigns") uri.query = URI.encode_www_form(params.compact) client.http.get(uri) end @@ -78,7 +78,7 @@ def create(name:, type:, emails:, language_id: nil, groups: nil, segments: nil, } end - client.http.post("#{API_URL}/campaigns", body: params.compact.to_json) + client.http.post("#{MAILERLITE_API_URL}/campaigns", body: params.compact.to_json) end # Update a new campaign with the specified details. @@ -132,7 +132,7 @@ def update(campaign_id:, name:, type:, emails:, language_id: nil, groups: nil, s end - client.http.put("#{API_URL}/campaigns/#{campaign_id}", body: params.compact.to_json) + client.http.put("#{MAILERLITE_API_URL}/campaigns/#{campaign_id}", body: params.compact.to_json) end # Schedules the specified campaign. @@ -160,7 +160,7 @@ def schedule(campaign_id:, delivery:, schedule: nil, resend: nil) params['resend']['minutes'] = resend[:minutes] if resend&.key?(:minutes) params['resend']['timezone_id'] = resend[:timezone_id] if resend&.key?(:timezone_id) - client.http.post("#{API_URL}/campaigns/#{campaign_id}/schedule", body: params.compact.to_json) + client.http.post("#{MAILERLITE_API_URL}/campaigns/#{campaign_id}/schedule", body: params.compact.to_json) end # Returns the details of the specified Campaigns @@ -168,7 +168,7 @@ def schedule(campaign_id:, delivery:, schedule: nil, resend: nil) # @param campaign_id [String] the ID of the campaign to fetch # @return [HTTP::Response] the response from the API def fetch(campaign_id) - client.http.get("#{API_URL}/campaigns/#{campaign_id}") + client.http.get("#{MAILERLITE_API_URL}/campaigns/#{campaign_id}") end # Cancels the specified campaign. @@ -176,7 +176,7 @@ def fetch(campaign_id) # @param campaign_id [String] the ID of the campaign to delete # @return [HTTP::Response] the response from the API def cancel(campaign_id) - client.http.post("#{API_URL}/campaigns/#{campaign_id}/cancel") + client.http.post("#{MAILERLITE_API_URL}/campaigns/#{campaign_id}/cancel") end # Deletes the specified campaign. @@ -184,7 +184,7 @@ def cancel(campaign_id) # @param campaign_id [String] the ID of the campaign to delete # @return [HTTP::Response] the response from the API def delete(campaign_id) - client.http.delete("#{API_URL}/campaigns/#{campaign_id}") + client.http.delete("#{MAILERLITE_API_URL}/campaigns/#{campaign_id}") end # activity the subscriber activity for specified campaign @@ -203,14 +203,14 @@ def activity(campaign_id:, filter: nil, page: nil, limit: nil, sort: nil) params['page'] = page if page params['limit'] = limit if limit params['sort'] = sort if sort - client.http.post("#{API_URL}/campaigns/#{campaign_id}/reports/subscriber-activity", body: params.compact.to_json) + client.http.post("#{MAILERLITE_API_URL}/campaigns/#{campaign_id}/reports/subscriber-activity", body: params.compact.to_json) end # Get a list of all campaign languages available # # @return [HTTP::Response] the response from the API def languages - client.http.get("#{API_URL}/campaigns/languages") + client.http.get("#{MAILERLITE_API_URL}/campaigns/languages") end end end diff --git a/lib/mailerlite/client.rb b/lib/mailerlite/client.rb index 09651d2..09ab26d 100644 --- a/lib/mailerlite/client.rb +++ b/lib/mailerlite/client.rb @@ -3,7 +3,7 @@ require 'http' require 'dotenv/load' -API_URL = 'https://connect.mailerlite.com/api' +MAILERLITE_API_URL = 'https://connect.mailerlite.com/api' Dotenv.require_keys('MAILERLITE_API_TOKEN') diff --git a/lib/mailerlite/fields/fields.rb b/lib/mailerlite/fields/fields.rb index 50e4e23..23babe0 100644 --- a/lib/mailerlite/fields/fields.rb +++ b/lib/mailerlite/fields/fields.rb @@ -25,7 +25,7 @@ def get(limit: nil, page: nil, filter: {}, sort: nil) params['sort'] = sort if sort params['limit'] = limit if limit params['page'] = page if page - uri = URI("#{API_URL}/fields") + uri = URI("#{MAILERLITE_API_URL}/fields") uri.query = URI.encode_www_form(params.compact) client.http.get(uri) end @@ -37,7 +37,7 @@ def get(limit: nil, page: nil, filter: {}, sort: nil) # @return [HTTP::Response] the response from the API def create(type:, name:) params = { 'name' => name, 'type' => type } - client.http.post("#{API_URL}/fields", json: params.compact) + client.http.post("#{MAILERLITE_API_URL}/fields", json: params.compact) end # Update the specified Field @@ -47,7 +47,7 @@ def create(type:, name:) # @return [HTTP::Response] the response from the API def update(field_id:, name:) params = { 'name' => name } - client.http.put("#{API_URL}/fields/#{field_id}", json: params.compact) + client.http.put("#{MAILERLITE_API_URL}/fields/#{field_id}", json: params.compact) end # Deletes the specified Field. @@ -55,7 +55,7 @@ def update(field_id:, name:) # @param field_id [String] the ID of the Field to delete # @return [HTTP::Response] the response from the API def delete(field_id) - client.http.delete("#{API_URL}/fields/#{field_id}") + client.http.delete("#{MAILERLITE_API_URL}/fields/#{field_id}") end end end diff --git a/lib/mailerlite/forms/forms.rb b/lib/mailerlite/forms/forms.rb index 52300fd..69f008e 100644 --- a/lib/mailerlite/forms/forms.rb +++ b/lib/mailerlite/forms/forms.rb @@ -24,7 +24,7 @@ def list(type:, filter: {}, limit: nil, sort: nil, page: nil) params['limit'] = limit if limit params['sort'] = sort if sort params['page'] = page if page - uri = URI("#{API_URL}/forms/#{type}") + uri = URI("#{MAILERLITE_API_URL}/forms/#{type}") uri.query = URI.encode_www_form(params.compact) client.http.get(uri) end @@ -34,7 +34,7 @@ def list(type:, filter: {}, limit: nil, sort: nil, page: nil) # @param form_id [String] the ID of the forms to fetch # @return [HTTP::Response] the response from the API def fetch(form_id) - client.http.get("#{API_URL}/forms/#{form_id}") + client.http.get("#{MAILERLITE_API_URL}/forms/#{form_id}") end # Returns the subscribers who signed up to a specific form @@ -42,7 +42,7 @@ def fetch(form_id) # @param form_id [String] the ID of the forms to fetch # @return [HTTP::Response] the response from the API def fetch_subscribers(form_id) - client.http.get("#{API_URL}/forms/#{form_id}/subscribers") + client.http.get("#{MAILERLITE_API_URL}/forms/#{form_id}/subscribers") end # Update the specified Forms @@ -52,14 +52,14 @@ def fetch_subscribers(form_id) # @return [HTTP::Response] the response from the API def update(form_id:, name:) params = { 'name' => name } - client.http.put("#{API_URL}/forms/#{form_id}", json: params.compact) + client.http.put("#{MAILERLITE_API_URL}/forms/#{form_id}", json: params.compact) end # Returns the total number of Forms in the MailerLite account. # # @return [HTTP::Response] the response from the API def fetch_count - client.http.get("#{API_URL}/forms/?limit=0") + client.http.get("#{MAILERLITE_API_URL}/forms/?limit=0") end # Deletes the specified forms. @@ -67,7 +67,7 @@ def fetch_count # @param form_id [String] the ID of the forms to delete # @return [HTTP::Response] the response from the API def delete(form_id) - client.http.delete("#{API_URL}/forms/#{form_id}") + client.http.delete("#{MAILERLITE_API_URL}/forms/#{form_id}") end end end diff --git a/lib/mailerlite/groups/groups.rb b/lib/mailerlite/groups/groups.rb index 8db2b2e..bc86d07 100644 --- a/lib/mailerlite/groups/groups.rb +++ b/lib/mailerlite/groups/groups.rb @@ -24,7 +24,7 @@ def get(filter: {}, limit: nil, sort: nil, page: nil) params['limit'] = limit if limit params['sort'] = sort if sort params['page'] = page if page - uri = URI("#{API_URL}/groups") + uri = URI("#{MAILERLITE_API_URL}/groups") uri.query = URI.encode_www_form(params.compact) client.http.get(uri) end @@ -35,7 +35,7 @@ def get(filter: {}, limit: nil, sort: nil, page: nil) # @return [HTTP::Response] the response from the API def create(name:) params = { 'name' => name } - client.http.post("#{API_URL}/groups", json: params.compact) + client.http.post("#{MAILERLITE_API_URL}/groups", json: params.compact) end # Update the specified Group @@ -45,7 +45,7 @@ def create(name:) # @return [HTTP::Response] the response from the API def update(group_id:, name:) params = { 'name' => name } - client.http.put("#{API_URL}/groups/#{group_id}", json: params.compact) + client.http.put("#{MAILERLITE_API_URL}/groups/#{group_id}", json: params.compact) end # Get Subscribers assigned to the specified group. @@ -60,7 +60,7 @@ def get_subscribers(group_id:, filter: {}, limit: nil, page: nil, sort: nil) params['limit'] = limit if limit params['sort'] = sort if sort params['page'] = page if page - client.http.get("#{API_URL}/groups/#{group_id}/subscribers", json: params.compact) + client.http.get("#{MAILERLITE_API_URL}/groups/#{group_id}/subscribers", json: params.compact) end # Assign Subscriber to the specified group. @@ -68,7 +68,7 @@ def get_subscribers(group_id:, filter: {}, limit: nil, page: nil, sort: nil) # @param subscriber [Integer] The id of existing subscriber belonging to the account # @return [HTTP::Response] the response from the API def assign_subscriber(group_id:, subscriber:) - client.http.post("#{API_URL}/subscribers/#{subscriber}/groups/#{group_id}") + client.http.post("#{MAILERLITE_API_URL}/subscribers/#{subscriber}/groups/#{group_id}") end # Unassign Subscriber to the specified group. @@ -76,7 +76,7 @@ def assign_subscriber(group_id:, subscriber:) # @param subscriber [Integer] The id of existing subscriber belonging to the account # @return [HTTP::Response] the response from the API def unassign_subscriber(group_id:, subscriber:) - client.http.delete("#{API_URL}/subscribers/#{subscriber}/groups/#{group_id}") + client.http.delete("#{MAILERLITE_API_URL}/subscribers/#{subscriber}/groups/#{group_id}") end # Deletes the specified Groups. @@ -84,7 +84,7 @@ def unassign_subscriber(group_id:, subscriber:) # @param group_id [String] the ID of the Groups to delete # @return [HTTP::Response] the response from the API def delete(group_id) - client.http.delete("#{API_URL}/groups/#{group_id}") + client.http.delete("#{MAILERLITE_API_URL}/groups/#{group_id}") end end end diff --git a/lib/mailerlite/segments/segments.rb b/lib/mailerlite/segments/segments.rb index 9e23b29..052c427 100644 --- a/lib/mailerlite/segments/segments.rb +++ b/lib/mailerlite/segments/segments.rb @@ -22,7 +22,7 @@ def list(limit: nil, page: nil) params['limit'] = limit if limit params['page'] = page if page - client.http.get("#{API_URL}/segments", json: params.compact) + client.http.get("#{MAILERLITE_API_URL}/segments", json: params.compact) end # Update the specified Segment @@ -32,7 +32,7 @@ def list(limit: nil, page: nil) # @return [HTTP::Response] the response from the API def update(segment_id:, name:) params = { 'name' => name } - client.http.put("#{API_URL}/segments/#{segment_id}", json: params.compact) + client.http.put("#{MAILERLITE_API_URL}/segments/#{segment_id}", json: params.compact) end # Get Subscribers assigned to the specified Segment. @@ -46,7 +46,7 @@ def get_subscribers(segment_id:, filter: {}, limit: nil, after: nil) params['filter[status]'] = filter[:status] if filter.key?(:status) params['limit'] = limit if limit params['after'] = after if after - uri = URI("#{API_URL}/segments/#{segment_id}/subscribers") + uri = URI("#{MAILERLITE_API_URL}/segments/#{segment_id}/subscribers") uri.query = URI.encode_www_form(params.compact) client.http.get(uri) end @@ -56,7 +56,7 @@ def get_subscribers(segment_id:, filter: {}, limit: nil, after: nil) # @param segment_id [String] the ID of the Segments to delete # @return [HTTP::Response] the response from the API def delete(segment_id) - client.http.delete("#{API_URL}/segments/#{segment_id}") + client.http.delete("#{MAILERLITE_API_URL}/segments/#{segment_id}") end end end diff --git a/lib/mailerlite/subscribers/subscribers.rb b/lib/mailerlite/subscribers/subscribers.rb index b3bad1d..239b187 100644 --- a/lib/mailerlite/subscribers/subscribers.rb +++ b/lib/mailerlite/subscribers/subscribers.rb @@ -23,7 +23,7 @@ def fetch(filter:, limit: nil, page: nil) params['limit'] = limit if limit params['page'] = page if page - uri = URI("#{API_URL}/subscribers") + uri = URI("#{MAILERLITE_API_URL}/subscribers") uri.query = URI.encode_www_form(params.compact) client.http.get(uri) end @@ -52,7 +52,7 @@ def create(email:, fields: nil, groups: nil, status: nil, subscribed_at: nil, ip params['optin_ip'] = optin_ip if optin_ip params['unsubscribed_at'] = unsubscribed_at if unsubscribed_at - client.http.post("#{API_URL}/subscribers", json: params.compact) + client.http.post("#{MAILERLITE_API_URL}/subscribers", json: params.compact) end # Updates an existing subscriber with the specified details. @@ -81,7 +81,7 @@ def update(subscriber_id, email: nil, fields: nil, groups: nil, status: nil, sub params['optin_ip'] = optin_ip if optin_ip params['unsubscribed_at'] = unsubscribed_at if unsubscribed_at - client.http.put("#{API_URL}/subscribers/#{subscriber_id}", json: params.compact) + client.http.put("#{MAILERLITE_API_URL}/subscribers/#{subscriber_id}", json: params.compact) end # Returns the details of the specified subscribers @@ -89,7 +89,7 @@ def update(subscriber_id, email: nil, fields: nil, groups: nil, status: nil, sub # @param subscriber_id [String] the ID of the subscriber to get # @return [HTTP::Response] the response from the API def get(subscriber_id) - client.http.get("#{API_URL}/subscribers/#{subscriber_id}") + client.http.get("#{MAILERLITE_API_URL}/subscribers/#{subscriber_id}") end # Returns the details of the specified subscribers @@ -97,14 +97,14 @@ def get(subscriber_id) # @param import_id [String] the ID of the import to fetch report # @return [HTTP::Response] the response from the API def get_single_import(import_id) - client.http.get("#{API_URL}/subscribers/import/#{import_id}") + client.http.get("#{MAILERLITE_API_URL}/subscribers/import/#{import_id}") end # Returns the total number of subscribers in the MailerLite account. # # @return [HTTP::Response] the response from the API def fetch_count - client.http.get("#{API_URL}/subscribers/?limit=0") + client.http.get("#{MAILERLITE_API_URL}/subscribers/?limit=0") end # Deletes the specified subscriber. @@ -112,7 +112,7 @@ def fetch_count # @param subscriber_id [String] the ID of the subscriber to delete # @return [HTTP::Response] the response from the API def delete(subscriber_id) - client.http.delete("#{API_URL}/subscribers/#{subscriber_id}") + client.http.delete("#{MAILERLITE_API_URL}/subscribers/#{subscriber_id}") end # Forgets the specified subscriber. @@ -120,7 +120,7 @@ def delete(subscriber_id) # @param subscriber_id [String] the ID of the subscriber to forget # @return [HTTP::Response] the response from the API def forget(subscriber_id) - client.http.post("#{API_URL}/subscribers/#{subscriber_id}/forget") + client.http.post("#{MAILERLITE_API_URL}/subscribers/#{subscriber_id}/forget") end end end diff --git a/lib/mailerlite/timezones/timezones.rb b/lib/mailerlite/timezones/timezones.rb index 966e4c2..26da3f5 100644 --- a/lib/mailerlite/timezones/timezones.rb +++ b/lib/mailerlite/timezones/timezones.rb @@ -16,7 +16,7 @@ def initialize(client: MailerLite::Client.new) # # @return [HTTP::Response] the response from the API def list - client.http.get("#{API_URL}/timezones") + client.http.get("#{MAILERLITE_API_URL}/timezones") end end end diff --git a/lib/mailerlite/webhooks/webhooks.rb b/lib/mailerlite/webhooks/webhooks.rb index 6310c35..d963a90 100644 --- a/lib/mailerlite/webhooks/webhooks.rb +++ b/lib/mailerlite/webhooks/webhooks.rb @@ -16,7 +16,7 @@ def initialize(client: MailerLite::Client.new) # # @return [HTTP::Response] the response from the API def list - client.http.get("#{API_URL}/webhooks") + client.http.get("#{MAILERLITE_API_URL}/webhooks") end # Returns the details of the specified webhooks @@ -24,7 +24,7 @@ def list # @param webhook_id [String] the ID of the webhooks to fetch # @return [HTTP::Response] the response from the API def get(webhook_id) - client.http.get("#{API_URL}/webhooks/#{webhook_id}") + client.http.get("#{MAILERLITE_API_URL}/webhooks/#{webhook_id}") end # Create a Webhook @@ -36,7 +36,7 @@ def get(webhook_id) def create(events:, url:, name: nil) params = { 'events' => events, 'url' => url } params['name'] = name if name - client.http.post("#{API_URL}/webhooks", json: params.compact) + client.http.post("#{MAILERLITE_API_URL}/webhooks", json: params.compact) end # Update the specified Webhook @@ -53,7 +53,7 @@ def update(webhook_id:, events: nil, name: nil, url: nil, enabled: nil) params['name'] = name if name params['url'] = url if url params['enabled'] = enabled if enabled - client.http.put("#{API_URL}/webhooks/#{webhook_id}", json: params.compact) + client.http.put("#{MAILERLITE_API_URL}/webhooks/#{webhook_id}", json: params.compact) end # Deletes the specified Webhook. @@ -61,7 +61,7 @@ def update(webhook_id:, events: nil, name: nil, url: nil, enabled: nil) # @param webhook_id [String] the ID of the Webhook to delete # @return [HTTP::Response] the response from the API def delete(webhook_id) - client.http.delete("#{API_URL}/webhooks/#{webhook_id}") + client.http.delete("#{MAILERLITE_API_URL}/webhooks/#{webhook_id}") end end end