Skip to content

Commit

Permalink
chore: add prefix to API_URL contant name
Browse files Browse the repository at this point in the history
  • Loading branch information
Kseniya Kalesnikava committed Mar 12, 2024
1 parent 12f5827 commit 580b71c
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 49 deletions.
6 changes: 3 additions & 3 deletions lib/mailerlite/automations/automations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/mailerlite/batch/batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 9 additions & 9 deletions lib/mailerlite/campaigns/campaigns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -160,31 +160,31 @@ 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
#
# @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.
#
# @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.
#
# @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
Expand All @@ -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
2 changes: 1 addition & 1 deletion lib/mailerlite/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
8 changes: 4 additions & 4 deletions lib/mailerlite/fields/fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -47,15 +47,15 @@ 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.
#
# @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
12 changes: 6 additions & 6 deletions lib/mailerlite/forms/forms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,15 +34,15 @@ 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
#
# @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
Expand All @@ -52,22 +52,22 @@ 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.
#
# @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
14 changes: 7 additions & 7 deletions lib/mailerlite/groups/groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -60,31 +60,31 @@ 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.
# @param group_id [Integer] The id of existing group belonging to the account
# @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.
# @param group_id [Integer] The id of existing group belonging to the account
# @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.
#
# @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
8 changes: 4 additions & 4 deletions lib/mailerlite/segments/segments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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
16 changes: 8 additions & 8 deletions lib/mailerlite/subscribers/subscribers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -81,46 +81,46 @@ 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
#
# @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
#
# @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.
#
# @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.
#
# @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
2 changes: 1 addition & 1 deletion lib/mailerlite/timezones/timezones.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit 580b71c

Please sign in to comment.