Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Migrate from lago‐ruby‐client

Vincent Pochet edited this page Sep 1, 2023 · 4 revisions

Replace gem in your Gemfile

gem 'lago-ruby-client'

becomes:

gem 'lago_ruby'

Client configuration

require 'lago-ruby-client'

client = Lago::Api::Client.new({api_key: '__YOUR_API_KEY__'})

must be replaced by one of:

Global configuration

require 'lago_ruby'

LagoAPI.configure do |config|
  config.access_token = '__YOUR_API_KEY__'

  # NOTE: if using a self hosted lago instance
  config.host = 'your-base-url.com'
end

Single client configuration

require 'lago_ruby'

lago_config = LagoAPI::Configuration.new
lago_config.access_token = '__YOUR_API_KEY__'

 # NOTE: if using a self hosted lago instance
lago_config.host = 'your-base-url.com'

Send a event to Lago

client.events.create(
  transaction_id: "__UNIQUE_ID__",
  external_customer_id: "__CUSTOMER_ID__",
  external_subscription_id: "__SUBSCRIPTION_ID__",
  code: "__BILLABLE_METRIC_CODE__",
  timestamp: Time.now.to_i,
  properties: {
      custom_field: 12
  }
)

must be replaced by:

api_instance = LagoAPI::EventsApi.new

# Optionaly
client = LagoAPI::ApiClient.new(config)
api_instance = LagoAPI::EventsApi.new(client)

# Init the event payload
event_input = LagoAPI::EventInput.new(
  event: LagoAPI::EventInputEvent.new(
    transaction_id: "transaction_1234567890",
    external_customer_id: "__CUSTOMER_ID__",
    external_subscription_id: "__SUBSCRIPTION_ID__",
    code: "__BILLABLE_METRIC_CODE__",
    timestamp: Time.now.to_i,
    properties: { custom_field: 12 }
  )
)

begin
  api_instance.create_event(event_input)
rescue LagoAPI::ApiError => e
  # Handle error
end

Other routes

Check the API endpoints documentation to migrate other API call.