SDKs overview

Cloverly provides Software Development Kits (SDKs) and client libraries designed to facilitate integration with its Carbon Emissions and Carbon Offsetting APIs. These SDKs abstract the underlying RESTful API calls, handling authentication, request formatting, and response parsing, which allows developers to focus on application logic rather than direct HTTP interactions. The availability of SDKs across multiple programming languages supports a broad range of development environments and simplifies the process of embedding sustainability features into various applications, from e-commerce platforms to logistics management systems. Developers can find comprehensive guides and reference materials in the Cloverly documentation portal.

The Cloverly API itself is built on standard web technologies, using HTTP methods for operations and JSON for data interchange, as detailed in the Cloverly API overview. This adherence to web standards, combined with the convenience of SDKs, aims to provide a streamlined developer experience for integrating carbon calculation and offsetting functionalities.

Official SDKs by language

Cloverly maintains official SDKs for several popular programming languages, ensuring direct support and compatibility with the latest API versions. These SDKs are developed and maintained by Cloverly to provide a consistent and reliable integration experience. The table below outlines the currently supported official SDKs, their respective package names, and typical installation commands.

Language Package Name Installation Command Maturity
Node.js @cloverly/sdk npm install @cloverly/sdk or yarn add @cloverly/sdk Stable
Python cloverly pip install cloverly Stable
Ruby cloverly-ruby gem install cloverly-ruby Stable
PHP cloverly/cloverly-php composer require cloverly/cloverly-php Stable
.NET Cloverly.Net dotnet add package Cloverly.Net Stable

Each SDK is designed to encapsulate the complexity of API calls, allowing developers to interact with Cloverly services using native language constructs. For instance, the Cloverly Node.js SDK documentation provides specific instructions and examples for JavaScript environments.

Installation

Installing Cloverly SDKs typically follows the standard package management practices for each respective programming language. Below are common installation instructions for the official SDKs. Prior to installation, ensure you have the appropriate package manager (npm/yarn for Node.js, pip for Python, gem for Ruby, composer for PHP, and .NET CLI for .NET) configured in your development environment.

Node.js

For Node.js projects, use npm or yarn to add the Cloverly SDK:

npm install @cloverly/sdk
# or
yarn add @cloverly/sdk

Python

Python developers can install the Cloverly SDK using pip:

pip install cloverly

Ruby

For Ruby applications, the SDK is available as a gem:

gem install cloverly-ruby

PHP

PHP projects typically use Composer for dependency management:

composer require cloverly/cloverly-php

.NET

.NET developers can add the Cloverly NuGet package using the .NET CLI or Visual Studio's NuGet Package Manager:

dotnet add package Cloverly.Net

After installation, you will need your Cloverly API key, which can be obtained from your Cloverly account dashboard, to authenticate your SDK requests. The handling of API keys should follow secure practices, such as using environment variables, as recommended by security guidelines for API key management best practices.

Quickstart example

The following example demonstrates a basic usage of the Cloverly Node.js SDK to calculate the carbon footprint for a shipping event. This quickstart illustrates the common pattern of initializing the SDK with an API key, defining a payload, and making an API call.

const Cloverly = require('@cloverly/sdk');

// Initialize the Cloverly SDK with your API key
// It's recommended to use environment variables for API keys
const cloverly = new Cloverly(process.env.CLOVERLY_API_KEY);

async function calculateShippingFootprint() {
  try {
    const response = await cloverly.footprints.shipping({
      weight: {
        value: 5,
        units: 'kg'
      },
      transport_method: 'truck',
      origin: {
        latitude: 34.0522,
        longitude: -118.2437 // Los Angeles
      },
      destination: {
        latitude: 40.7128,
        longitude: -74.0060 // New York
      }
    });

    console.log('Carbon Footprint Calculation:');
    console.log(`Carbon (g): ${response.carbon_g}`);
    console.log(`Estimated Cost (USD): $${response.cost.amount}`);

    // Example of offsetting the footprint
    // const offsetResponse = await cloverly.offsets.create({
    //   transaction_id: 'unique-transaction-id-123',
    //   carbon_g: response.carbon_g,
    //   // ... other offset details
    // });
    // console.log('Offset created:', offsetResponse);

  } catch (error) {
    console.error('Error calculating carbon footprint:', error.message);
    if (error.response) {
      console.error('API Error Details:', error.response.data);
    }
  }
}

calculateShippingFootprint();

This example demonstrates how to perform a carbon footprint calculation for a hypothetical package shipment. The footprints.shipping method takes an object specifying the weight, transport method, and origin/destination coordinates. The response includes the calculated carbon emissions in grams and an estimated cost for offsetting. For more detailed examples and specific API endpoints, refer to the Cloverly API reference documentation.

Community libraries

While Cloverly provides a set of officially supported SDKs, the open nature of its RESTful API allows for the development of community-contributed libraries and integrations. These community-driven projects can offer support for additional programming languages, frameworks, or specific use cases not covered by the official SDKs. Developers often create such libraries to integrate Cloverly with platforms like Shopify, WooCommerce, or custom e-commerce solutions, sometimes extending functionality with features like local caching or advanced error handling.

Community libraries are typically hosted on platforms like GitHub and are often distributed via language-specific package managers. When considering a community library, it is advisable to review its documentation, community support, and recent activity to ensure it aligns with your project's requirements and maintenance standards. Although not officially supported by Cloverly, these libraries can provide valuable alternatives for niche development needs or preferred technology stacks. Always verify the source and security of third-party libraries before integrating them into production systems, as outlined in general secure coding guidelines.