Official Ruby client for the Socialstats Enterprise API.
RubyGems: https://rubygems.org/gems/socialstats-ruby-sdk
API Documentation: https://developers.stats.company/socialstats
API Key Access: Please contact api@socialstats.com
- Ruby >= 3.2
Add to your Gemfile:
gem "socialstats-ruby-sdk"
Then install:
bundle install
Or install directly via RubyGems:
gem install socialstats-ruby-sdk
require "socialstats_sdk"
client = SocialstatsSDK::Client.new(
api_key: ENV["SOCIALSTATS_API_KEY"]
)
# API status
status = client.info.status
# Creator information
creator = client.creators.info(
socialstats_creator_id: "d3rvjgk2"
)
# Creator statistics
creator_stats = client.creators.stats(
socialstats_creator_id: "d3rvjgk2",
source: "instagram"
)
# Post statistics
post_stats = client.posts.stats(
socialstats_creator_id: "d3rvjgk2",
source_id: "tiktok",
post_id: "7654234001833610518"
)
# Start and poll a creator authorization
authorization = client.oauth.create(
socialstats_creator_id: "d3rvjgk2",
source_id: "youtube",
return_url: "https://customer.example.com/socialstats/oauth-return"
)
authorization_status = client.oauth.attempt_status(authorization["state_token"])
All requests include your API key in the apikey header.
You can generate an API key in your Socialstats Enterprise dashboard.
We recommend storing your key securely in environment variables:
export SOCIALSTATS_API_KEY=your_key_here
client.infoclient.creatorsclient.postsclient.oauth
Creator-scoped methods accept socialstats_creator_id, instagram_creator_id, facebook_creator_id, youtube_creator_id, or tiktok_creator_id. Platform-specific identifiers may be either the platform's internal ID or its username.
Info endpoints:
client.info.sources->/sourcesclient.info.status->/statusclient.info.uptime_check->/uptime_checkclient.info.definitions->/definitions
Creator endpoints:
client.creators.info(...)->/creators/infoclient.creators.stats(...)->/creators/statsclient.creators.historic_stats(...)->/creators/historic_statsclient.creators.audience(...)->/creators/audienceclient.creators.audience_details(country_code: ..., ...)->/creators/audience/detailsclient.creators.activities(...)->/creators/activitiesclient.creators.content(...)->/creators/contentclient.creators.authorized_stats(...)->/creators/authorized/statsclient.creators.authorized_historic_stats(...)->/creators/authorized/historic_statsclient.creators.authorized_audience(...)->/creators/authorized/audienceclient.creators.authorized_content(...)->/creators/authorized/contentclient.creators.top_posts(...)->/creators/top_postsclient.creators.search(q: ..., ...)->/creators/searchclient.creators.add_link_request(link: ..., ...)->/creators/link_requestclient.creators.remove_link_request(link: ..., ...)->/creators/link_request
Post endpoints:
client.posts.stats(...)->/posts/statsclient.posts.historic_stats(...)->/posts/historic_statsclient.posts.authorized_stats(...)->/posts/authorized/{source_id}/statsclient.posts.authorized_historic_stats(...)->/posts/authorized/{source_id}/historic_stats
OAuth endpoints:
client.oauth.create(...)->POST /oauthclient.oauth.list(...)->GET /oauthclient.oauth.get(...)->GET /oauth/{id}client.oauth.revoke(...)->DELETE /oauth/{id}client.oauth.attempt_status(...)->GET /oauth-attempts/{state_token}
begin
client.creators.info(socialstats_creator_id: "invalid")
rescue SocialstatsSDK::SocialstatsAPIError => e
puts "API error: #{e.message}"
rescue SocialstatsSDK::SocialstatsTransportError => e
puts "Transport error: #{e.message}"
end
To work on the SDK locally:
git clone https://github.com/songstats/socialstats-ruby-sdk.git
cd socialstats-ruby-sdk
bundle install
This SDK follows Semantic Versioning (SemVer).
MIT