### Run Mailbluster Demo Script Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/README.md Execute the demo script located in the 'bin' directory to create example leads in Mailbluster. Requires the API key to be set as an environment variable. ```bash env MAILBLUSTER_API_KEY=your-api-key ruby bin/demo ``` -------------------------------- ### Create and Read Lead with Mailbluster Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/README.md Example of creating a new lead and then reading it using the Mailbluster Ruby client. Ensure the client is initialized before use. ```ruby mailbluster_client = Mailbluster::Client.new lead = mailbluster_client.leads.create(email: 'lead@example.org') puts lead.inspect # => #, @raw_attributes={"id"=>262093545 ...}> mailbluster_client.leads.read(lead.email) # => #, @raw_attributes={"id"=>262093545 ...}> ``` -------------------------------- ### Initialize and Use Mailbluster Client Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/client.md Instantiate the Mailbluster client and perform operations like creating and reading leads. This example demonstrates basic client interaction with the leads resource. ```ruby mailbluster_client = Mailbluster::Client.new lead = mailbluster_client.leads.create(email: 'lead@example.org') puts lead.inspect mailbluster_client.leads.read(lead.id) ``` -------------------------------- ### Install Mailbluster Gem Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/README.md Install the Mailbluster gem using either the 'gem install' command or by adding it to your Gemfile with Bundler. ```bash gem install mailbluster ``` ```bash bundler add mailbluster ``` -------------------------------- ### Install and Configure Mailbluster Gem Source: https://context7.com/tanaylakhani/mailbluster-ruby/llms.txt Add the gem to your Gemfile and configure your API key globally, via environment variable, or per client instance. ```ruby gem 'mailbluster' ``` ```ruby Mailbluster.configure do |config| config.api_key = 'your-api-key' end ``` ```ruby # MAILBLUSTER_API_KEY=your-api-key ruby app.rb ``` ```ruby mailbluster_client = Mailbluster::Client.new('your-api-key') ``` -------------------------------- ### Mailbluster Custom Fields Resource Operations Source: https://context7.com/tanaylakhani/mailbluster-ruby/llms.txt Manage custom merge-tag fields for leads. Fields are identified by numeric IDs. Includes examples for creating and reading all fields. ```ruby client = Mailbluster::Client.new # CREATE a custom field field = client.fields.create( "fieldLabel" => "Gender", "fieldMergeTag" => "gender" ) # => # ``` ```ruby # READ all fields (returns an array of Resource objects) all_fields = client.fields.read first_field = all_fields.first puts first_field.raw_attributes["fieldLabel"] # => "Gender" ``` -------------------------------- ### Mailbluster Leads Resource CRUD Operations Source: https://context7.com/tanaylakhani/mailbluster-ruby/llms.txt Perform CRUD operations on Mailbluster leads. Email addresses are automatically MD5 hashed internally. Includes examples for creating, reading, updating, deleting, and error handling. ```ruby client = Mailbluster::Client.new # CREATE a lead lead = client.leads.create( "firstName" => "Richard", "lastName" => "Hendricks", "email" => "richard@example.com", "ipAddress" => "162.213.1.246", "subscribed" => false, "doubleOptIn" => true, "fields" => { "gender" => "Male", "address" => "Silicon Valley" }, "meta" => { "company" => "Pied Piper", "role" => "CEO" }, "tags" => ["iPhone User", "Startup"], "overrideExisting" => true ) # => #, ...> ``` ```ruby # READ a lead by email (auto-MD5 hashed) or by MD5 hash directly lead = client.leads.read("richard@example.com") puts lead.raw_attributes["email"] # => "richard@example.com" ``` ```ruby # UPDATE a lead updated_lead = client.leads.update( "richard@example.com", "subscribed" => true, "fields" => { "address" => nil, "hobby" => "Programming" }, "meta" => { "company" => "Piper Net" }, "addTags" => ["Entrepreneur"], "removeTags" => ["iPhone User"] ) ``` ```ruby # DELETE a lead — returns the MD5 hash of the email result = client.leads.delete("richard@example.com") # => "5a91f0b2d2c1e5c3229d906d978b7337" ``` ```ruby # Error handling begin client.leads.read("nonexistent@example.com") rescue Mailbluster::Client::NotFound => e puts "Lead not found: #{e.message}" rescue Mailbluster::Client::Forbidden => e puts "Invalid API key: #{e.message}" rescue Mailbluster::Client::UnprocessableEntity => e puts "Validation error: #{e.message}" end ``` -------------------------------- ### Create Product Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/resources/products.md Creates a new product with the provided attributes. ```APIDOC ## Create Product ### Description Creates a new product. ### Method POST (inferred from create operation) ### Endpoint /products (inferred from resource context) ### Request Body - **id** (string) - Required - The unique identifier for the product. - **name** (string) - Required - The name of the product. ### Request Example ```ruby mailbluster_client = Mailbluster::Client.new create_product_attributes = { "id": "101", "name": "Reign Html Template" } created_product = mailbluster_client.products.create(create_product_attributes) ``` ### Response #### Success Response (200) - **product** (object) - The created product object. ### Response Example (Response structure not explicitly defined in source) ``` -------------------------------- ### Create a Product with Mailbluster Ruby Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/resources/products.md Use this snippet to create a new product. Ensure you have initialized the Mailbluster client and prepared the product attributes. ```ruby mailbluster_client = Mailbluster::Client.new create_product_attributes = { "id": "101", "name": "Reign Html Template" } created_product = mailbluster_client.products.create( create_product_attributes ) ``` -------------------------------- ### Instantiate a Client Source: https://context7.com/tanaylakhani/mailbluster-ruby/llms.txt Creates a new API client. Resolves the API key from the argument, the global config, or the MAILBLUSTER_API_KEY environment variable (in that order). ```APIDOC ## Mailbluster::Client.new — Instantiate a Client Creates a new API client. Resolves the API key from the argument, the global config, or the `MAILBLUSTER_API_KEY` environment variable (in that order). ```ruby # From global config client = Mailbluster::Client.new # Explicit key client = Mailbluster::Client.new('mb_live_xxxxxxxxxxxx') # With a custom logger logger = Logger.new($stdout) client = Mailbluster::Client.new('mb_live_xxxxxxxxxxxx', logger) # Access a resource type via dynamic method or generic accessor client.leads # => # client.fields # => # client.products # => # client.orders # => # client.resource("leads") # equivalent generic accessor ``` ``` -------------------------------- ### Create a product Source: https://context7.com/tanaylakhani/mailbluster-ruby/llms.txt Creates a new product in the Mailbluster catalog. Requires a product ID and name. ```ruby product = client.products.create( "id" => "101", "name" => "Reign Html Template" ) ``` -------------------------------- ### Create an order Source: https://context7.com/tanaylakhani/mailbluster-ruby/llms.txt Creates a new customer order, linking customer data with purchased products. Requires order details including customer information and items. ```ruby order = client.orders.create( "id" => "order_id_0001", "currency" => "USD", "totalPrice" => 10.43, "customer" => { "firstName" => "Richard", "lastName" => "Hendricks", "email" => "richard@example.com", "subscribed" => true, "fields" => { "gender" => "Male", "address" => "Silicon Valley" } }, "items" => [ { "id" => "101", "name" => "Reign Html Template", "price" => 2.13, "quantity" => 1 }, { "id" => "102", "name" => "Slick Html Template", "price" => 4.15, "quantity" => 2 } ] ) ``` -------------------------------- ### Read a Single Product with Mailbluster Ruby Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/resources/products.md Retrieve a specific product by its ID. Initialize the client before making the request. ```ruby mailbluster_client = Mailbluster::Client.new found_product = mailbluster_client.products.read(101) ``` -------------------------------- ### Instantiate Client with API Key Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/configuration.md Create a new Mailbluster::Client instance by passing the API key directly during initialization. This is useful for single-instance configurations. ```ruby mailbluster_client = Mailbluster::Client.new('your-api-key') ``` -------------------------------- ### Sample Attributes for Lead Creation Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/README.md Defines a hash containing sample attributes for creating a lead, including personal details, custom fields, contact information, and subscription settings. ```ruby create_lead_attributes = { "firstName" => "Richard", "lastName" => "Hendricks", "fields" => { "gender" => "Male", "address" => "Silicon Valley" }, "email" => "richard@example.com", "ipAddress" => "162.213.1.246", "subscribed" => false, "doubleOptIn" => true, "meta" => { "company" => "Pied Piper", "role" => "CEO" }, "tags" => [ "iPhone User", "Startup" ], "overrideExisting" => true } ``` -------------------------------- ### Create a Lead with Mailbluster Ruby Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/resources/leads.md Use this to create a new lead. It supports custom fields, meta-data, and tags. Ensure `doubleOptIn` is set appropriately for your email sending strategy. ```ruby mailbluster_client = Mailbluster::Client.new create_lead_attributes = { "firstName": "Richard", "lastName": "Hendricks", "fields" => { "gender": "Male", "address": "Silicon Valley" }, "email": "richard@example.com", "ipAddress": "162.213.1.246", "subscribed": false, "doubleOptIn": true, "meta": { "company": "Pied Piper", "role": "CEO" }, "tags": [ "iPhone User", "Startup" ], "overrideExisting": true } created_lead = mailbluster_client.leads.create( create_lead_attributes ) ``` -------------------------------- ### Read Product(s) Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/resources/products.md Retrieves a single product by its ID or a list of products with pagination. ```APIDOC ## Read Product(s) ### Description Retrieves a single product by ID or a list of products with pagination. ### Method GET (inferred from read operation) ### Endpoint /products/{id} (for single product) /products (for multiple products) ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the product to retrieve. #### Query Parameters - **page_no** (integer) - Optional - The page number for retrieving multiple products. ### Request Example One product: ```ruby mailbluster_client = Mailbluster::Client.new found_product = mailbluster_client.products.read(101) ``` Many products: ```ruby mailbluster_client = Mailbluster::Client.new found_products = mailbluster_client.products.read(page_no: 1) found_product = found_products.first ``` ### Response #### Success Response (200) - **product** (object) - The requested product object (for single read). - **products** (array) - A list of product objects (for multiple read). ### Response Example (Response structure not explicitly defined in source) ``` -------------------------------- ### Create Order Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/resources/orders.md Creates a new order with specified details including customer information, currency, total price, and items. ```APIDOC ## Create Order ### Description Creates a new order with specified details including customer information, currency, total price, and items. ### Method `mailbluster_client.orders.create` ### Request Body Example ```json { "id": "order_id_0001", "customer": { "firstName": "Richard", "lastName": "Hendricks", "fields": { "gender": "Male", "address": "Silicon Valley" }, "email": "richard@example.com", "subscribed": true }, "currency": "USD", "totalPrice": 10.43, "items": [ { "id": "101", "name": "Reign Html Template", "price": 2.13, "quantity": 1 }, { "id": "102", "name": "Slick Html Template", "price": 4.15, "quantity": 2 } ] } ``` ``` -------------------------------- ### Read Many Products with Mailbluster Ruby Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/resources/products.md Fetch a list of products, optionally paginated. The first product from the list can be accessed directly. ```ruby mailbluster_client = Mailbluster::Client.new found_products = mailbluster_client.products.read(page_no: 1) found_product = found_products.first ``` -------------------------------- ### Instantiate Mailbluster API Client Source: https://context7.com/tanaylakhani/mailbluster-ruby/llms.txt Create a new API client, resolving the API key from arguments, global config, or environment variable. Access resource types via dynamic methods or generic accessors. ```ruby client = Mailbluster::Client.new ``` ```ruby client = Mailbluster::Client.new('mb_live_xxxxxxxxxxxx') ``` ```ruby logger = Logger.new($stdout) client = Mailbluster::Client.new('mb_live_xxxxxxxxxxxx', logger) ``` ```ruby client.leads # => # client.fields # => # client.products # => # client.orders # => # client.resource("leads") # equivalent generic accessor ``` -------------------------------- ### Create Lead Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/resources/leads.md Creates a new lead with the provided attributes. You can include custom fields, subscription status, metadata, and tags. ```APIDOC ## Create Lead ### Description Creates a new lead with the provided attributes. You can include custom fields, subscription status, metadata, and tags. ### Method POST (assumed based on create operation) ### Endpoint /leads (assumed based on client.leads.create) ### Request Body - **firstName** (string) - Required - The first name of the lead. - **lastName** (string) - Required - The last name of the lead. - **fields** (object) - Optional - A key-value map for custom lead fields. - **gender** (string) - Optional - Example custom field. - **address** (string) - Optional - Example custom field. - **email** (string) - Required - The email address of the lead. - **ipAddress** (string) - Optional - The IP address from which the lead originated. - **subscribed** (boolean) - Optional - Whether the lead is subscribed to emails. - **doubleOptIn** (boolean) - Optional - Whether double opt-in is enabled for this lead. - **meta** (object) - Optional - Metadata associated with the lead. - **company** (string) - Optional - Example metadata field. - **role** (string) - Optional - Example metadata field. - **tags** (array of strings) - Optional - Tags to associate with the lead. - **overrideExisting** (boolean) - Optional - Whether to override existing lead data if a lead with the same email already exists. ### Request Example ```json { "firstName": "Richard", "lastName": "Hendricks", "fields": { "gender": "Male", "address": "Silicon Valley" }, "email": "richard@example.com", "ipAddress": "162.213.1.246", "subscribed": false, "doubleOptIn": true, "meta": { "company": "Pied Piper", "role": "CEO" }, "tags": [ "iPhone User", "Startup" ], "overrideExisting": true } ``` ### Response #### Success Response (200) - **lead** (object) - The created lead object. #### Response Example ```json { "lead": { "id": "generated_lead_id", "firstName": "Richard", "lastName": "Hendricks", "email": "richard@example.com" // ... other lead details } } ``` ``` -------------------------------- ### Create an Order with Mailbluster Ruby Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/resources/orders.md Use this snippet to create a new order. Ensure all required fields for customer, currency, total price, and items are provided. ```ruby mailbluster_client = Mailbluster::Client.new create_order_attributes = { "id": "order_id_0001", "customer" => { "firstName": "Richard", "lastName": "Hendricks", "fields" => { "gender": "Male", "address": "Silicon Valley" }, "email": "richard@example.com", "subscribed": true }, "currency": "USD", "totalPrice": 10.43, "items" => [ { "id": "101", "name": "Reign Html Template", "price": 2.13, "quantity": 1 }, { "id": "102", "name": "Slick Html Template", "price": 4.15, "quantity": 2 } ] } created_order = mailbluster_client.orders.create( create_order_attributes ) ``` -------------------------------- ### Read a single product by ID Source: https://context7.com/tanaylakhani/mailbluster-ruby/llms.txt Retrieves a single product from the catalog using its ID. The product's name can be accessed via `raw_attributes`. ```ruby product = client.products.read(101) puts product.raw_attributes["name"] # => "Reign Html Template" ``` -------------------------------- ### Products Resource Source: https://context7.com/tanaylakhani/mailbluster-ruby/llms.txt Manages product catalog entries. Supports creating, reading (single and paginated), updating, and deleting products. ```APIDOC ## CREATE a product Creates a new product in the catalog. ### Method POST ### Endpoint /products ### Parameters #### Request Body - **id** (string) - Required - The unique identifier for the product. - **name** (string) - Required - The name of the product. ### Request Example ```ruby client.products.create( "id" => "101", "name" => "Reign Html Template" ) ``` ## READ a single product by ID Retrieves a specific product using its ID. ### Method GET ### Endpoint /products/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the product to retrieve. ### Request Example ```ruby client.products.read(101) ``` ## READ paginated products Retrieves a list of products with pagination support. ### Method GET ### Endpoint /products ### Parameters #### Query Parameters - **page_no** (integer) - Optional - The page number to retrieve. ### Request Example ```ruby client.products.read(page_no: 1) ``` ## UPDATE a product Updates an existing product identified by its ID. ### Method PUT ### Endpoint /products/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the product to update. #### Request Body - **name** (string) - Required - The updated name of the product. ### Request Example ```ruby client.products.update(101, "name" => "Reign PRO Html Template") ``` ## DELETE a product Deletes a product by its ID. Returns the ID of the deleted product. ### Method DELETE ### Endpoint /products/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the product to delete. ### Request Example ```ruby client.products.delete(101) ``` ### Response Example ```ruby # => 101 ``` ``` -------------------------------- ### Update a product Source: https://context7.com/tanaylakhani/mailbluster-ruby/llms.txt Updates an existing product in the catalog. Requires the product ID and a hash of attributes to update. ```ruby updated = client.products.update(101, "name" => "Reign PRO Html Template") ``` -------------------------------- ### Read Fields Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/resources/fields.md Retrieves a list of all existing fields. ```APIDOC ## Read Fields ### Description Retrieves a list of all existing fields. ### Method GET (inferred from read operation) ### Endpoint /fields (inferred from client.fields.read) ### Response #### Success Response (200) - **fields** (array) - A list of field objects. - **field** (object) - Details of a field. - **id** (integer) - The unique identifier of the field. - **fieldLabel** (string) - The label of the field. - **fieldMergeTag** (string) - The merge tag of the field. ### Request Example ```ruby mailbluster_client = Mailbluster::Client.new found_fields = mailbluster_client.fields.read found_field = found_fields.first ``` ### Response Example ```json [ { "id": 1234, "fieldLabel": "Gender", "fieldMergeTag": "gender" }, { "id": 5678, "fieldLabel": "City", "fieldMergeTag": "city" } ] ``` ``` -------------------------------- ### Configure API Key with Block Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/configuration.md Set the API key using the Mailbluster.configure block. Ensure the API key is kept secret. ```ruby Mailbluster.configure do |config| config.api_key = 'your-api-key' end ``` -------------------------------- ### Create Field Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/resources/fields.md Creates a new field with the specified label and merge tag. ```APIDOC ## Create Field ### Description Creates a new field with the specified label and merge tag. ### Method POST (inferred from create operation) ### Endpoint /fields (inferred from client.fields.create) ### Parameters #### Request Body - **fieldLabel** (string) - Required - The label for the field. - **fieldMergeTag** (string) - Required - The merge tag for the field. ### Request Example ```ruby mailbluster_client = Mailbluster::Client.new create_field_attributes = { "fieldLabel": "Gender", "fieldMergeTag": "gender" } created_field = mailbluster_client.fields.create(create_field_attributes) ``` ### Response #### Success Response (200) - **field** (object) - Details of the created field. - **id** (integer) - The unique identifier of the created field. - **fieldLabel** (string) - The label of the field. - **fieldMergeTag** (string) - The merge tag of the field. #### Response Example ```json { "id": 1234, "fieldLabel": "Gender", "fieldMergeTag": "gender" } ``` ``` -------------------------------- ### Read paginated products Source: https://context7.com/tanaylakhani/mailbluster-ruby/llms.txt Retrieves a paginated list of products. Use `page_no` to specify the desired page. ```ruby page_one = client.products.read(page_no: 1) # => Array of Mailbluster::Resource objects puts page_one.first.raw_attributes["id"] ``` -------------------------------- ### Configure API Key with Environment Variable Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/configuration.md Set the API key using the MAILBLUSTER_API_KEY environment variable before running your application. This is a common practice for managing secrets. ```bash env MAILBLUSTER_API_KEY=your-api-key ruby app.rb ``` -------------------------------- ### Update Product Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/resources/products.md Updates an existing product with new attributes. ```APIDOC ## Update Product ### Description Updates an existing product identified by its ID. ### Method PUT (inferred from update operation) ### Endpoint /products/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the product to update. #### Request Body - **name** (string) - Optional - The new name for the product. ### Request Example ```ruby mailbluster_client = Mailbluster::Client.new updated_product = mailbluster_client.resource("products").update( 101, { "name": "Reign PRO Html Template" } ) ``` ### Response #### Success Response (200) - **product** (object) - The updated product object. ### Response Example (Response structure not explicitly defined in source) ``` -------------------------------- ### Read All Fields - Ruby Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/resources/fields.md Retrieve a list of all custom fields associated with your Mailbluster account. The client must be initialized first. ```ruby mailbluster_client = Mailbluster::Client.new found_fields = mailbluster_client.fields.read found_field = found_fields.first ``` -------------------------------- ### Update a Product with Mailbluster Ruby Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/resources/products.md Modify an existing product's details using its ID and the updated attributes. The Mailbluster client must be initialized. ```ruby mailbluster_client = Mailbluster::Client.new updated_product = mailbluster_client.resource("products").update( 101, { "name": "Reign PRO Html Template" } ) ``` -------------------------------- ### Configure Mailbluster API Key Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/README.md Configure the Mailbluster gem with your API key either globally using a block, via environment variables, or directly when creating a client instance. ```ruby Mailbluster.configure do |config| config.api_key = 'your-api-key' end ``` ```bash env MAILBLUSTER_API_KEY=your-api-key ruby app.rb ``` ```ruby mailbluster_client = Mailbluster::Client.new('your-api-key') ``` -------------------------------- ### Handle Mailbluster::Client::NotFound error Source: https://context7.com/tanaylakhani/mailbluster-ruby/llms.txt Catches HTTP 404 errors, indicating that the requested resource does not exist. ```ruby rescue Mailbluster::Client::NotFound => e # HTTP 404 — resource does not exist puts e.message ``` -------------------------------- ### Read Multiple Orders with Mailbluster Ruby Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/resources/orders.md Fetch a list of orders, optionally paginated. Use the `page_no` parameter to specify the desired page. ```ruby mailbluster_client = Mailbluster::Client.new found_orders = mailbluster_client.orders.read(page_no: 1) found_order = found_orders.first ``` -------------------------------- ### Read a Lead by Email with Mailbluster Ruby Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/resources/leads.md Retrieve lead details by providing the lead's email address. This is useful for checking existing lead information. ```ruby mailbluster_client = Mailbluster::Client.new found_lead = mailbluster_client.leads.read("richard@example.com") ``` -------------------------------- ### Delete a product Source: https://context7.com/tanaylakhani/mailbluster-ruby/llms.txt Deletes a product from the catalog using its ID. Returns the ID of the deleted product. ```ruby result = client.products.delete(101) # => 101 ``` -------------------------------- ### Global Configuration Source: https://context7.com/tanaylakhani/mailbluster-ruby/llms.txt Configure the Mailbluster gem globally with an API key, optional custom API URL, and an optional logger. The default API URL is https://api.mailbluster.com/api/. ```APIDOC ## Mailbluster.configure — Global Configuration Configures the gem globally with an API key, optional custom API URL, and an optional logger. The default API URL is `https://api.mailbluster.com/api/`. ```ruby require 'logger' Mailbluster.configure do |config| config.api_key = 'mb_live_xxxxxxxxxxxx' config.api_url = 'https://api.mailbluster.com/api/' # optional override config.logger = Logger.new($stdout) # optional logger end # Access current config puts Mailbluster.configuration.api_key # => "mb_live_xxxxxxxxxxxx" ``` ``` -------------------------------- ### Delete Product Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/resources/products.md Deletes a product by its ID. ```APIDOC ## Delete Product ### Description Deletes a product identified by its ID. ### Method DELETE (inferred from delete operation) ### Endpoint /products/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the product to delete. ### Request Example ```ruby mailbluster_client = Mailbluster::Client.new deleted_response = mailbluster_client.products.delete(101) deleted_response # => 101 ``` ### Response #### Success Response (200) - **id** (integer) - The ID of the deleted product. ### Response Example (Response structure not explicitly defined in source, but example shows ID returned) ``` -------------------------------- ### Read Lead Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/resources/leads.md Retrieves a lead's information using their email address. ```APIDOC ## Read Lead ### Description Retrieves a lead's information using their email address. ### Method GET (assumed based on read operation) ### Endpoint /leads/{email} (assumed based on client.leads.read) ### Parameters #### Path Parameters - **email** (string) - Required - The email address of the lead to retrieve. ### Response #### Success Response (200) - **lead** (object) - The lead object matching the provided email. #### Response Example ```json { "lead": { "id": "lead_id_found", "firstName": "Richard", "lastName": "Hendricks", "email": "richard@example.com" // ... other lead details } } ``` ``` -------------------------------- ### Inspect a Mailbluster::Resource object Source: https://context7.com/tanaylakhani/mailbluster-ruby/llms.txt Provides a string representation of a Mailbluster::Resource object, useful for debugging. ```ruby puts lead.inspect # => #, # @raw_attributes={"id"=>262093545, "email"=>"richard@example.com", ...}> ``` -------------------------------- ### Read Order Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/resources/orders.md Retrieves a specific order by its ID or fetches a list of orders with pagination. ```APIDOC ## Read Order ### Description Retrieves a specific order by its ID or fetches a list of orders with pagination. ### Method `mailbluster_client.orders.read` ### Parameters #### Path Parameters - **order_id** (string) - Required - The unique identifier of the order to retrieve. - **page_no** (integer) - Optional - The page number to retrieve for a list of orders. ### Request Example (Single Order) ```ruby mailbluster_client.orders.read("order_id_0001") ``` ### Request Example (Multiple Orders) ```ruby mailbluster_client.orders.read(page_no: 1) ``` ``` -------------------------------- ### Access dynamically generated snake_case methods Source: https://context7.com/tanaylakhani/mailbluster-ruby/llms.txt Demonstrates accessing resource attributes using dynamically generated snake_case methods, which are converted from API response camelCase keys. ```ruby lead.first_name # => "Richard" (from "firstName") lead.last_name # => "Hendricks" (from "lastName") lead.ip_address # => "162.213.1.246" (from "ipAddress") ``` -------------------------------- ### Leads Resource Source: https://context7.com/tanaylakhani/mailbluster-ruby/llms.txt Provides CRUD access to Mailbluster leads (subscribers). When passing an email address as identifier, the library automatically converts it to an MD5 hash internally. ```APIDOC ## Client#leads — Leads Resource Provides CRUD access to Mailbluster leads (subscribers). When passing an email address as identifier, the library automatically converts it to an MD5 hash internally. ```ruby client = Mailbluster::Client.new # CREATE a lead lead = client.leads.create( "firstName" => "Richard", "lastName" => "Hendricks", "email" => "richard@example.com", "ipAddress" => "162.213.1.246", "subscribed" => false, "doubleOptIn" => true, "fields" => { "gender" => "Male", "address" => "Silicon Valley" }, "meta" => { "company" => "Pied Piper", "role" => "CEO" }, "tags" => ["iPhone User", "Startup"], "overrideExisting" => true ) # => #, ...> # READ a lead by email (auto-MD5 hashed) or by MD5 hash directly lead = client.leads.read("richard@example.com") puts lead.raw_attributes["email"] # => "richard@example.com" # UPDATE a lead updated_lead = client.leads.update( "richard@example.com", "subscribed" => true, "fields" => { "address" => nil, "hobby" => "Programming" }, "meta" => { "company" => "Piper Net" }, "addTags" => ["Entrepreneur"], "removeTags" => ["iPhone User"] ) # DELETE a lead — returns the MD5 hash of the email result = client.leads.delete("richard@example.com") # => "5a91f0b2d2c1e5c3229d906d978b7337" # Error handling begin client.leads.read("nonexistent@example.com") rescue Mailbluster::Client::NotFound => e puts "Lead not found: #{e.message}" rescue Mailbluster::Client::Forbidden => e puts "Invalid API key: #{e.message}" rescue Mailbluster::Client::UnprocessableEntity => e puts "Validation error: #{e.message}" end ``` ``` -------------------------------- ### Orders Resource Source: https://context7.com/tanaylakhani/mailbluster-ruby/llms.txt Manages customer orders, linking customer data with purchased products. Supports creating, reading (single and paginated), updating, and deleting orders. ```APIDOC ## CREATE an order Creates a new customer order. ### Method POST ### Endpoint /orders ### Parameters #### Request Body - **id** (string) - Required - The unique identifier for the order. - **currency** (string) - Required - The currency of the order total. - **totalPrice** (number) - Required - The total price of the order. - **customer** (object) - Required - Information about the customer. - **firstName** (string) - Optional - The customer's first name. - **lastName** (string) - Optional - The customer's last name. - **email** (string) - Optional - The customer's email address. - **subscribed** (boolean) - Optional - Whether the customer is subscribed. - **fields** (object) - Optional - Custom fields for the customer. - **items** (array) - Required - A list of items in the order. - **id** (string) - Required - The ID of the product item. - **name** (string) - Required - The name of the product item. - **price** (number) - Required - The price of the item. - **quantity** (integer) - Required - The quantity of the item. ### Request Example ```ruby client.orders.create( "id" => "order_id_0001", "currency" => "USD", "totalPrice" => 10.43, "customer" => { "firstName" => "Richard", "lastName" => "Hendricks", "email" => "richard@example.com", "subscribed" => true, "fields" => { "gender" => "Male", "address" => "Silicon Valley" } }, "items" => [ { "id" => "101", "name" => "Reign Html Template", "price" => 2.13, "quantity" => 1 }, { "id" => "102", "name" => "Slick Html Template", "price" => 4.15, "quantity" => 2 } ] ) ``` ## READ a single order by ID Retrieves a specific order using its ID. ### Method GET ### Endpoint /orders/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the order to retrieve. ### Request Example ```ruby client.orders.read("order_id_0001") ``` ## READ paginated orders Retrieves a list of orders with pagination support. ### Method GET ### Endpoint /orders ### Parameters #### Query Parameters - **page_no** (integer) - Optional - The page number to retrieve. ### Request Example ```ruby client.orders.read(page_no: 1) ``` ## UPDATE an order Updates an existing order identified by its ID. ### Method PUT ### Endpoint /orders/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the order to update. #### Request Body - **currency** (string) - Optional - The updated currency of the order. - **totalPrice** (number) - Optional - The updated total price of the order. - **campaignId** (integer) - Optional - The ID of the campaign associated with the order. - **customer** (object) - Optional - Updated customer information. - **subscribed** (boolean) - Optional - Updated subscription status. - **tags** (array) - Optional - List of tags for the customer. - **meta** (object) - Optional - Metadata for the customer. - **gender** (string) - Optional - The gender of the customer. - **items** (array) - Optional - Updated list of items in the order. - **id** (string) - Required - The ID of the product item. - **name** (string) - Required - The name of the product item. - **price** (number) - Required - The price of the item. - **quantity** (integer) - Required - The quantity of the item. ### Request Example ```ruby client.orders.update( "order_id_0001", "currency" => "USD", "totalPrice" => 17.28, "campaignId" => 2, "customer" => { "subscribed" => false, "tags" => ["Developer"], "meta" => { "gender" => "Male" } }, "items" => [ { "id" => "103", "name" => "Falcon Html Template", "price" => 4.49, "quantity" => 2 }, { "id" => "102", "name" => "Slick Html Template", "price" => 4.15, "quantity" => 2 } ] ) ``` ## DELETE an order Deletes an order by its ID. Returns the ID of the deleted order. ### Method DELETE ### Endpoint /orders/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the order to delete. ### Request Example ```ruby client.orders.delete("order_id_0001") ``` ### Response Example ```ruby # => "order_id_0001" ``` ``` -------------------------------- ### Read a single order by ID Source: https://context7.com/tanaylakhani/mailbluster-ruby/llms.txt Retrieves a specific order using its unique ID. ```ruby order = client.orders.read("order_id_0001") ``` -------------------------------- ### Global Mailbluster Configuration Source: https://context7.com/tanaylakhani/mailbluster-ruby/llms.txt Configure the Mailbluster gem globally with an API key, an optional custom API URL, and an optional logger. Accesses the current configuration. ```ruby require 'logger' Mailbluster.configure do |config| config.api_key = 'mb_live_xxxxxxxxxxxx' config.api_url = 'https://api.mailbluster.com/api/' # optional override config.logger = Logger.new($stdout) # optional logger end ``` ```ruby puts Mailbluster.configuration.api_key # => "mb_live_xxxxxxxxxxxx" ``` -------------------------------- ### Read paginated orders Source: https://context7.com/tanaylakhani/mailbluster-ruby/llms.txt Retrieves a paginated list of orders. Use `page_no` to specify the desired page. ```ruby page_one = client.orders.read(page_no: 1) ``` -------------------------------- ### Delete a Product with Mailbluster Ruby Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/resources/products.md Remove a product from the system using its ID. The response will typically confirm the deleted ID. ```ruby mailbluster_client = Mailbluster::Client.new deleted_response = mailbluster_client.products.delete(101) deleted_response # => 101 ``` -------------------------------- ### Update Lead Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/resources/leads.md Updates an existing lead's information. You can modify custom fields, subscription status, metadata, and manage tags. ```APIDOC ## Update Lead ### Description Updates an existing lead's information. You can modify custom fields, subscription status, metadata, and manage tags. ### Method PUT or PATCH (assumed based on update operation) ### Endpoint /leads/{email} (assumed based on client.resource("leads").update) ### Parameters #### Path Parameters - **email** (string) - Required - The email address of the lead to update. #### Request Body - **fields** (object) - Optional - A key-value map for custom lead fields. Setting a field to `nil` will remove it. - **gender** (string) - Optional - Example custom field. - **address** (string or null) - Optional - Example custom field. Set to `null` to remove. - **hobby** (string) - Optional - Example custom field to add. - **subscribed** (boolean) - Optional - The new subscription status for the lead. - **meta** (object) - Optional - Updated metadata for the lead. - **company** (string) - Optional - Example metadata field. - **addTags** (array of strings) - Optional - Tags to add to the lead. - **removeTags** (array of strings) - Optional - Tags to remove from the lead. ### Request Example ```json { "fields": { "gender": "Male", "address": null, "hobby": "Programming" }, "subscribed": true, "meta": { "company": "Piper Net" }, "addTags": [ "Entrepreneur" ], "removeTags": [ "iPhone User" ] } ``` ### Response #### Success Response (200) - **lead** (object) - The updated lead object. #### Response Example ```json { "lead": { "id": "lead_id_updated", "email": "richard@example.com", "subscribed": true // ... other updated lead details } } ``` ``` -------------------------------- ### Mailbluster::Resource - Response Objects Source: https://context7.com/tanaylakhani/mailbluster-ruby/llms.txt Details on how to access and use `Mailbluster::Resource` objects returned from API operations, including accessing raw attributes and dynamically generated methods. ```APIDOC ## Accessing Raw API Response Hash All CRUD operations return `Mailbluster::Resource` instances. You can access the original API response hash using the `raw_attributes` method. ### Method `raw_attributes` ### Usage ```ruby lead = client.leads.read("richard@example.com") lead.raw_attributes # => { "id" => 262093545, "email" => "richard@example.com", "firstName" => "Richard", ... } ``` ## Dynamically Generated Methods Resource objects dynamically define accessor methods from API response keys. CamelCase keys are converted to snake_case. ### Usage ```ruby lead.first_name # => "Richard" (from "firstName") lead.last_name # => "Hendricks" (from "lastName") lead.ip_address # => "162.213.1.246" (from "ipAddress") ``` ## Inspecting a Resource Provides a string representation of the `Mailbluster::Resource` object. ### Method `inspect` ### Usage ```ruby puts lead.inspect # => #, # @raw_attributes={"id"=>262093545, "email"=>"richard@example.com", ...}> ``` ``` -------------------------------- ### Custom Fields Resource Source: https://context7.com/tanaylakhani/mailbluster-ruby/llms.txt Manages custom merge-tag fields that can be attached to leads. Fields are identified by numeric IDs on read/update/delete and are listed as a collection. ```APIDOC ## Client#fields — Custom Fields Resource Manages custom merge-tag fields that can be attached to leads. Fields are identified by numeric IDs on read/update/delete and are listed as a collection. ```ruby client = Mailbluster::Client.new # CREATE a custom field field = client.fields.create( "fieldLabel" => "Gender", "fieldMergeTag" => "gender" ) # => # # READ all fields (returns an array of Resource objects) all_fields = client.fields.read first_field = all_fields.first puts first_field.raw_attributes["fieldLabel"] # => "Gender" ``` ``` -------------------------------- ### Update Order Source: https://github.com/tanaylakhani/mailbluster-ruby/blob/main/docs/resources/orders.md Updates an existing order with new details, including customer information, currency, total price, and items. ```APIDOC ## Update Order ### Description Updates an existing order with new details, including customer information, currency, total price, and items. ### Method `mailbluster_client.resource("orders").update` ### Parameters #### Path Parameters - **order_id** (string) - Required - The unique identifier of the order to update. ### Request Body Example ```json { "customer": { "fields": { "gender": "Male", "address": "Silicon Valley" }, "subscribed": false, "meta": { "gender": "Male" }, "tags": [ "Developer" ] }, "campaignId": 2, "currency": "USD", "totalPrice": 17.28, "items": [ { "id": "103", "name": "Falcon Html Template", "price": 4.49, "quantity": 2 }, { "id": "102", "name": "Slick Html Template", "price": 4.15, "quantity": 2 } ] } ``` ```