Idiomatic Ruby gem with Rails integration and ActiveRecord-like syntax
gem install jewelmusic
Or add to your Gemfile:
gem 'jewelmusic', '~> 2.1.0'
require 'jewelmusic'
# Configure the client
JewelMusic.configure do |config|
config.api_key = ENV['JEWELMUSIC_API_KEY']
config.environment = :production # or :sandbox
config.timeout = 30
config.max_retries = 3
end
# Upload a track
track = JewelMusic::Track.create(
file: File.open('song.mp3'),
title: 'My Song',
artist: 'Artist Name',
album: 'Album Name',
genre: 'Electronic',
release_date: '2025-09-01'
)
puts "Track uploaded: #{track.id}"
# Rails integration
class MusicController < ApplicationController
def upload
@track = JewelMusic::Track.create(track_params)
redirect_to @track if @track.persisted?
end
private
def track_params
params.require(:track).permit(:file, :title, :artist, :album)
end
end
# Find tracks
track = JewelMusic::Track.find('track_id')
tracks = JewelMusic::Track.all
recent = JewelMusic::Track.where(created_at: 1.week.ago..Time.now)
# Create and update
track = JewelMusic::Track.new(
title: 'My Song',
artist: 'Artist Name'
)
track.file = File.open('song.mp3')
track.save!
# Update attributes
track.update(title: 'New Title')
# Destroy
track.destroy
# Batch operations
JewelMusic::Track.create([
{ title: 'Song 1', file: file1 },
{ title: 'Song 2', file: file2 }
])
# Scopes and chains
JewelMusic::Track
.where(genre: 'Electronic')
.where('duration > ?', 180)
.order(created_at: :desc)
.limit(10)
# Create a release
release = JewelMusic::Release.create(
type: :album,
title: 'My Album',
artist: 'Artist Name',
tracks: [track1, track2, track3],
release_date: 30.days.from_now,
platforms: [:spotify, :apple_music, :youtube_music],
territories: [:worldwide]
)
# Add tracks to existing release
release.tracks << track4
release.save
# Schedule distribution
distribution = release.distribute(
schedule_for: 1.week.from_now,
notify_platforms: true
)
# Check status
if distribution.live?
puts "Release is live on #{distribution.live_platforms.join(', ')}"
end
# Rails background job integration
class ReleaseJob < ApplicationJob
def perform(release_id)
release = JewelMusic::Release.find(release_id)
release.distribute
end
end
# app/controllers/webhooks_controller.rb
class WebhooksController < ApplicationController
skip_before_action :verify_authenticity_token
before_action :verify_webhook_signature
def jewelmusic
event = JewelMusic::Webhook.construct_event(
request.body.read,
request.headers['X-JewelMusic-Signature'],
ENV['WEBHOOK_SECRET']
)
case event.type
when 'track.processed'
handle_track_processed(event.data)
when 'release.live'
handle_release_live(event.data)
when 'royalty.reported'
handle_royalty_reported(event.data)
end
head :ok
rescue JewelMusic::SignatureVerificationError => e
head :unauthorized
end
private
def verify_webhook_signature
JewelMusic::Webhook.verify_signature(
request.body.read,
request.headers['X-JewelMusic-Signature'],
ENV['WEBHOOK_SECRET']
)
end
def handle_track_processed(data)
TrackProcessedJob.perform_later(data[:track_id])
end
end
# config/routes.rb
post '/webhooks/jewelmusic', to: 'webhooks#jewelmusic'