songstats-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 +25 -0
- data/LICENSE +21 -0
- data/README.md +55 -0
- data/docs/enterprise_routes_audit.md +118 -0
- data/lib/songstats_sdk/client.rb +31 -0
- data/lib/songstats_sdk/errors.rb +22 -0
- data/lib/songstats_sdk/http_client.rb +143 -0
- data/lib/songstats_sdk/resources/base.rb +53 -0
- data/lib/songstats_sdk/resources/charts.rb +14 -0
- data/lib/songstats_sdk/resources/entities.rb +156 -0
- data/lib/songstats_sdk/resources/info.rb +23 -0
- data/lib/songstats_sdk/resources/stations.rb +29 -0
- data/lib/songstats_sdk/resources/tracks.rb +75 -0
- data/lib/songstats_sdk/resources.rb +8 -0
- data/lib/songstats_sdk/version.rb +5 -0
- data/lib/songstats_sdk.rb +7 -0
- metadata +63 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 6e9cfa8f372c183dcde82286fa023415c8fb16b62c7f78652eef43d1128adaca
|
|
4
|
+
data.tar.gz: 995c45f1acab79d840ce4a899577ba4a964284f3ceb5ce72b75bb221e120e22e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: bbf2f0293a3b15963723911ee7679c464d4eb96bdd71468ccfd4e3fb3508021b297aa219252f90fcbf24381b2d2892ec2f423ad3bb4f0d3546342debac10dfeb
|
|
7
|
+
data.tar.gz: e66e21ea1532cd8e0cc8fe6f350af45cd506df7a267a6c79a1a158338727805beeef8a83a0308dabad043d9185f707b232f8649468319d560be645c401f0a0f3
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.1.0] - 2026-02-19
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- Initial standalone Ruby SDK repo for Songstats Enterprise API (`/enterprise/v1`)
|
|
9
|
+
- Full resource coverage:
|
|
10
|
+
- `info`
|
|
11
|
+
- `tracks`
|
|
12
|
+
- `artists`
|
|
13
|
+
- `collaborators`
|
|
14
|
+
- `labels`
|
|
15
|
+
- `charts`
|
|
16
|
+
- `stations`
|
|
17
|
+
- Shared HTTP client with:
|
|
18
|
+
- `apikey` header auth
|
|
19
|
+
- JSON response decoding
|
|
20
|
+
- retry/backoff on transport errors and retryable status codes
|
|
21
|
+
- Structured exception types for API and transport failures
|
|
22
|
+
- Route coverage audit doc mapping Rails routes to SDK methods
|
|
23
|
+
- Test suite covering route mapping, header auth, validation, and error handling
|
|
24
|
+
- GitHub Actions CI workflow (`bundle exec rake test`)
|
|
25
|
+
- GitHub Actions release workflow for tag-based gem publishing (`v*`)
|
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,55 @@
|
|
|
1
|
+
# Songstats Ruby SDK
|
|
2
|
+
|
|
3
|
+
Official Ruby Client SDK for the Songstats Enterprise API.
|
|
4
|
+
|
|
5
|
+
## API Documentation
|
|
6
|
+
|
|
7
|
+
https://docs.songstats.com
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
bundle install
|
|
13
|
+
bundle exec rake test
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
For local usage in another project:
|
|
17
|
+
|
|
18
|
+
```ruby
|
|
19
|
+
gem "songstats-ruby-sdk", path: "/path/to/songstats-ruby-sdk"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
require "songstats_sdk"
|
|
26
|
+
|
|
27
|
+
client = SongstatsSDK::Client.new(api_key: "YOUR_API_KEY")
|
|
28
|
+
|
|
29
|
+
status = client.info.status
|
|
30
|
+
track = client.tracks.info(songstats_track_id: "abcd1234")
|
|
31
|
+
artist_stats = client.artists.stats(songstats_artist_id: "abcd1234", source: "spotify")
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Authentication
|
|
35
|
+
|
|
36
|
+
The SDK sends your key in the `apikey` header, matching Songstats enterprise auth.
|
|
37
|
+
|
|
38
|
+
## Included Resource Clients
|
|
39
|
+
|
|
40
|
+
- `client.info`
|
|
41
|
+
- `client.tracks`
|
|
42
|
+
- `client.artists`
|
|
43
|
+
- `client.collaborators`
|
|
44
|
+
- `client.labels`
|
|
45
|
+
- `client.charts`
|
|
46
|
+
- `client.stations`
|
|
47
|
+
|
|
48
|
+
## Error Handling
|
|
49
|
+
|
|
50
|
+
- `SongstatsSDK::SongstatsAPIError`: non-2xx HTTP response
|
|
51
|
+
- `SongstatsSDK::SongstatsTransportError`: transport/connectivity failure
|
|
52
|
+
|
|
53
|
+
## Route Coverage Audit
|
|
54
|
+
|
|
55
|
+
See `docs/enterprise_routes_audit.md` for the Rails route to SDK method mapping.
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Enterprise Routes Audit (Songstats Rails -> Ruby SDK)
|
|
2
|
+
|
|
3
|
+
Audited against:
|
|
4
|
+
- `/Users/Oskar/1001tl/config/routes.rb`
|
|
5
|
+
- `/Users/Oskar/1001tl/app/controllers/enterprise/v1/*.rb`
|
|
6
|
+
- `/Users/Oskar/1001tl/app/helpers/enterprise_helper.rb`
|
|
7
|
+
|
|
8
|
+
Authentication observed in Rails: `apikey` request header.
|
|
9
|
+
|
|
10
|
+
## `/enterprise/v1/info`
|
|
11
|
+
|
|
12
|
+
| HTTP | Route | SDK Method |
|
|
13
|
+
|---|---|---|
|
|
14
|
+
| GET | `/sources` | `client.info.sources` |
|
|
15
|
+
| GET | `/status` | `client.info.status` |
|
|
16
|
+
| GET | `/uptime_check` | `client.info.uptime_check` |
|
|
17
|
+
| GET | `/definitions` | `client.info.definitions` |
|
|
18
|
+
|
|
19
|
+
## `/enterprise/v1/tracks`
|
|
20
|
+
|
|
21
|
+
| HTTP | Route | SDK Method |
|
|
22
|
+
|---|---|---|
|
|
23
|
+
| GET | `/info` | `client.tracks.info(...)` |
|
|
24
|
+
| GET | `/stats` | `client.tracks.stats(...)` |
|
|
25
|
+
| GET | `/historic_stats` | `client.tracks.historic_stats(...)` |
|
|
26
|
+
| GET | `/search` | `client.tracks.search(q: ..., ...)` |
|
|
27
|
+
| GET | `/activities` | `client.tracks.activities(...)` |
|
|
28
|
+
| GET | `/comments` | `client.tracks.comments(...)` |
|
|
29
|
+
| GET | `/songshare` | `client.tracks.songshare(...)` |
|
|
30
|
+
| GET | `/locations` | `client.tracks.locations(...)` |
|
|
31
|
+
| POST | `/link_request` | `client.tracks.add_link_request(link: ..., ...)` |
|
|
32
|
+
| DELETE | `/link_request` | `client.tracks.remove_link_request(link: ..., ...)` |
|
|
33
|
+
| POST | `/add_to_member_relevant_list` | `client.tracks.add_to_member_relevant_list(...)` |
|
|
34
|
+
| DELETE | `/remove_from_member_relevant_list` | `client.tracks.remove_from_member_relevant_list(...)` |
|
|
35
|
+
|
|
36
|
+
## `/enterprise/v1/charts`
|
|
37
|
+
|
|
38
|
+
| HTTP | Route | SDK Method |
|
|
39
|
+
|---|---|---|
|
|
40
|
+
| GET | `/tracks` | `client.charts.tracks(country_code: ..., ...)` |
|
|
41
|
+
|
|
42
|
+
## `/enterprise/v1/stations`
|
|
43
|
+
|
|
44
|
+
| HTTP | Route | SDK Method |
|
|
45
|
+
|---|---|---|
|
|
46
|
+
| POST | `/station_request` | `client.stations.station_request(...)` |
|
|
47
|
+
|
|
48
|
+
## `/enterprise/v1/artists`
|
|
49
|
+
|
|
50
|
+
| HTTP | Route | SDK Method |
|
|
51
|
+
|---|---|---|
|
|
52
|
+
| GET | `/info` | `client.artists.info(...)` |
|
|
53
|
+
| GET | `/stats` | `client.artists.stats(...)` |
|
|
54
|
+
| GET | `/historic_stats` | `client.artists.historic_stats(...)` |
|
|
55
|
+
| GET | `/audience` | `client.artists.audience(...)` |
|
|
56
|
+
| GET | `/audience/details` | `client.artists.audience_details(country_code: ..., ...)` |
|
|
57
|
+
| GET | `/catalog` | `client.artists.catalog(...)` |
|
|
58
|
+
| GET | `/search` | `client.artists.search(q: ..., ...)` |
|
|
59
|
+
| GET | `/activities` | `client.artists.activities(...)` |
|
|
60
|
+
| GET | `/songshare` | `client.artists.songshare(...)` |
|
|
61
|
+
| GET | `/top_tracks` | `client.artists.top_tracks(...)` |
|
|
62
|
+
| GET | `/top_playlists` | `client.artists.top_playlists(...)` |
|
|
63
|
+
| GET | `/top_curators` | `client.artists.top_curators(...)` |
|
|
64
|
+
| GET | `/top_commentors` | `client.artists.top_commentors(...)` |
|
|
65
|
+
| POST | `/link_request` | `client.artists.add_link_request(link: ..., ...)` |
|
|
66
|
+
| DELETE | `/link_request` | `client.artists.remove_link_request(link: ..., ...)` |
|
|
67
|
+
| POST | `/track_request` | `client.artists.add_track_request(...)` |
|
|
68
|
+
| DELETE | `/track_request` | `client.artists.remove_track_request(...)` |
|
|
69
|
+
| POST | `/add_to_member_relevant_list` | `client.artists.add_to_member_relevant_list(...)` |
|
|
70
|
+
| DELETE | `/remove_from_member_relevant_list` | `client.artists.remove_from_member_relevant_list(...)` |
|
|
71
|
+
|
|
72
|
+
## `/enterprise/v1/collaborators`
|
|
73
|
+
|
|
74
|
+
| HTTP | Route | SDK Method |
|
|
75
|
+
|---|---|---|
|
|
76
|
+
| GET | `/info` | `client.collaborators.info(...)` |
|
|
77
|
+
| GET | `/stats` | `client.collaborators.stats(...)` |
|
|
78
|
+
| GET | `/historic_stats` | `client.collaborators.historic_stats(...)` |
|
|
79
|
+
| GET | `/audience` | `client.collaborators.audience(...)` |
|
|
80
|
+
| GET | `/audience/details` | `client.collaborators.audience_details(country_code: ..., ...)` |
|
|
81
|
+
| GET | `/catalog` | `client.collaborators.catalog(...)` |
|
|
82
|
+
| GET | `/search` | `client.collaborators.search(q: ..., ...)` |
|
|
83
|
+
| GET | `/activities` | `client.collaborators.activities(...)` |
|
|
84
|
+
| GET | `/songshare` | `client.collaborators.songshare(...)` |
|
|
85
|
+
| GET | `/top_tracks` | `client.collaborators.top_tracks(...)` |
|
|
86
|
+
| GET | `/top_playlists` | `client.collaborators.top_playlists(...)` |
|
|
87
|
+
| GET | `/top_curators` | `client.collaborators.top_curators(...)` |
|
|
88
|
+
| GET | `/top_commentors` | `client.collaborators.top_commentors(...)` |
|
|
89
|
+
| POST | `/link_request` | `client.collaborators.add_link_request(link: ..., ...)` |
|
|
90
|
+
| DELETE | `/link_request` | `client.collaborators.remove_link_request(link: ..., ...)` |
|
|
91
|
+
| POST | `/track_request` | `client.collaborators.add_track_request(...)` |
|
|
92
|
+
| DELETE | `/track_request` | `client.collaborators.remove_track_request(...)` |
|
|
93
|
+
| POST | `/add_to_member_relevant_list` | `client.collaborators.add_to_member_relevant_list(...)` |
|
|
94
|
+
| DELETE | `/remove_from_member_relevant_list` | `client.collaborators.remove_from_member_relevant_list(...)` |
|
|
95
|
+
|
|
96
|
+
## `/enterprise/v1/labels`
|
|
97
|
+
|
|
98
|
+
| HTTP | Route | SDK Method |
|
|
99
|
+
|---|---|---|
|
|
100
|
+
| GET | `/info` | `client.labels.info(...)` |
|
|
101
|
+
| GET | `/stats` | `client.labels.stats(...)` |
|
|
102
|
+
| GET | `/historic_stats` | `client.labels.historic_stats(...)` |
|
|
103
|
+
| GET | `/audience` | `client.labels.audience(...)` |
|
|
104
|
+
| GET | `/audience/details` | `client.labels.audience_details(country_code: ..., ...)` |
|
|
105
|
+
| GET | `/catalog` | `client.labels.catalog(...)` |
|
|
106
|
+
| GET | `/search` | `client.labels.search(q: ..., ...)` |
|
|
107
|
+
| GET | `/activities` | `client.labels.activities(...)` |
|
|
108
|
+
| GET | `/songshare` | `client.labels.songshare(...)` |
|
|
109
|
+
| GET | `/top_tracks` | `client.labels.top_tracks(...)` |
|
|
110
|
+
| GET | `/top_playlists` | `client.labels.top_playlists(...)` |
|
|
111
|
+
| GET | `/top_curators` | `client.labels.top_curators(...)` |
|
|
112
|
+
| GET | `/top_commentors` | `client.labels.top_commentors(...)` |
|
|
113
|
+
| POST | `/link_request` | `client.labels.add_link_request(link: ..., ...)` |
|
|
114
|
+
| DELETE | `/link_request` | `client.labels.remove_link_request(link: ..., ...)` |
|
|
115
|
+
| POST | `/track_request` | `client.labels.add_track_request(...)` |
|
|
116
|
+
| DELETE | `/track_request` | `client.labels.remove_track_request(...)` |
|
|
117
|
+
| POST | `/add_to_member_relevant_list` | `client.labels.add_to_member_relevant_list(...)` |
|
|
118
|
+
| DELETE | `/remove_from_member_relevant_list` | `client.labels.remove_from_member_relevant_list(...)` |
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SongstatsSDK
|
|
4
|
+
class Client
|
|
5
|
+
attr_reader :info, :tracks, :artists, :collaborators, :labels, :charts, :stations
|
|
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
|
+
@tracks = Resources::Tracks.new(@http)
|
|
20
|
+
@artists = Resources::Artists.new(@http)
|
|
21
|
+
@collaborators = Resources::Collaborators.new(@http)
|
|
22
|
+
@labels = Resources::Labels.new(@http)
|
|
23
|
+
@charts = Resources::Charts.new(@http)
|
|
24
|
+
@stations = Resources::Stations.new(@http)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def close
|
|
28
|
+
@http.close
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SongstatsSDK
|
|
4
|
+
class SongstatsError < StandardError; end
|
|
5
|
+
|
|
6
|
+
class SongstatsTransportError < SongstatsError; end
|
|
7
|
+
|
|
8
|
+
class SongstatsAPIError < SongstatsError
|
|
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
|
+
"Songstats 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 SongstatsSDK
|
|
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.sub(%r{\A/}, ""))
|
|
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://data.songstats.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 || "songstats-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.sub(%r{\A/}, "")}"
|
|
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 SongstatsTransportError, 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
|
+
SongstatsAPIError.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 SongstatsSDK
|
|
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.nil? || params.empty?
|
|
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,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SongstatsSDK
|
|
4
|
+
module Resources
|
|
5
|
+
class Charts < Base
|
|
6
|
+
def tracks(country_code:, source: nil, **params)
|
|
7
|
+
raise ArgumentError, "country_code is required" if country_code.to_s.empty?
|
|
8
|
+
|
|
9
|
+
query = { country_code: country_code, source: source }.merge(params)
|
|
10
|
+
get("charts/tracks", params: query)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SongstatsSDK
|
|
4
|
+
module Resources
|
|
5
|
+
class Entity < Base
|
|
6
|
+
def initialize(http_client, resource:, identifier_keys:)
|
|
7
|
+
super(http_client)
|
|
8
|
+
@resource = resource
|
|
9
|
+
@identifier_keys = identifier_keys
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def info(**params)
|
|
13
|
+
get("#{@resource}/info", params: with_identifier(params))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def stats(**params)
|
|
17
|
+
get("#{@resource}/stats", params: with_identifier(params))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def historic_stats(**params)
|
|
21
|
+
get("#{@resource}/historic_stats", params: with_identifier(params))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def audience(**params)
|
|
25
|
+
get("#{@resource}/audience", params: with_identifier(params))
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def audience_details(country_code:, **params)
|
|
29
|
+
raise ArgumentError, "country_code is required" if country_code.to_s.empty?
|
|
30
|
+
|
|
31
|
+
query = with_identifier(params)
|
|
32
|
+
query[:country_code] = country_code
|
|
33
|
+
get("#{@resource}/audience/details", params: query)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def catalog(**params)
|
|
37
|
+
get("#{@resource}/catalog", params: with_identifier(params))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def search(q:, **params)
|
|
41
|
+
raise ArgumentError, "q is required" if q.to_s.empty?
|
|
42
|
+
|
|
43
|
+
get("#{@resource}/search", params: params.merge(q: q))
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def activities(**params)
|
|
47
|
+
get("#{@resource}/activities", params: with_identifier(params))
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def songshare(**params)
|
|
51
|
+
get("#{@resource}/songshare", params: with_identifier(params))
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def top_tracks(**params)
|
|
55
|
+
get("#{@resource}/top_tracks", params: with_identifier(params))
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def top_playlists(**params)
|
|
59
|
+
get("#{@resource}/top_playlists", params: with_identifier(params))
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def top_curators(**params)
|
|
63
|
+
get("#{@resource}/top_curators", params: with_identifier(params))
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def top_commentors(**params)
|
|
67
|
+
get("#{@resource}/top_commentors", params: with_identifier(params))
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def add_link_request(link:, **params)
|
|
71
|
+
raise ArgumentError, "link is required" if link.to_s.empty?
|
|
72
|
+
|
|
73
|
+
query = with_identifier(params)
|
|
74
|
+
query[:link] = link
|
|
75
|
+
post("#{@resource}/link_request", params: query)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def remove_link_request(link:, **params)
|
|
79
|
+
raise ArgumentError, "link is required" if link.to_s.empty?
|
|
80
|
+
|
|
81
|
+
query = with_identifier(params)
|
|
82
|
+
query[:link] = link
|
|
83
|
+
delete("#{@resource}/link_request", params: query)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def add_track_request(link: nil, spotify_track_id: nil, isrc: nil, **params)
|
|
87
|
+
if [link, spotify_track_id, isrc].all? { |value| value.to_s.empty? }
|
|
88
|
+
raise ArgumentError, "One of link, spotify_track_id, or isrc is required"
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
query = with_identifier(params)
|
|
92
|
+
query[:link] = link
|
|
93
|
+
query[:spotify_track_id] = spotify_track_id
|
|
94
|
+
query[:isrc] = isrc
|
|
95
|
+
post("#{@resource}/track_request", params: query)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def remove_track_request(songstats_track_id: nil, spotify_track_id: nil, **params)
|
|
99
|
+
if [songstats_track_id, spotify_track_id].all? { |value| value.to_s.empty? }
|
|
100
|
+
raise ArgumentError, "songstats_track_id or spotify_track_id is required"
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
query = with_identifier(params)
|
|
104
|
+
query[:songstats_track_id] = songstats_track_id
|
|
105
|
+
query[:spotify_track_id] = spotify_track_id
|
|
106
|
+
delete("#{@resource}/track_request", params: query)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def add_to_member_relevant_list(**params)
|
|
110
|
+
post("#{@resource}/add_to_member_relevant_list", params: with_identifier(params))
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def remove_from_member_relevant_list(**params)
|
|
114
|
+
delete("#{@resource}/remove_from_member_relevant_list", params: with_identifier(params))
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
private
|
|
118
|
+
|
|
119
|
+
def with_identifier(params)
|
|
120
|
+
query = params.dup
|
|
121
|
+
require_any_identifier!(query, @identifier_keys)
|
|
122
|
+
query
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
class Artists < Entity
|
|
127
|
+
def initialize(http_client)
|
|
128
|
+
super(
|
|
129
|
+
http_client,
|
|
130
|
+
resource: "artists",
|
|
131
|
+
identifier_keys: %i[songstats_artist_id spotify_artist_id apple_music_artist_id]
|
|
132
|
+
)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
class Collaborators < Entity
|
|
137
|
+
def initialize(http_client)
|
|
138
|
+
super(
|
|
139
|
+
http_client,
|
|
140
|
+
resource: "collaborators",
|
|
141
|
+
identifier_keys: %i[songstats_collaborator_id spotify_artist_id apple_music_artist_id tidal_artist_id]
|
|
142
|
+
)
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
class Labels < Entity
|
|
147
|
+
def initialize(http_client)
|
|
148
|
+
super(
|
|
149
|
+
http_client,
|
|
150
|
+
resource: "labels",
|
|
151
|
+
identifier_keys: %i[songstats_label_id beatport_label_id]
|
|
152
|
+
)
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SongstatsSDK
|
|
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 SongstatsSDK
|
|
4
|
+
module Resources
|
|
5
|
+
class Stations < Base
|
|
6
|
+
def station_request(radio_type:, name:, country_code:, website:, stream_url: nil, city_name: nil, frequency: nil,
|
|
7
|
+
contact: nil, comment: nil, **extra)
|
|
8
|
+
raise ArgumentError, "radio_type is required" if radio_type.to_s.empty?
|
|
9
|
+
raise ArgumentError, "name is required" if name.to_s.empty?
|
|
10
|
+
raise ArgumentError, "country_code is required" if country_code.to_s.empty?
|
|
11
|
+
raise ArgumentError, "website is required" if website.to_s.empty?
|
|
12
|
+
|
|
13
|
+
payload = {
|
|
14
|
+
radio_type: radio_type,
|
|
15
|
+
name: name,
|
|
16
|
+
country_code: country_code,
|
|
17
|
+
website: website,
|
|
18
|
+
stream_url: stream_url,
|
|
19
|
+
city_name: city_name,
|
|
20
|
+
frequency: frequency,
|
|
21
|
+
contact: contact,
|
|
22
|
+
comment: comment
|
|
23
|
+
}.merge(extra)
|
|
24
|
+
|
|
25
|
+
post("stations/station_request", json: payload)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SongstatsSDK
|
|
4
|
+
module Resources
|
|
5
|
+
class Tracks < Base
|
|
6
|
+
IDENTIFIER_KEYS = %i[songstats_track_id spotify_track_id apple_music_track_id isrc].freeze
|
|
7
|
+
|
|
8
|
+
def info(**params)
|
|
9
|
+
get("tracks/info", params: with_identifier(params))
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def stats(**params)
|
|
13
|
+
get("tracks/stats", params: with_identifier(params))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def historic_stats(**params)
|
|
17
|
+
get("tracks/historic_stats", params: with_identifier(params))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def activities(**params)
|
|
21
|
+
get("tracks/activities", params: with_identifier(params))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def comments(**params)
|
|
25
|
+
get("tracks/comments", params: with_identifier(params))
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def songshare(**params)
|
|
29
|
+
get("tracks/songshare", params: with_identifier(params))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def locations(**params)
|
|
33
|
+
get("tracks/locations", params: with_identifier(params))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def search(q:, **params)
|
|
37
|
+
raise ArgumentError, "q is required" if q.to_s.empty?
|
|
38
|
+
|
|
39
|
+
get("tracks/search", params: params.merge(q: q))
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def add_link_request(link:, **params)
|
|
43
|
+
raise ArgumentError, "link is required" if link.to_s.empty?
|
|
44
|
+
|
|
45
|
+
query = with_identifier(params)
|
|
46
|
+
query[:link] = link
|
|
47
|
+
post("tracks/link_request", params: query)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def remove_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
|
+
delete("tracks/link_request", params: query)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def add_to_member_relevant_list(**params)
|
|
59
|
+
post("tracks/add_to_member_relevant_list", params: with_identifier(params))
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def remove_from_member_relevant_list(**params)
|
|
63
|
+
delete("tracks/remove_from_member_relevant_list", params: with_identifier(params))
|
|
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
|
metadata
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: songstats-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-02-19 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Typed Ruby client covering all /enterprise/v1 Songstats API routes.
|
|
14
|
+
email:
|
|
15
|
+
- api@songstats.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- CHANGELOG.md
|
|
21
|
+
- LICENSE
|
|
22
|
+
- README.md
|
|
23
|
+
- docs/enterprise_routes_audit.md
|
|
24
|
+
- lib/songstats_sdk.rb
|
|
25
|
+
- lib/songstats_sdk/client.rb
|
|
26
|
+
- lib/songstats_sdk/errors.rb
|
|
27
|
+
- lib/songstats_sdk/http_client.rb
|
|
28
|
+
- lib/songstats_sdk/resources.rb
|
|
29
|
+
- lib/songstats_sdk/resources/base.rb
|
|
30
|
+
- lib/songstats_sdk/resources/charts.rb
|
|
31
|
+
- lib/songstats_sdk/resources/entities.rb
|
|
32
|
+
- lib/songstats_sdk/resources/info.rb
|
|
33
|
+
- lib/songstats_sdk/resources/stations.rb
|
|
34
|
+
- lib/songstats_sdk/resources/tracks.rb
|
|
35
|
+
- lib/songstats_sdk/version.rb
|
|
36
|
+
homepage: https://songstats.com
|
|
37
|
+
licenses:
|
|
38
|
+
- MIT
|
|
39
|
+
metadata:
|
|
40
|
+
homepage_uri: https://songstats.com
|
|
41
|
+
source_code_uri: https://github.com/songstats/songstats-ruby-sdk
|
|
42
|
+
bug_tracker_uri: https://github.com/songstats/songstats-ruby-sdk/issues
|
|
43
|
+
allowed_push_host: https://rubygems.org
|
|
44
|
+
post_install_message:
|
|
45
|
+
rdoc_options: []
|
|
46
|
+
require_paths:
|
|
47
|
+
- lib
|
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - ">="
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: 3.0.0
|
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
|
+
requirements:
|
|
55
|
+
- - ">="
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: '0'
|
|
58
|
+
requirements: []
|
|
59
|
+
rubygems_version: 3.5.17
|
|
60
|
+
signing_key:
|
|
61
|
+
specification_version: 4
|
|
62
|
+
summary: Ruby SDK for the Songstats Enterprise API.
|
|
63
|
+
test_files: []
|