songstats-api 1.2.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env.example +1 -0
- data/.env.test +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -0
- data/lib/songstats/api/artist.rb +18 -0
- data/lib/songstats/api/base.rb +9 -4
- data/lib/songstats/api/chart.rb +43 -0
- data/lib/songstats/api/label.rb +18 -0
- data/lib/songstats/api/version.rb +1 -1
- data/lib/songstats/api.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4435e46748e62f3669e038f19ea0f03205f601de6bec3563b0a5ec909843151b
|
4
|
+
data.tar.gz: 258b58b810715353304066ac1ab2b6d34946eed0d2571d81ebd27d77d2ff540a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 457df44f7cdc558acc43684787b70034c1f90576e8e0c1471a69b1f1b1f6b6b7e43cb5527d17c67a42a5db9ba09817bdb7937bad544343b3c0bf3bf421c3535d
|
7
|
+
data.tar.gz: 676eabfa8b92ba961877b68a1a9bbca39c10314cd721681215b7b84eab4f3a7abe25d2e756ca2c89c02a5b44f1caa85cfc38cb2faf0cd54d1dcc30cd1e780783
|
data/.env.example
CHANGED
data/.env.test
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -26,6 +26,8 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
To use this gem ensure that `SONGSTATS_API_KEY` is set as an env variarble.
|
28
28
|
|
29
|
+
To use `Songstats:Api::Charts` ensure `SONGSTATS_CHARTS_API_KEY` is set as an env variable. This is billed differently than other endpoints so it needs its own api key.
|
30
|
+
|
29
31
|
This is a wrapper around Song Stats API - [you can find their docs here](https://docs.songstats.com/docs/api/e80265bb8b01b-songstats-api).
|
30
32
|
|
31
33
|
|
data/lib/songstats/api/artist.rb
CHANGED
@@ -73,6 +73,24 @@ module Songstats
|
|
73
73
|
# https://docs.songstats.com/docs/api/dc58c858fdbb6-delete-artist-link
|
74
74
|
delete path(id, "/artists/link_request", link: link)
|
75
75
|
end
|
76
|
+
|
77
|
+
def add_track(id, track_id)
|
78
|
+
# https://docs.songstats.com/docs/api/aux8fvg3g9sv7-add-artist-track
|
79
|
+
options = {}
|
80
|
+
options[:isrc] = track_id if track_id.size == ISRC_LENGTH
|
81
|
+
options[:spotify_track_id] = track_id if track_id.size > ISRC_LENGTH && !url?(track_id)
|
82
|
+
options[:link] = track_id if url? track_id
|
83
|
+
post path(id, "/artists/track_request", options)
|
84
|
+
end
|
85
|
+
|
86
|
+
def delete_track(id, track_id)
|
87
|
+
# https://docs.songstats.com/docs/api/sijd2vkvgwpdj-remove-artist-track
|
88
|
+
options = {}
|
89
|
+
options[:isrc] = track_id if track_id.size == ISRC_LENGTH
|
90
|
+
options[:songstats_track_id] = track_id if track_id.size == SONG_STATS_ID_LENGTH
|
91
|
+
options[:spotify_track_id] = track_id if track_id.size > ISRC_LENGTH
|
92
|
+
delete path(id, "/artists/track_request", options)
|
93
|
+
end
|
76
94
|
end
|
77
95
|
end
|
78
96
|
end
|
data/lib/songstats/api/base.rb
CHANGED
@@ -16,11 +16,16 @@ module Songstats
|
|
16
16
|
def initialize
|
17
17
|
@api_key = ENV.fetch "SONGSTATS_API_KEY", nil
|
18
18
|
|
19
|
-
raise "Missing SongStats API key" if @api_key.nil?
|
19
|
+
raise Songstats::Api::Error, "Missing SongStats API key" if @api_key.nil?
|
20
20
|
end
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
|
+
def url?(str)
|
25
|
+
url_regex = /\A#{URI::DEFAULT_PARSER.make_regexp(%w[http https])}\z/
|
26
|
+
str =~ url_regex ? true : false
|
27
|
+
end
|
28
|
+
|
24
29
|
def query_string(id)
|
25
30
|
return "isrc=#{id}" if id.size == ISRC_LENGTH
|
26
31
|
|
@@ -49,21 +54,21 @@ module Songstats
|
|
49
54
|
response = self.class.get path, headers: { "apiKey" => @api_key }
|
50
55
|
return response.parsed_response if response.success?
|
51
56
|
|
52
|
-
raise response.parsed_response
|
57
|
+
raise Songstats::Api::Error, response.parsed_response
|
53
58
|
end
|
54
59
|
|
55
60
|
def post(path, body)
|
56
61
|
response = self.class.post path, body: body, headers: { "apiKey" => @api_key }
|
57
62
|
return response.parsed_response if response.success?
|
58
63
|
|
59
|
-
raise response.parsed_response
|
64
|
+
raise Songstats::Api::Error, response.parsed_response
|
60
65
|
end
|
61
66
|
|
62
67
|
def delete(path)
|
63
68
|
response = self.class.delete path, headers: { "apiKey" => @api_key }
|
64
69
|
return response.parsed_response if response.success?
|
65
70
|
|
66
|
-
raise response.parsed_response
|
71
|
+
raise Songstats::Api::Error, response.parsed_response
|
67
72
|
end
|
68
73
|
end
|
69
74
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "httparty"
|
4
|
+
|
5
|
+
module Songstats
|
6
|
+
module Api
|
7
|
+
# Chart class for the Songstats API
|
8
|
+
class Chart < Base
|
9
|
+
include HTTParty
|
10
|
+
|
11
|
+
base_uri "https://api.songstats.com/enterprise/v1"
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@api_key = ENV.fetch "SONGSTATS_CHARTS_API_KEY", nil
|
15
|
+
|
16
|
+
raise Songstats::Api::Error, "Missing SongStats Charts API key" if @api_key.nil?
|
17
|
+
end
|
18
|
+
|
19
|
+
def tracks(options = {})
|
20
|
+
options[:source] = "all" unless options.key? :source
|
21
|
+
options[:country_code] = "US" unless options.key? :country_code
|
22
|
+
|
23
|
+
fetch path("/charts/tracks", options)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def path(path, options = {})
|
29
|
+
query_params = options.map { |key, value| "#{key}=#{value}" }.join("&")
|
30
|
+
return "#{path}?#{query_params}" unless query_params.empty?
|
31
|
+
|
32
|
+
path
|
33
|
+
end
|
34
|
+
|
35
|
+
def fetch(path)
|
36
|
+
response = self.class.get path, headers: { "apiKey" => @api_key }
|
37
|
+
return response.parsed_response if response.success?
|
38
|
+
|
39
|
+
raise Songstats::Api::Error, response.parsed_response
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/songstats/api/label.rb
CHANGED
@@ -78,6 +78,24 @@ module Songstats
|
|
78
78
|
# https://docs.songstats.com/docs/api/f684183faa3b9-delete-label-link
|
79
79
|
delete path(id, "/labels/link_request", link: link)
|
80
80
|
end
|
81
|
+
|
82
|
+
def add_track(id, track_id)
|
83
|
+
# https://docs.songstats.com/docs/api/sf9lrzr189m48-add-label-track
|
84
|
+
options = {}
|
85
|
+
options[:isrc] = track_id if track_id.size == ISRC_LENGTH
|
86
|
+
options[:spotify_track_id] = track_id if track_id.size > ISRC_LENGTH && !url?(track_id)
|
87
|
+
options[:link] = track_id if url? track_id
|
88
|
+
post path(id, "/labels/track_request", options)
|
89
|
+
end
|
90
|
+
|
91
|
+
def delete_track(id, track_id)
|
92
|
+
# https://docs.songstats.com/docs/api/l0xhrjijnktgf-remove-label-link
|
93
|
+
options = {}
|
94
|
+
options[:isrc] = track_id if track_id.size == ISRC_LENGTH
|
95
|
+
options[:songstats_track_id] = track_id if track_id.size == SONG_STATS_ID_LENGTH
|
96
|
+
options[:spotify_track_id] = track_id if track_id.size > ISRC_LENGTH
|
97
|
+
delete path(id, "/labels/track_request", options)
|
98
|
+
end
|
81
99
|
end
|
82
100
|
end
|
83
101
|
end
|
data/lib/songstats/api.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: songstats-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daryl Findlay
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- lib/songstats/api.rb
|
50
50
|
- lib/songstats/api/artist.rb
|
51
51
|
- lib/songstats/api/base.rb
|
52
|
+
- lib/songstats/api/chart.rb
|
52
53
|
- lib/songstats/api/label.rb
|
53
54
|
- lib/songstats/api/track.rb
|
54
55
|
- lib/songstats/api/version.rb
|