socialstats-ruby-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +19 -0
- data/LICENSE +21 -0
- data/README.md +136 -0
- data/docs/enterprise_routes_audit.md +43 -0
- data/lib/socialstats_sdk/client.rb +27 -0
- data/lib/socialstats_sdk/errors.rb +22 -0
- data/lib/socialstats_sdk/http_client.rb +143 -0
- data/lib/socialstats_sdk/resources/base.rb +53 -0
- data/lib/socialstats_sdk/resources/creators.rb +75 -0
- data/lib/socialstats_sdk/resources/info.rb +23 -0
- data/lib/socialstats_sdk/resources/posts.rb +29 -0
- data/lib/socialstats_sdk/resources.rb +6 -0
- data/lib/socialstats_sdk/version.rb +5 -0
- data/lib/socialstats_sdk.rb +8 -0
- metadata +82 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 9913c6eb0102ad42654410100eb2a33fe967ee4d99d0e831b9d34e34b7a02c95
|
|
4
|
+
data.tar.gz: 6585f4e2b0bae1eee06e6e8a6aba82124efb9f10495f92a00fc8635f2055f707
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ca3e3dc6d29ac228a25383015048592efed8a66591e864670cd967f4e16ab340c639552b4c39c53b9250199ec6ff4b9ba401de8f470fcd4368d8a5b33adf869c
|
|
7
|
+
data.tar.gz: df8cf7c971eec6f6225d6ae5a4dd896a9256e7ace3fef6e75654f7cee6a5aba8b186157758421f916e04f7c9dbbb31fe550ea1d514797b17b02ee9fc4cd910f2
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.1.0] - 2026-06-25
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Initial standalone Ruby SDK repo for Socialstats Enterprise API (`/enterprise/v1`)
|
|
10
|
+
- Resource coverage:
|
|
11
|
+
- `info`
|
|
12
|
+
- `creators`
|
|
13
|
+
- `posts`
|
|
14
|
+
- Shared HTTP client with:
|
|
15
|
+
- `apikey` header auth
|
|
16
|
+
- JSON response decoding
|
|
17
|
+
- retry/backoff on transport errors and retryable status codes
|
|
18
|
+
- Structured exception types for API and transport failures
|
|
19
|
+
- Route coverage audit doc mapping Rails routes to SDK methods
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Songstats
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# Socialstats Ruby SDK
|
|
2
|
+
|
|
3
|
+
Official Ruby client for the **Socialstats Enterprise API**.
|
|
4
|
+
|
|
5
|
+
RubyGems: https://rubygems.org/gems/socialstats-ruby-sdk
|
|
6
|
+
API Documentation: https://docs.socialstats.com
|
|
7
|
+
API Key Access: Please contact api@socialstats.com
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Requirements
|
|
12
|
+
|
|
13
|
+
- Ruby >= 3.2
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Add to your `Gemfile`:
|
|
20
|
+
|
|
21
|
+
gem "socialstats-ruby-sdk"
|
|
22
|
+
|
|
23
|
+
Then install:
|
|
24
|
+
|
|
25
|
+
bundle install
|
|
26
|
+
|
|
27
|
+
Or install directly via RubyGems:
|
|
28
|
+
|
|
29
|
+
gem install socialstats-ruby-sdk
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
require "socialstats_sdk"
|
|
36
|
+
|
|
37
|
+
client = SocialstatsSDK::Client.new(
|
|
38
|
+
api_key: ENV["SOCIALSTATS_API_KEY"]
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# API status
|
|
42
|
+
status = client.info.status
|
|
43
|
+
|
|
44
|
+
# Creator information
|
|
45
|
+
creator = client.creators.info(
|
|
46
|
+
socialstats_creator_id: "d3rvjgk2"
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
# Creator statistics
|
|
50
|
+
creator_stats = client.creators.stats(
|
|
51
|
+
socialstats_creator_id: "d3rvjgk2",
|
|
52
|
+
source: "instagram"
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
# Post statistics
|
|
56
|
+
post_stats = client.posts.stats(
|
|
57
|
+
socialstats_creator_id: "d3rvjgk2",
|
|
58
|
+
source_id: "tiktok",
|
|
59
|
+
post_id: "7654234001833610518"
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Authentication
|
|
65
|
+
|
|
66
|
+
All requests include your API key in the `apikey` header.
|
|
67
|
+
|
|
68
|
+
You can generate an API key in your Socialstats Enterprise dashboard.
|
|
69
|
+
|
|
70
|
+
We recommend storing your key securely in environment variables:
|
|
71
|
+
|
|
72
|
+
export SOCIALSTATS_API_KEY=your_key_here
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Available Resource Clients
|
|
77
|
+
|
|
78
|
+
- `client.info`
|
|
79
|
+
- `client.creators`
|
|
80
|
+
- `client.posts`
|
|
81
|
+
|
|
82
|
+
Info endpoints:
|
|
83
|
+
- `client.info.sources` -> `/sources`
|
|
84
|
+
- `client.info.status` -> `/status`
|
|
85
|
+
- `client.info.definitions` -> `/definitions`
|
|
86
|
+
|
|
87
|
+
Creator endpoints:
|
|
88
|
+
- `client.creators.info(...)` -> `/creators/info`
|
|
89
|
+
- `client.creators.stats(...)` -> `/creators/stats`
|
|
90
|
+
- `client.creators.historic_stats(...)` -> `/creators/historic_stats`
|
|
91
|
+
- `client.creators.audience(...)` -> `/creators/audience`
|
|
92
|
+
- `client.creators.audience_details(country_code: ..., ...)` -> `/creators/audience/details`
|
|
93
|
+
- `client.creators.activities(...)` -> `/creators/activities`
|
|
94
|
+
- `client.creators.content(...)` -> `/creators/content`
|
|
95
|
+
- `client.creators.top_posts(...)` -> `/creators/top_posts`
|
|
96
|
+
- `client.creators.search(q: ..., ...)` -> `/creators/search`
|
|
97
|
+
- `client.creators.add_link_request(link: ..., ...)` -> `/creators/link_request`
|
|
98
|
+
- `client.creators.remove_link_request(link: ..., ...)` -> `/creators/link_request`
|
|
99
|
+
|
|
100
|
+
Post endpoints:
|
|
101
|
+
- `client.posts.stats(...)` -> `/posts/stats`
|
|
102
|
+
- `client.posts.historic_stats(...)` -> `/posts/historic_stats`
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Error Handling
|
|
107
|
+
|
|
108
|
+
begin
|
|
109
|
+
client.creators.info(socialstats_creator_id: "invalid")
|
|
110
|
+
rescue SocialstatsSDK::SocialstatsAPIError => e
|
|
111
|
+
puts "API error: #{e.message}"
|
|
112
|
+
rescue SocialstatsSDK::SocialstatsTransportError => e
|
|
113
|
+
puts "Transport error: #{e.message}"
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Development
|
|
119
|
+
|
|
120
|
+
To work on the SDK locally:
|
|
121
|
+
|
|
122
|
+
git clone https://github.com/songstats/socialstats-ruby-sdk.git
|
|
123
|
+
cd socialstats-ruby-sdk
|
|
124
|
+
bundle install
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Versioning
|
|
129
|
+
|
|
130
|
+
This SDK follows Semantic Versioning (SemVer).
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## License
|
|
135
|
+
|
|
136
|
+
MIT
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Enterprise Routes Audit (Socialstats Rails -> Ruby SDK)
|
|
2
|
+
|
|
3
|
+
Audited against:
|
|
4
|
+
|
|
5
|
+
- `/Users/Oskar/1001tl/config/routes.rb`
|
|
6
|
+
- `/Users/Oskar/1001tl/app/controllers/enterprise/v1/creators_controller.rb`
|
|
7
|
+
- `/Users/Oskar/1001tl/app/controllers/enterprise/v1/info_controller.rb`
|
|
8
|
+
- `/Users/Oskar/1001tl/app/controllers/enterprise/v1/enterprise_base_controller.rb`
|
|
9
|
+
- `/Users/Oskar/1001tl/docs/socialstats_openapi.yaml`
|
|
10
|
+
|
|
11
|
+
Authentication observed in Rails: `apikey` request header.
|
|
12
|
+
|
|
13
|
+
## `/enterprise/v1/info`
|
|
14
|
+
|
|
15
|
+
| HTTP | Route | SDK Method |
|
|
16
|
+
| ---- | --------------- | -------------------------- |
|
|
17
|
+
| GET | `/sources` | `client.info.sources` |
|
|
18
|
+
| GET | `/status` | `client.info.status` |
|
|
19
|
+
| GET | `/uptime_check` | `client.info.uptime_check` |
|
|
20
|
+
| GET | `/definitions` | `client.info.definitions` |
|
|
21
|
+
|
|
22
|
+
## `/enterprise/v1/creators`
|
|
23
|
+
|
|
24
|
+
| HTTP | Route | SDK Method |
|
|
25
|
+
| ------ | ------------------- | ---------------------------------------------------------- |
|
|
26
|
+
| GET | `/info` | `client.creators.info(...)` |
|
|
27
|
+
| GET | `/stats` | `client.creators.stats(...)` |
|
|
28
|
+
| GET | `/historic_stats` | `client.creators.historic_stats(...)` |
|
|
29
|
+
| GET | `/audience` | `client.creators.audience(...)` |
|
|
30
|
+
| GET | `/audience/details` | `client.creators.audience_details(country_code: ..., ...)` |
|
|
31
|
+
| GET | `/activities` | `client.creators.activities(...)` |
|
|
32
|
+
| GET | `/content` | `client.creators.content(...)` |
|
|
33
|
+
| GET | `/top_posts` | `client.creators.top_posts(...)` |
|
|
34
|
+
| GET | `/search` | `client.creators.search(q: ..., ...)` |
|
|
35
|
+
| POST | `/link_request` | `client.creators.add_link_request(link: ..., ...)` |
|
|
36
|
+
| DELETE | `/link_request` | `client.creators.remove_link_request(link: ..., ...)` |
|
|
37
|
+
|
|
38
|
+
## `/enterprise/v1/posts`
|
|
39
|
+
|
|
40
|
+
| HTTP | Route | SDK Method |
|
|
41
|
+
| ---- | ----------------- | ---------------------------------- |
|
|
42
|
+
| GET | `/stats` | `client.posts.stats(...)` |
|
|
43
|
+
| GET | `/historic_stats` | `client.posts.historic_stats(...)` |
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SocialstatsSDK
|
|
4
|
+
class Client
|
|
5
|
+
attr_reader :info, :creators, :posts
|
|
6
|
+
|
|
7
|
+
def initialize(api_key:, base_url: HTTPClient::DEFAULT_BASE_URL, timeout: HTTPClient::DEFAULT_TIMEOUT_SECONDS,
|
|
8
|
+
max_retries: 2, http_adapter: nil, user_agent: nil)
|
|
9
|
+
@http = HTTPClient.new(
|
|
10
|
+
api_key: api_key,
|
|
11
|
+
base_url: base_url,
|
|
12
|
+
timeout: timeout,
|
|
13
|
+
max_retries: max_retries,
|
|
14
|
+
adapter: http_adapter,
|
|
15
|
+
user_agent: user_agent
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
@info = Resources::Info.new(@http)
|
|
19
|
+
@creators = Resources::Creators.new(@http)
|
|
20
|
+
@posts = Resources::Posts.new(@http)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def close
|
|
24
|
+
@http.close
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SocialstatsSDK
|
|
4
|
+
class SocialstatsError < StandardError; end
|
|
5
|
+
|
|
6
|
+
class SocialstatsTransportError < SocialstatsError; end
|
|
7
|
+
|
|
8
|
+
class SocialstatsAPIError < SocialstatsError
|
|
9
|
+
attr_reader :status_code, :payload
|
|
10
|
+
|
|
11
|
+
def initialize(message:, status_code:, payload: nil)
|
|
12
|
+
@error_message = message
|
|
13
|
+
super(@error_message)
|
|
14
|
+
@status_code = status_code
|
|
15
|
+
@payload = payload
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def to_s
|
|
19
|
+
"Socialstats API error (#{status_code}): #{@error_message}"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "net/http"
|
|
5
|
+
require "uri"
|
|
6
|
+
|
|
7
|
+
module SocialstatsSDK
|
|
8
|
+
HTTPResponse = Struct.new(:status, :body, :headers, keyword_init: true)
|
|
9
|
+
|
|
10
|
+
class NetHTTPAdapter
|
|
11
|
+
METHOD_MAP = {
|
|
12
|
+
get: Net::HTTP::Get,
|
|
13
|
+
post: Net::HTTP::Post,
|
|
14
|
+
delete: Net::HTTP::Delete
|
|
15
|
+
}.freeze
|
|
16
|
+
|
|
17
|
+
def request(method:, base_url:, path:, headers:, params:, json:, timeout:)
|
|
18
|
+
uri = URI.join("#{base_url.chomp('/')}/", path.delete_prefix('/'))
|
|
19
|
+
query = URI.encode_www_form(params || {})
|
|
20
|
+
uri.query = [uri.query, query].compact.reject(&:empty?).join("&") unless query.empty?
|
|
21
|
+
|
|
22
|
+
request_class = METHOD_MAP.fetch(method.to_sym) { raise ArgumentError, "Unsupported HTTP method: #{method}" }
|
|
23
|
+
request = request_class.new(uri)
|
|
24
|
+
headers.each { |key, value| request[key] = value unless value.nil? }
|
|
25
|
+
|
|
26
|
+
if json
|
|
27
|
+
request["content-type"] ||= "application/json"
|
|
28
|
+
request.body = JSON.generate(json)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
32
|
+
http.use_ssl = uri.scheme == "https"
|
|
33
|
+
http.open_timeout = timeout
|
|
34
|
+
http.read_timeout = timeout
|
|
35
|
+
|
|
36
|
+
response = http.request(request)
|
|
37
|
+
HTTPResponse.new(status: response.code.to_i, body: response.body.to_s, headers: response.to_hash)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class HTTPClient
|
|
42
|
+
DEFAULT_BASE_URL = "https://api.socialstats.com"
|
|
43
|
+
DEFAULT_TIMEOUT_SECONDS = 30
|
|
44
|
+
RETRYABLE_STATUS_CODES = [429, 500, 502, 503, 504].freeze
|
|
45
|
+
RETRYABLE_EXCEPTIONS = [
|
|
46
|
+
EOFError,
|
|
47
|
+
IOError,
|
|
48
|
+
SocketError,
|
|
49
|
+
Timeout::Error,
|
|
50
|
+
Errno::ECONNRESET,
|
|
51
|
+
Errno::ECONNREFUSED,
|
|
52
|
+
Errno::ETIMEDOUT,
|
|
53
|
+
Net::OpenTimeout,
|
|
54
|
+
Net::ReadTimeout
|
|
55
|
+
].freeze
|
|
56
|
+
|
|
57
|
+
def initialize(api_key:, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT_SECONDS, max_retries: 2, adapter: nil,
|
|
58
|
+
user_agent: nil)
|
|
59
|
+
raise ArgumentError, "api_key is required" if api_key.to_s.empty?
|
|
60
|
+
raise ArgumentError, "max_retries must be >= 0" if max_retries.to_i.negative?
|
|
61
|
+
|
|
62
|
+
@api_key = api_key
|
|
63
|
+
@base_url = base_url
|
|
64
|
+
@timeout = timeout
|
|
65
|
+
@max_retries = max_retries.to_i
|
|
66
|
+
@adapter = adapter || NetHTTPAdapter.new
|
|
67
|
+
@user_agent = user_agent || "socialstats-ruby-sdk/#{VERSION}"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def close
|
|
71
|
+
@adapter.close if @adapter.respond_to?(:close)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def request(method, path, params: nil, json: nil)
|
|
75
|
+
endpoint = "/enterprise/v1/#{path.to_s.delete_prefix('/')}"
|
|
76
|
+
attempts = 0
|
|
77
|
+
|
|
78
|
+
loop do
|
|
79
|
+
begin
|
|
80
|
+
response = @adapter.request(
|
|
81
|
+
method: method.to_sym,
|
|
82
|
+
base_url: @base_url,
|
|
83
|
+
path: endpoint,
|
|
84
|
+
headers: request_headers,
|
|
85
|
+
params: params,
|
|
86
|
+
json: json,
|
|
87
|
+
timeout: @timeout
|
|
88
|
+
)
|
|
89
|
+
rescue *RETRYABLE_EXCEPTIONS => e
|
|
90
|
+
if attempts < @max_retries
|
|
91
|
+
sleep(backoff_seconds(attempts))
|
|
92
|
+
attempts += 1
|
|
93
|
+
next
|
|
94
|
+
end
|
|
95
|
+
raise SocialstatsTransportError, e.message
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
if RETRYABLE_STATUS_CODES.include?(response.status) && attempts < @max_retries
|
|
99
|
+
sleep(backoff_seconds(attempts))
|
|
100
|
+
attempts += 1
|
|
101
|
+
next
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
return decode_response(response.body) if response.status.between?(200, 299)
|
|
105
|
+
|
|
106
|
+
raise build_api_error(response)
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
private
|
|
111
|
+
|
|
112
|
+
def request_headers
|
|
113
|
+
{
|
|
114
|
+
"apikey" => @api_key,
|
|
115
|
+
"accept" => "application/json",
|
|
116
|
+
"user-agent" => @user_agent
|
|
117
|
+
}
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def backoff_seconds(attempt)
|
|
121
|
+
0.2 * (2**attempt)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def decode_response(body)
|
|
125
|
+
return nil if body.nil? || body.strip.empty?
|
|
126
|
+
|
|
127
|
+
JSON.parse(body)
|
|
128
|
+
rescue JSON::ParserError
|
|
129
|
+
{ "raw" => body }
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def build_api_error(response)
|
|
133
|
+
payload = decode_response(response.body)
|
|
134
|
+
message = "HTTP #{response.status}"
|
|
135
|
+
|
|
136
|
+
if payload.is_a?(Hash)
|
|
137
|
+
message = payload["message"] || payload["error"] || message
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
SocialstatsAPIError.new(message: message, status_code: response.status, payload: payload)
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SocialstatsSDK
|
|
4
|
+
module Resources
|
|
5
|
+
class Base
|
|
6
|
+
def initialize(http_client)
|
|
7
|
+
@http = http_client
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
private
|
|
11
|
+
|
|
12
|
+
def get(path, params: nil)
|
|
13
|
+
@http.request(:get, path, params: normalize_params(params))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def post(path, params: nil, json: nil)
|
|
17
|
+
@http.request(:post, path, params: normalize_params(params), json: normalize_params(json))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def delete(path, params: nil)
|
|
21
|
+
@http.request(:delete, path, params: normalize_params(params))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def normalize_params(params)
|
|
25
|
+
return nil if params.blank?
|
|
26
|
+
|
|
27
|
+
normalized = {}
|
|
28
|
+
params.each do |key, value|
|
|
29
|
+
next if value.nil?
|
|
30
|
+
|
|
31
|
+
normalized[key] = case value
|
|
32
|
+
when true then "true"
|
|
33
|
+
when false then "false"
|
|
34
|
+
when Array then value.map(&:to_s).join(",")
|
|
35
|
+
else value
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
normalized.empty? ? nil : normalized
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def require_any_identifier!(params, identifier_keys)
|
|
43
|
+
has_identifier = identifier_keys.any? do |key|
|
|
44
|
+
value = params[key]
|
|
45
|
+
!value.nil? && value != ""
|
|
46
|
+
end
|
|
47
|
+
return if has_identifier
|
|
48
|
+
|
|
49
|
+
raise ArgumentError, "One identifier is required. Supported keys: #{identifier_keys.join(', ')}"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SocialstatsSDK
|
|
4
|
+
module Resources
|
|
5
|
+
class Creators < Base
|
|
6
|
+
IDENTIFIER_KEYS = %i[socialstats_creator_id].freeze
|
|
7
|
+
|
|
8
|
+
def info(**params)
|
|
9
|
+
get("creators/info", params: with_identifier(params))
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def stats(**params)
|
|
13
|
+
get("creators/stats", params: with_identifier(params))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def historic_stats(**params)
|
|
17
|
+
get("creators/historic_stats", params: with_identifier(params))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def audience(**params)
|
|
21
|
+
get("creators/audience", params: with_identifier(params))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def audience_details(country_code:, **params)
|
|
25
|
+
raise ArgumentError, "country_code is required" if country_code.to_s.empty?
|
|
26
|
+
|
|
27
|
+
query = with_identifier(params)
|
|
28
|
+
query[:country_code] = country_code
|
|
29
|
+
get("creators/audience/details", params: query)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def activities(**params)
|
|
33
|
+
get("creators/activities", params: with_identifier(params))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def content(**params)
|
|
37
|
+
get("creators/content", params: with_identifier(params))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def top_posts(**params)
|
|
41
|
+
get("creators/top_posts", params: with_identifier(params))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def search(q:, **params)
|
|
45
|
+
raise ArgumentError, "q is required" if q.to_s.empty?
|
|
46
|
+
|
|
47
|
+
get("creators/search", params: params.merge(q: q))
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def add_link_request(link:, **params)
|
|
51
|
+
raise ArgumentError, "link is required" if link.to_s.empty?
|
|
52
|
+
|
|
53
|
+
query = with_identifier(params)
|
|
54
|
+
query[:link] = link
|
|
55
|
+
post("creators/link_request", params: query)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def remove_link_request(link:, **params)
|
|
59
|
+
raise ArgumentError, "link is required" if link.to_s.empty?
|
|
60
|
+
|
|
61
|
+
query = with_identifier(params)
|
|
62
|
+
query[:link] = link
|
|
63
|
+
delete("creators/link_request", params: query)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
private
|
|
67
|
+
|
|
68
|
+
def with_identifier(params)
|
|
69
|
+
query = params.dup
|
|
70
|
+
require_any_identifier!(query, IDENTIFIER_KEYS)
|
|
71
|
+
query
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SocialstatsSDK
|
|
4
|
+
module Resources
|
|
5
|
+
class Info < Base
|
|
6
|
+
def sources
|
|
7
|
+
get("sources")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def status
|
|
11
|
+
get("status")
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def uptime_check
|
|
15
|
+
get("uptime_check")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def definitions
|
|
19
|
+
get("definitions")
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SocialstatsSDK
|
|
4
|
+
module Resources
|
|
5
|
+
class Posts < Base
|
|
6
|
+
CREATOR_IDENTIFIER_KEYS = %i[socialstats_creator_id].freeze
|
|
7
|
+
POST_IDENTIFIER_KEYS = %i[post_id id_unique external_id].freeze
|
|
8
|
+
|
|
9
|
+
def stats(source_id:, **params)
|
|
10
|
+
get("posts/stats", params: with_post_identifier(params.merge(source_id: source_id)))
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def historic_stats(source_id:, **params)
|
|
14
|
+
get("posts/historic_stats", params: with_post_identifier(params.merge(source_id: source_id)))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def with_post_identifier(params)
|
|
20
|
+
query = params.dup
|
|
21
|
+
raise ArgumentError, "source_id is required" if query[:source_id].to_s.empty?
|
|
22
|
+
|
|
23
|
+
require_any_identifier!(query, CREATOR_IDENTIFIER_KEYS)
|
|
24
|
+
require_any_identifier!(query, POST_IDENTIFIER_KEYS)
|
|
25
|
+
query
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "socialstats_sdk/version"
|
|
4
|
+
require_relative "socialstats_sdk/errors"
|
|
5
|
+
require "active_support/core_ext/object/blank"
|
|
6
|
+
require_relative "socialstats_sdk/http_client"
|
|
7
|
+
require_relative "socialstats_sdk/resources"
|
|
8
|
+
require_relative "socialstats_sdk/client"
|
metadata
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: socialstats-ruby-sdk
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Songstats
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-06-25 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: activesupport
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '7.0'
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '9.0'
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '7.0'
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '9.0'
|
|
33
|
+
description: Typed Ruby client for Socialstats Enterprise API resources.
|
|
34
|
+
email:
|
|
35
|
+
- api@socialstats.com
|
|
36
|
+
executables: []
|
|
37
|
+
extensions: []
|
|
38
|
+
extra_rdoc_files: []
|
|
39
|
+
files:
|
|
40
|
+
- CHANGELOG.md
|
|
41
|
+
- LICENSE
|
|
42
|
+
- README.md
|
|
43
|
+
- docs/enterprise_routes_audit.md
|
|
44
|
+
- lib/socialstats_sdk.rb
|
|
45
|
+
- lib/socialstats_sdk/client.rb
|
|
46
|
+
- lib/socialstats_sdk/errors.rb
|
|
47
|
+
- lib/socialstats_sdk/http_client.rb
|
|
48
|
+
- lib/socialstats_sdk/resources.rb
|
|
49
|
+
- lib/socialstats_sdk/resources/base.rb
|
|
50
|
+
- lib/socialstats_sdk/resources/creators.rb
|
|
51
|
+
- lib/socialstats_sdk/resources/info.rb
|
|
52
|
+
- lib/socialstats_sdk/resources/posts.rb
|
|
53
|
+
- lib/socialstats_sdk/version.rb
|
|
54
|
+
homepage: https://socialstats.com
|
|
55
|
+
licenses:
|
|
56
|
+
- MIT
|
|
57
|
+
metadata:
|
|
58
|
+
homepage_uri: https://socialstats.com
|
|
59
|
+
source_code_uri: https://github.com/songstats/socialstats-ruby-sdk
|
|
60
|
+
bug_tracker_uri: https://github.com/songstats/socialstats-ruby-sdk/issues
|
|
61
|
+
allowed_push_host: https://rubygems.org
|
|
62
|
+
rubygems_mfa_required: 'true'
|
|
63
|
+
post_install_message:
|
|
64
|
+
rdoc_options: []
|
|
65
|
+
require_paths:
|
|
66
|
+
- lib
|
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
|
+
requirements:
|
|
69
|
+
- - ">="
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: 3.2.0
|
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
|
+
requirements:
|
|
74
|
+
- - ">="
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: '0'
|
|
77
|
+
requirements: []
|
|
78
|
+
rubygems_version: 3.5.17
|
|
79
|
+
signing_key:
|
|
80
|
+
specification_version: 4
|
|
81
|
+
summary: Ruby SDK for the Socialstats Enterprise API.
|
|
82
|
+
test_files: []
|