ifeelgoods

Official Ruby SDK for IFeelGoods Fulfillment API

Package name: ifeelgoods
Module namespace: Ifeelgoods::

Authentication

The Fulfillment API supports two authentication methods:

Option 1: API Key + API Secret (Simple, Direct)

Use this for simple scripts or when you prefer direct authentication:

require 'ifeelgoods'

# Configure the SDK globally
Ifeelgoods.configure do |config|
  config.scheme = 'https' # http for testing only [not recommended for production]
  config.host = 'api.ifeelgoods.com'
  # Sandbox: config.host = 'api-sandbox.ifeelgoods.com'
  config.api_key['Api-Key'] = 'YOUR_API_KEY'
  config.api_key['Api-Secret'] = 'YOUR_API_SECRET'
  config.debugging = ENV['IFEELGOODS_DEBUG'] == 'true' # Optional: Enable debugging
end

# All API instances use the configured settings
accounts_api = Ifeelgoods::AccountsApi.new
result = accounts_api.

puts result.inspect

Use OAuth2 to exchange API Key + Secret for a bearer token, then cache it to avoid repeated token requests.

Environment Setup:

# Set your API credentials
export IFEELGOODS_API_KEY='your-api-key'
export IFEELGOODS_API_SECRET='your-api-secret'

# Set OAuth endpoint (defaults to production)
export IFEELGOODS_OAUTH_URL='https://oauth.ifeelgoods.com'
# Or for sandbox:
# export IFEELGOODS_OAUTH_URL='https://oauth-sandbox.ifeelgoods.com'
require 'ifeelgoods'
require 'net/http'
require 'json'

class OAuthTokenManager
  # Default to production OAuth endpoint. Override with IFEELGOODS_OAUTH_URL environment variable.
  # Production: https://oauth.ifeelgoods.com
  # Sandbox:    https://oauth-sandbox.ifeelgoods.com
  DEFAULT_OAUTH_URL = 'https://oauth.ifeelgoods.com'

  def initialize(api_key = nil, api_secret = nil, oauth_url = nil)
    @api_key = api_key || ENV['IFEELGOODS_API_KEY']
    @api_secret = api_secret || ENV['IFEELGOODS_API_SECRET']
    @oauth_url = oauth_url || ENV['IFEELGOODS_OAUTH_URL'] || DEFAULT_OAUTH_URL

    raise 'IFEELGOODS_API_KEY environment variable not set' if @api_key.nil?
    raise 'IFEELGOODS_API_SECRET environment variable not set' if @api_secret.nil?
    @token = nil
    @token_expires_at = nil
  end

  def access_token
    # Return cached token if still valid
    return @token if @token && Time.now < @token_expires_at

    # Fetch new token
    fetch_new_token
  end

  private

  def fetch_new_token
    uri = URI("#{@oauth_url}/oauth/token")
    
    request = Net::HTTP::Post.new(uri)
    request.basic_auth(@api_key, @api_secret)
    request['Content-Type'] = 'application/x-www-form-urlencoded'
    request.body = 'grant_type=client_credentials'

    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = uri.scheme == 'https'
    response = http.request(request)

    if response.code.to_i == 200
      data = JSON.parse(response.body)
      @token = data['access_token']
      @token_expires_at = Time.now + data['expires_in'] - 60 # Refresh 60s before expiry
      @token
    else
      raise "Failed to get access token: #{response.body}"
    end
  end
end

# Usage
token_manager = OAuthTokenManager.new  # Reads from environment variables

api_client = Ifeelgoods::ApiClient.new
api_client.config.host = 'https://api.ifeelgoods.com'
api_client.config.access_token_getter = -> { token_manager.access_token }

accounts_api = Ifeelgoods::AccountsApi.new(api_client)  # Uses custom API client with token auth
result = accounts_api.

Benefits of Option 2:

  • ✅ Token is cached and reused (fewer network requests)
  • ✅ Automatic refresh before expiry
  • ✅ Recommended for production environments
  • ✅ More secure (API credentials stay server-side)

Installation & Usage

Install from RubyGems

gem install ifeelgoods

Then require it in your code:

ruby -e "require 'ifeelgoods'; puts 'SDK loaded successfully'"

Development: Build & Install Locally

To build and test the SDK from source:

cd ruby/generated/fulfillment-sdk
gem build ifeelgoods.gemspec
gem install ./ifeelgoods-VERSION.gem

Documentation

Full API documentation is available at:

Explore the SDK Locally

Use IRB to explore available classes and methods:

require 'ifeelgoods'

# List all available API classes
Ifeelgoods.constants.grep(/Api$/).sort

# Explore a specific API
Ifeelgoods::AccountsApi.instance_methods(false)