Skip to content

About

No description or website provided.

Topics

Resources

Stars

12 stars

Watchers

4 watching

Forks

Repository files navigation

MailerLite Ruby SDK

MIT licensed

Getting started

For more information about MailerLite API, please visit the following link:

Authentication

API keys are a quick way to implement machine-to-machine authentication without any direct inputs from a human beyond initial setup.

For more information how to obtain an API key visit the following link

Table of Contents

Setup

gem install mailerlite-ruby

You will have to initalize it in your Ruby file with require "mailerlite-ruby".

Usage

This SDK requires that you have the MAILERLITE_API_TOKEN environment variable set. You can set this variable in a .env file or enable it system-wide (useful for Docker/Kubernetes). The example of how MAILERLITE_API_TOKEN should look like is in .env.example.

If you want to use dotenv to manage your environment variables, you can configure the mailerlite gem to load dotenv:

MailerLite.configure do |config|
  config.use_dotenv = true
end

Subscribers

List all subscribers

require "mailerlite-ruby"

# Intialize the class
subscribers = MailerLite::Subscribers.new

subscribers.fetch(filter: { status: 'active' }, cursor: 'cursor')

Create a subscriber

require "mailerlite-ruby"

# Intialize the class
subscribers = MailerLite::Subscribers.new

subscribers.create(email:'some@email.com', fields: {'name': 'John', 'last_name': 'Doe'}, ip_address:'1.2.3.4', optin_ip:'1.2.3.4')

Update a subscriber

require "mailerlite-ruby"

# Intialize the class
subscribers = MailerLite::Subscribers.new

subscribers.update('some@email.com', fields: {'name': 'John', 'last_name': 'Doe'}, ip_address:'1.2.3.4', optin_ip:'1.2.3.4')

Get a subscriber

require "mailerlite-ruby"

# Intialize the class
subscribers = MailerLite::Subscribers.new

subscribers.get('some@email.com')

Delete a subscriber

require "mailerlite-ruby"

# Intialize the class
subscribers = MailerLite::Subscribers.new

subscriber_id = 1234567890

subscribers.delete(subscriber_id)

Groups

List all groups

require "mailerlite-ruby"

# Intialize the class
groups = MailerLite::Groups.new

groups.get(limit:10, page:1, filter:{'name': 'My'}, sort:'name')

Create a group

require "mailerlite-ruby"

# Intialize the class
groups = MailerLite::Groups.new

groups.create(name:'Group Name')

Update a group

require "mailerlite-ruby"

# Intialize the class
groups = MailerLite::Groups.new

groups.update(group_id:1234567, name:'My New Group')

Delete a group

require "mailerlite-ruby"

# Intialize the class
groups = MailerLite::Groups.new

group_id = 1234567

groups.delete(group_id)

Get subscribers belonging to a group

require "mailerlite-ruby"

# Initialize the class
groups = MailerLite::Groups.new

groups.get_subscribers(group_id: 1234567, cursor: 'cursor', limit: 10, filter: { 'status': 'active' })

Assign subscriber to a group

require "mailerlite-ruby"

# Intialize the class
groups = MailerLite::Groups.new

groups.assign_subscriber(subscriber:111222, group_id:1234567)

Unassign subscriber from a group

require "mailerlite-ruby"

# Intialize the class
groups = MailerLite::Groups.new

groups.unassign_subscriber(subscriber:111222, group_id:1234567)

Segments

List all segments

require "mailerlite-ruby"

# Intialize the class
segments = MailerLite::Segments.new

segments.list(limit:10, page:1)

Update a segment

require "mailerlite-ruby"

# Intialize the class
segments = MailerLite::Segments.new

segments.update(segment_id: 123456, name:'My New Segment Name')

Delete a segment

require "mailerlite-ruby"

# Intialize the class
segments = MailerLite::Segments.new
segment_id = 123456

segments.delete(segment_id)

Get subscribers belonging to a segment

require "mailerlite-ruby"

# Intialize the class
segments = MailerLite::Segments.new

segments.get_subscribers(segment_id:123456, limit:10, filter:{'status': 'active'})

Fields

List all fields

require "mailerlite-ruby"

# Intialize the class
fields = MailerLite::Fields.new

fields.get(limit:10, page:1, sort:'name', filter:{'keyword': 'abc', 'type': 'text'})

Create a field

require "mailerlite-ruby"

# Intialize the class
fields = MailerLite::Fields.new

fields.create(name:'My Field', type:'text')

Update a field

require "mailerlite-ruby"

# Intialize the class
fields = MailerLite::Fields.new

fields.update(field_id:123345, name:'My New Field')

Delete a field

require "mailerlite-ruby"

# Intialize the class
fields = MailerLite::Fields.new

field_id = 123456

fields.delete(field_id)

Automations

List all automations

require "mailerlite-ruby"

# Intialize the class
automations = MailerLite::Automations.new

automations.get(limit:10, page:1, filter:{'status': true, 'name': 'some name', 'group': 123456})

Get an automation

require "mailerlite-ruby"

# Intialize the class
automations = MailerLite::Automations.new

automation_id = 123456

automations.fetch(automation_id)

Get subscribers activity for an automation

require "mailerlite-ruby"

# Intialize the class
automations = MailerLite::Automations.new

automations.get_subscriber_activity(automation_id:123456, page:1, limit:10, filter:{'status': 'active', 'date_from': '2022-12-20', 'date_to': '2022-12-31'})

Campaigns

List all campaigns

require "mailerlite-ruby"

# Intialize the class
campaigns = MailerLite::Campaigns.new

campaigns.get(limit:10, page:1, filter:{'status': 'ready', 'type': 'regular'})

Get a campaign

require "mailerlite-ruby"

# Intialize the class
campaigns = MailerLite::Campaigns.new

campaigns.fetch(campaign_id:123456)

Create a campaign

require "mailerlite-ruby"

# Intialize the class
campaigns = MailerLite::Campaigns.new

campaigns.create(
    name: "Test Campaign",
    language_id: 1,
    type: "regular",
    emails: [{
        "subject": "This is a test campaign",
        "from_name": "Test Man",
        "from": "testuser@mailerlite.com",
        "content": "Hi there, this is a test campaign!"
    }]
  )

Create a campaign with the simple editor

To build the email with the simple editor, set editor to MailerLite::Campaigns::EDITOR_SIMPLE, and do not send content. Then edit the email with the email methods.

  • template_id is optional. It is the simple editor template that the email starts from: a template from the shared gallery, or a template that you saved from your own email with create_template (the id in its response). It needs editor. Without it, the email starts from the default blank template. The API copies the template into the new email and does not change the template.
  • All emails of a campaign must have the same editor and template_id.
  • Only create accepts editor and template_id. update does not.
require "mailerlite-ruby"

# Initialize the class
campaigns = MailerLite::Campaigns.new

response = campaigns.create(
  name: "Test Campaign",
  type: "regular",
  emails: [{
    subject: "This is a test campaign",
    from_name: "Test Man",
    from: "testuser@mailerlite.com",
    editor: MailerLite::Campaigns::EDITOR_SIMPLE
  }]
)

email_id = JSON.parse(response.body)['data']['emails'][0]['id']

Update a campaign

require "mailerlite-ruby"

# Intialize the class
campaigns = MailerLite::Campaigns.new

campaigns.update(
  campaign_id: 1233455,
  name: "New Campaign Name",
  language_id: 2,
  emails: [{
      "subject": "This is a test campaign",
      "from_name": "Test Man",
      "from": "testuser@mailerlite.com",
      "content": "Hi there, this is a test campaign!"
  }]
  )

Schedule a campaign

require "mailerlite-ruby"

# Intialize the class
campaigns = MailerLite::Campaigns.new

campaigns.schedule(
  campaign_id: 123456,
  delivery: "scheduled",
  schedule: {
      "date": "2022-12-31",
      "hours": "22",
      "minutes": "00"
  }
)

Cancel a campaign

require "mailerlite-ruby"

# Intialize the class
campaigns = MailerLite::Campaigns.new

campaign_id = 123456

campaigns.cancel(campaign_id)

Delete a campaign

require "mailerlite-ruby"

# Intialize the class
campaigns = MailerLite::Campaigns.new

campaign_id = 123456

campaigns.delete(campaign_id)

Get subscribers activity for a campaign

require "mailerlite-ruby"

# Intialize the class
campaigns = MailerLite::Campaigns.new

campaign_id = 123456

campaigns.activity(campaign_id)

Emails

These methods edit emails built with the simple editor. To create such an email, create a campaign with the simple editor. The ID of the email is in data.emails[0].id of the response.

  • IDs are strings of digits. You can also give them as integers. An empty ID raises MailerLite::EmptyIdError, and an ID that does not contain only digits raises MailerLite::InvalidIdError. The SDK sends no request in these cases.
  • The SDK checks only the IDs in the URL path, and the settings of update_settings: they must be a Hash without an etag key. The SDK sends all other values as you give them, and the API checks them. For a value that is not valid, the API returns 422 with the errors for each field.
  • The methods return an HTTP::Response, like the other methods. Use response.code for the status code, response.headers for the headers and JSON.parse(response.body) for the body.
  • The methods do not raise an error for a 4xx or 5xx status. response.api_error is nil for a 2xx status. For other statuses, it is a MailerLite::ApiError with status, code, etag, api_message and errors. You can raise it.
  • Each write needs the etag from the last response for the email, and returns a new etag. The etag covers the whole email, so send the writes to one email one after another.
  • If the email changed after you read it, the write returns 409, and response.api_error.code is MailerLite::Emails::VERSION_CONFLICT. Then response.api_error.etag is the current etag. Get the email again, and then send the write again with the current etag.
  • The keys of editor_content are camelCase, for example textAlign. The SDK sends them as you give them.

Get an email

Returns the email with its settings and blocks, and the etag of the email.

require "mailerlite-ruby"

# Initialize the class
emails = MailerLite::Emails.new

response = emails.get('123456')

body = JSON.parse(response.body)
email = body['data']
etag = body['etag']

Get the HTML of an email

Returns the HTML that the email sends. The API can return a temporary 503 error. If it does, try again later.

require "mailerlite-ruby"

# Initialize the class
emails = MailerLite::Emails.new

response = emails.get_html('123456')

html = JSON.parse(response.body)['data']['html'] if response.code == 200

Get a block

Returns the block and its place in the email: placement has the IDs of the blocks after and before it, or nil.

require "mailerlite-ruby"

# Initialize the class
emails = MailerLite::Emails.new

response = emails.get_block(email_id: '123456', block_id: '57')

block = JSON.parse(response.body)['data']

Insert a block

Use the block types in MailerLite::Emails::BlockType. editor_content can be empty. Without placement, the API puts the block at the end of the email. The positions are in MailerLite::Emails::BlockPosition. The BEFORE and AFTER positions also need a block_id. The SDK sends placement as you give it.

The API drops the attributes and the mobile keys that the block type does not declare, and the write still succeeds. Then the response has rejected with a message and the keys that the API dropped, for example editor_content.attrs.onclick. When the API drops nothing, the response has no rejected.

require "mailerlite-ruby"

# Initialize the class
emails = MailerLite::Emails.new

email_id = '123456'
etag = JSON.parse(emails.get(email_id).body)['etag']

response = emails.create_block(
  email_id: email_id,
  etag: etag,
  type: MailerLite::Emails::BlockType::PARAGRAPH,
  editor_content: { attrs: { textAlign: 'left' }, content: [{ type: 'text', text: 'Hello' }] },
  placement: { position: MailerLite::Emails::BlockPosition::AT_START }
)

body = JSON.parse(response.body)
block_id = body['data']['id']
etag = body['etag']
puts body['rejected']['keys'] if body['rejected']

Update a block

The new editor_content replaces the whole content of the block. The API removes the keys that you do not send.

The API drops the attributes and the mobile keys that the block type does not declare, and the write still succeeds. Then the response has rejected with a message and the keys that the API dropped, for example editor_content.mobile.onclick. When the API drops nothing, the response has no rejected.

require "mailerlite-ruby"

# Initialize the class
emails = MailerLite::Emails.new

response = emails.update_block(
  email_id: '123456',
  block_id: '57',
  etag: 'etag-from-the-last-response',
  editor_content: { attrs: { textAlign: 'center' }, content: [{ type: 'text', text: 'Hello again' }] }
)

body = JSON.parse(response.body)
etag = body['etag']
puts body['rejected']['keys'] if body['rejected']

Delete a block

Also deletes the blocks in it. The response has only the new etag.

require "mailerlite-ruby"

# Initialize the class
emails = MailerLite::Emails.new

response = emails.delete_block(email_id: '123456', block_id: '57', etag: 'etag-from-the-last-response')

etag = JSON.parse(response.body)['etag']

Move a block

The BEFORE and AFTER positions also need a block_id. The SDK sends placement as you give it.

require "mailerlite-ruby"

# Initialize the class
emails = MailerLite::Emails.new

response = emails.move_block(
  email_id: '123456',
  block_id: '57',
  etag: 'etag-from-the-last-response',
  placement: { position: MailerLite::Emails::BlockPosition::AFTER, block_id: '12' }
)

etag = JSON.parse(response.body)['etag']

Validate a block

Checks a block before you insert it. It needs no email and no etag. An invalid block is not an error: the response has valid set to false and the errors for each field.

If a valid block has attributes or mobile keys that the block type does not declare, the response has rejected with a message and these keys. Insert and update drop these keys. When valid is false, the response has no rejected.

The block in this example is not valid, because sideways is not a valid textAlign. The response has valid: false and errors.

require "mailerlite-ruby"

# Initialize the class
emails = MailerLite::Emails.new

response = emails.validate_block(
  type: MailerLite::Emails::BlockType::PARAGRAPH,
  editor_content: { attrs: { textAlign: 'sideways' } }
)

body = JSON.parse(response.body)
puts body['errors'] unless body['valid']

Update the design settings

Send only the keys to change, in the shape of settings in the email. The groups are brand, layout, typography, button and footer.

  • The SDK sends exactly the keys of the Hash. A key that is not in the Hash does not change.
  • To unset a brand colour, send an empty string. The API stores the value empty, and the email then uses the account value.
  • To unset a footer text, send an empty editor document: { editor_content: {} } or { editor_content: { content: [] } }.
  • Other colours, sizes, button.border_radius and brand.style cannot be empty. An empty string gives a 422 error.
  • Send all style values as strings, for example '16' and not 16.
  • The API stores each value that you send, also a value that the email inherits from your account. Then the email no longer follows your account for that value.
  • footer.social_links replaces the whole list. Keep the link_id of each link to keep its click history.
  • brand.mode is one of MailerLite::Emails::BrandMode. To apply a preset palette, send its identifier from the brand styles in brand.style.
  • Do not put etag in the settings. Use the etag argument.
  • If the API removed unsafe values, the response has rejected with the keys of these values.
require "mailerlite-ruby"

# Initialize the class
emails = MailerLite::Emails.new

response = emails.update_settings(
  email_id: '123456',
  etag: 'etag-from-the-last-response',
  settings: {
    brand: { mode: MailerLite::Emails::BrandMode::CUSTOM, background_color: '#f4f4f4' },
    typography: { paragraph: { p1: { size: '18' } } }
  }
)

body = JSON.parse(response.body)
etag = body['etag']
puts body['rejected']['keys'] if body['rejected']

Validate the design settings

Checks a change with the rules of the update, and saves nothing. It needs no etag. Invalid settings are not an error: the response has valid set to false and the errors for each field.

require "mailerlite-ruby"

# Initialize the class
emails = MailerLite::Emails.new

response = emails.validate_settings(email_id: '123456', settings: { button: { border_radius: '8' } })

body = JSON.parse(response.body)
puts body['errors'] unless body['valid']

Save an email as a template

Copies the email to a new template. The API cannot delete templates.

require "mailerlite-ruby"

# Initialize the class
emails = MailerLite::Emails.new

response = emails.create_template(email_id: '123456', name: 'Monthly newsletter')

template_id = JSON.parse(response.body)['data']['id']

List the versions of an email

A version is a saved copy of the content and the settings of an email. The list starts with the newest version. current marks the version that the email has now.

require "mailerlite-ruby"

# Initialize the class
emails = MailerLite::Emails.new

response = emails.list_versions('123456', page: 1, limit: 10)

versions = JSON.parse(response.body)['data']

Save a version of an email

Writes through the API do not save versions. If nothing changed after the last version, the API saves no new version and returns the last version. response.code is 201 for a new version and 200 for the last version.

require "mailerlite-ruby"

# Initialize the class
emails = MailerLite::Emails.new

response = emails.create_version('123456')

version_id = JSON.parse(response.body)['data']['id']
is_new = response.code == 201

Restore a version of an email

Puts the email back to the version, and returns the full email with the new etag. Before the restore, the API saves the current state as a version, so you can undo the restore.

require "mailerlite-ruby"

# Initialize the class
emails = MailerLite::Emails.new

response = emails.restore_version(email_id: '123456', version_id: '901', etag: 'etag-from-the-last-response')

etag = JSON.parse(response.body)['etag']

Retry a write with an idempotency key

If a write fails with a network error, you do not know if the API did the write. Give the write an idempotency_key, and send it again with the same key and the same arguments. If the first request was a success, the API returns the stored response and does not do the write two times. Then response.idempotent_replay? is true.

  • Use a new key for each write. The API keeps a key for 24 hours.
  • The key must be 1 to 255 printable ASCII characters. The SDK sends the key as you give it. For a key that is not valid, the API returns 400.
  • The same key with different arguments returns 422. If the first request is still running, the API returns 409 without a code.
  • These methods accept a key: create_block, update_block, delete_block, move_block, update_settings, create_template, create_version and restore_version.
require "mailerlite-ruby"
require "securerandom"

# Initialize the class
emails = MailerLite::Emails.new

args = {
  email_id: '123456',
  etag: 'etag-from-the-last-response',
  type: MailerLite::Emails::BlockType::DIVIDER,
  editor_content: {},
  idempotency_key: SecureRandom.uuid
}

begin
  response = emails.create_block(**args)
rescue HTTP::ConnectionError, HTTP::TimeoutError
  # Network error: send the write again with the same key and the same arguments.
  response = emails.create_block(**args)
end

error = response.api_error
raise error if error

puts JSON.parse(response.body)['data']['id'], response.idempotent_replay?

Brand styles

Get the brand styles

Returns the palettes of your account: brand (your brand styles, or nil if your account has none), default and the presets. Match a palette on its identifier, not on its name. To apply a preset to an email, update the design settings with { brand: { style: identifier } }.

require "mailerlite-ruby"

# Initialize the class
brand_styles = MailerLite::BrandStyles.new

response = brand_styles.get

identifiers = JSON.parse(response.body)['data']['presets'].map { |preset| preset['identifier'] }

Files

List all files

Returns the files of your media library. Use their url in image blocks. width and height are nil for files that are not images.

  • filter: name (a part of the file name) and type (one of MailerLite::Files::FileType).
  • sort: one of MailerLite::Files::FileSort. The default is newest first.
  • The SDK does not send nil values.
require "mailerlite-ruby"

# Initialize the class
files = MailerLite::Files.new

response = files.list(
  filter: { name: 'summer sale', type: MailerLite::Files::FileType::IMAGE },
  sort: MailerLite::Files::FileSort::SIZE_DESC,
  page: 1,
  limit: 25
)

urls = JSON.parse(response.body)['data'].map { |file| file['url'] }

Forms

List all forms

require "mailerlite-ruby"

# Intialize the class
forms = MailerLite::Forms.new

forms.list(limit:10, page:1, sort:'name', filter:{'name': 'form name'})

Get a form

require "mailerlite-ruby"

# Intialize the class
forms = MailerLite::Forms.new

form_id = 123456

forms.fetch(form_id)

Update a form

require "mailerlite-ruby"

# Intialize the class
forms = MailerLite::Forms.new

forms.update(form_id:123456, name: 'My form Name')

Delete a form

require "mailerlite-ruby"

# Intialize the class
forms = MailerLite::Forms.new

form_id = 123456

forms.delete(form_id)

Get subscribers who signed up to a specific form

require "mailerlite-ruby"

# Intialize the class
forms = MailerLite::Forms.new

forms.fetch_subscribers(form_id:123345, page:1, limit:10, filter:{'status': 'active'})

Batching

Create a new batch

require "mailerlite-ruby"

# Intialize the class
batch = MailerLite::Batch.new

batch.request(
          requests: [
            { method: 'GET', path: 'api/subscribers/list' },
            { method: 'GET', path: 'api/campaigns/list' }
          ]
        )

Webhooks

List all webhooks

require "mailerlite-ruby"

# Intialize the class
subscribers = MailerLite::Subscribers.new

webhooks.list()

Get a webhook

require "mailerlite-ruby"

# Intialize the class
subscribers = MailerLite::Subscribers.new

webhook_id = 123456

webhooks.get(webhook_id)

Create a webhook

require "mailerlite-ruby"

# Intialize the class
webhooks = MailerLite::Webhooks.new

webhooks.create(
  events:[
    'subscriber.created',
    'subscriber.updated',
    'subscriber.unsubscribed'
  ],
  url:'https://my-url.com',
  name: 'Webhook name'
)

Update a webhook

require "mailerlite-ruby"

# Intialize the class
webhooks = MailerLite::Webhooks.new

webhooks.update(
  webhook_id: 123456,
  events:[
    'subscriber.created',
    'subscriber.updated',
    'subscriber.unsubscribed'
  ],
  url:'https://my-url.com',
  name: 'Webhook name',
  enabled: false
)

Delete a webhook

require "mailerlite-ruby"

# Intialize the class
webhooks = MailerLite::Webhooks.new

webhook_id = 123456

webhooks.delete(webhook_id)

Timezones

Get a list of timezones

require "mailerlite-ruby"

# Intialize the class
timezones = MailerLite::Timezones.new

timezones.list()

Campaign languages

Get a list of languages

require "mailerlite-ruby"

# Intialize the class
campaigns = MailerLite::Campaigns.new

campaigns.languages()

E-commerce

Shops

require "mailerlite-ruby"

shops = MailerLite::Ecommerce::Shops.new

shops.list(limit: 25)
shops.get('shop_id')
shops.create({ name: 'My shop', url: 'https://shop.example.com', currency: 'EUR' })
shops.update(shop_id: 'shop_id', params: { name: 'New name' })
shops.delete('shop_id')

Products and variants

products = MailerLite::Ecommerce::Products.new

products.list(shop_id: 'shop_id', filter: { enabled: true }, sort: '-created_at')
products.get(shop_id: 'shop_id', product_id: 'product_id')
products.create(shop_id: 'shop_id', params: { name: 'Red T-shirt', price: 19.99 })
products.update(shop_id: 'shop_id', product_id: 'product_id', params: { price: 24.99 })
products.delete(shop_id: 'shop_id', product_id: 'product_id')
products.change_status(shop_id: 'shop_id', product_id: 'product_id', enabled: false)
products.assign_categories(shop_id: 'shop_id', product_id: 'product_id', category_ids: ['category_id'], replace: true)

variants = MailerLite::Ecommerce::ProductVariants.new

variants.list(shop_id: 'shop_id', product_id: 'product_id')
variants.sync(shop_id: 'shop_id', product_id: 'product_id', variants: [{ name: 'Large', attributes: { size: 'L' }, resource_id: 'variant-l' }])
variants.update(shop_id: 'shop_id', product_id: 'product_id', variant_id: 'variant_id', params: { name: 'Extra large', attributes: { size: 'XL' } })
variants.delete(shop_id: 'shop_id', product_id: 'product_id', variant_id: 'variant_id')

Categories

categories = MailerLite::Ecommerce::Categories.new

categories.list(shop_id: 'shop_id')
categories.get(shop_id: 'shop_id', category_id: 'category_id')
categories.create(shop_id: 'shop_id', params: { name: 'Hats' })
categories.update(shop_id: 'shop_id', category_id: 'category_id', params: { name: 'Caps' })
categories.delete(shop_id: 'shop_id', category_id: 'category_id')
categories.products(shop_id: 'shop_id', category_id: 'category_id')
categories.assign_product(shop_id: 'shop_id', category_id: 'category_id', product_id: 'product_id')
categories.unassign_product(shop_id: 'shop_id', category_id: 'category_id', product_id: 'product_id')

Customers, orders and carts

customers = MailerLite::Ecommerce::Customers.new
customers.list(shop_id: 'shop_id', filter: { email: 'customer@example.com' })
customers.create(shop_id: 'shop_id', params: { email: 'customer@example.com', create_subscriber: true })
customers.update(shop_id: 'shop_id', customer_id: 'customer_id', params: { name: 'Jane' })
customers.delete(shop_id: 'shop_id', customer_id: 'customer_id')

orders = MailerLite::Ecommerce::Orders.new
orders.list(shop_id: 'shop_id', filter: { attributed: true, email_id: 'email_id' })
orders.create(shop_id: 'shop_id', params: {
  customer: { email: 'customer@example.com' },
  cart: { items: [{ ecommerce_product_id: 'product_id', quantity: 1, price: 19.99 }] },
  status: 'complete'
})
orders.update(shop_id: 'shop_id', order_id: 'order_id', params: { status: 'complete' })
orders.delete(shop_id: 'shop_id', order_id: 'order_id')

carts = MailerLite::Ecommerce::Carts.new
carts.list(shop_id: 'shop_id')
carts.update(shop_id: 'shop_id', cart_id: 'cart_id', params: { checkout_url: 'https://shop.example.com/cart' })

cart_items = MailerLite::Ecommerce::CartItems.new
cart_items.list(shop_id: 'shop_id', cart_id: 'cart_id')
cart_items.update(shop_id: 'shop_id', cart_id: 'cart_id', item_id: 'item_id', params: { quantity: 2 })
cart_items.delete(shop_id: 'shop_id', cart_id: 'cart_id', item_id: 'item_id')

Imports

imports = MailerLite::Ecommerce::Imports.new

imports.products(shop_id: 'shop_id', products: [{ name: 'Red T-shirt', price: 19.99 }])
imports.categories(shop_id: 'shop_id', categories: [{ name: 'Hats' }])
imports.customers(shop_id: 'shop_id', customers: [{ email: 'customer@example.com' }])

Revenue reports and settings

MailerLite::Ecommerce::Shops.new.stats(shop_id: 'shop_id', start_date: '2026-10-01', end_date: '2026-10-31')

campaigns = MailerLite::Campaigns.new
campaigns.ecommerce_stats(campaign_id: 'campaign_id', shop_id: 'shop_id')
campaigns.ecommerce_orders(campaign_id: 'campaign_id', shop_id: 'shop_id')

subscribers = MailerLite::Subscribers.new
subscribers.ecommerce_stats(subscriber_id: 'subscriber_id', shop_id: 'shop_id')
subscribers.ecommerce_orders(subscriber_id: 'subscriber_id', shop_id: 'shop_id')

automations = MailerLite::Automations.new
automations.ecommerce_stats(automation_id: 'automation_id')
automations.email_ecommerce_stats(automation_id: 'automation_id', email_id: 'email_id')
automations.ecommerce_orders(automation_id: 'automation_id', time_frame: 'all_time')

MailerLite::Ecommerce::Settings.new.get

Testing

bundle i
bundle exec rspec spec/*rspec.rb

To run tests you would need to install gems using bundle and then run rspec via bundle to run all tests. The fixtures for the test have been recorded using vcr and are available in the ./fixtures directory

Generate Docs

bundle i
bundle exec yardoc 'lib/**/*.rb'

This will generate html docs in the doc directory which can be opened up in any browser. Navigate to index.html and open it up.

About

No description or website provided.

Topics

Resources

Stars

12 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages