songstats-api 1.0.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +20 -1
- data/lib/songstats/api/artist.rb +2 -6
- data/lib/songstats/api/base.rb +21 -10
- data/lib/songstats/api/label.rb +8 -8
- data/lib/songstats/api/track.rb +2 -4
- data/lib/songstats/api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a6d73f1bc7dae4d2a9f13b8b9a6e79ffc1d7eae7f439bc6cc11b11d83f74a20
|
4
|
+
data.tar.gz: a1e58fb1fece05588a000aa3127a76107a361ef889d375b8fe99998683984c46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ce059265973ec4d7f7d2e9f0848a3f2495a6e9285012d8328df0daee47741ef5d1a9e49ab73c592cb4cc8056ae19900d4fd658f3f9eede8afe4b471eb58d42c
|
7
|
+
data.tar.gz: 687bf1a1f80075abd4b1f23425160d6ec42530a56c3504c8af09bebc5ba04c918969b52180e2dfb215f77532a4640ef5120e161afed27fcbd3a1a09d20f1c637
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Songstats::Api
|
2
2
|
|
3
|
+
[![Ruby](https://github.com/songtradr/songstats-api/actions/workflows/main.yml/badge.svg)](https://github.com/songtradr/songstats-api/actions/workflows/main.yml)
|
4
|
+
|
3
5
|
The Songstats API Gem is a lightweight tool for developers to interact with the Songstats REST API. With this gem, you can integrate Songstats' music data into your Ruby applications, making it easy to access information about tracks, artists, and more.
|
4
6
|
|
5
7
|
To experiment with that code, run `bin/console` for an interactive prompt.
|
@@ -22,7 +24,24 @@ Or install it yourself as:
|
|
22
24
|
|
23
25
|
## Usage
|
24
26
|
|
25
|
-
|
27
|
+
To use this gem ensure that `SONGSTATS_API_KEY` is set as an env variarble.
|
28
|
+
|
29
|
+
This is a wrapper around Song Stats API - [you can find their docs here](https://docs.songstats.com/docs/api/e80265bb8b01b-songstats-api).
|
30
|
+
|
31
|
+
|
32
|
+
### Artist
|
33
|
+
```ruby
|
34
|
+
artist = Songstats::Api::Artist.new
|
35
|
+
artist.search "elton john", {"limit": "1"}
|
36
|
+
artist.info "22wbnEMDvgVIAGdFeek6ET"
|
37
|
+
```
|
38
|
+
|
39
|
+
### Track
|
40
|
+
```ruby
|
41
|
+
track = Songstats::Api::Track.new
|
42
|
+
track.search "rocket man", {"limit": "1"}
|
43
|
+
track.info "12341234"
|
44
|
+
```
|
26
45
|
|
27
46
|
## Development
|
28
47
|
|
data/lib/songstats/api/artist.rb
CHANGED
@@ -1,13 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "singleton"
|
4
|
-
|
5
3
|
module Songstats
|
6
4
|
module Api
|
7
5
|
# Artist class for the Songstats API
|
8
6
|
class Artist < Base
|
9
|
-
include Singleton
|
10
|
-
|
11
7
|
def initialize
|
12
8
|
super
|
13
9
|
@type = "artist"
|
@@ -62,10 +58,10 @@ module Songstats
|
|
62
58
|
fetch path(id, "/artists/top_playlists", options)
|
63
59
|
end
|
64
60
|
|
65
|
-
def search(
|
61
|
+
def search(query, options = {})
|
66
62
|
# https://docs.songstats.com/docs/api/d761545339f09-search-artist
|
67
63
|
options[:q] = query
|
68
|
-
fetch path(
|
64
|
+
fetch path("", "/artists/search", options)
|
69
65
|
end
|
70
66
|
|
71
67
|
def add_link(id, link)
|
data/lib/songstats/api/base.rb
CHANGED
@@ -21,17 +21,28 @@ module Songstats
|
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
|
+
def query_string(id)
|
25
|
+
return "isrc=#{id}" if id.size == ISRC_LENGTH
|
26
|
+
|
27
|
+
return "songstats_#{@type}_id=#{id}" if id.size == SONG_STATS_ID_LENGTH
|
28
|
+
|
29
|
+
return "" if id.size.zero?
|
30
|
+
|
31
|
+
"spotify_#{@type}_id=#{id}"
|
32
|
+
end
|
33
|
+
|
24
34
|
def path(id, path, options = {})
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
+
query_params = options.map { |key, value| "#{key}=#{value}" }.join("&")
|
36
|
+
|
37
|
+
query_string = query_string(id)
|
38
|
+
|
39
|
+
if query_string.empty?
|
40
|
+
"#{path}?#{query_params}"
|
41
|
+
else
|
42
|
+
return "#{path}?#{query_string}" if query_params.empty?
|
43
|
+
|
44
|
+
"#{path}?#{query_string}&#{query_params}"
|
45
|
+
end
|
35
46
|
end
|
36
47
|
|
37
48
|
def fetch(path)
|
data/lib/songstats/api/label.rb
CHANGED
@@ -4,13 +4,13 @@ module Songstats
|
|
4
4
|
module Api
|
5
5
|
# Label class for the Songstats API
|
6
6
|
class Label < Base
|
7
|
-
include Singleton
|
8
|
-
|
9
7
|
# override because the label id is either songstats_label_id or beatport_label_id
|
10
|
-
def
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
def query_string(id)
|
9
|
+
return "songstats_label_id=#{id}" if id.size == SONG_STATS_ID_LENGTH
|
10
|
+
|
11
|
+
return "" if id.size.zero?
|
12
|
+
|
13
|
+
"beatport_label_id=#{id}"
|
14
14
|
end
|
15
15
|
|
16
16
|
def info(id)
|
@@ -63,10 +63,10 @@ module Songstats
|
|
63
63
|
fetch path(id, "/labels/top_playlists", options)
|
64
64
|
end
|
65
65
|
|
66
|
-
def search(
|
66
|
+
def search(query, options = {})
|
67
67
|
# https://docs.songstats.com/docs/api/c934a2909ba0f-search-label
|
68
68
|
options[:q] = query
|
69
|
-
fetch path(
|
69
|
+
fetch path("", "/labels/search", options)
|
70
70
|
end
|
71
71
|
|
72
72
|
def add_link(id, link)
|
data/lib/songstats/api/track.rb
CHANGED
@@ -4,8 +4,6 @@ module Songstats
|
|
4
4
|
module Api
|
5
5
|
# Track class for the Songstats API
|
6
6
|
class Track < Base
|
7
|
-
include Singleton
|
8
|
-
|
9
7
|
def initialize
|
10
8
|
super
|
11
9
|
@type = "track"
|
@@ -34,10 +32,10 @@ module Songstats
|
|
34
32
|
fetch path(id, "/tracks/historic_stats", options)
|
35
33
|
end
|
36
34
|
|
37
|
-
def search(
|
35
|
+
def search(query, options = {})
|
38
36
|
# https://docs.songstats.com/docs/api/1f2e4f9b3b1d1-search-track
|
39
37
|
options[:q] = query
|
40
|
-
fetch path(
|
38
|
+
fetch path("", "/tracks/search", options)
|
41
39
|
end
|
42
40
|
|
43
41
|
def add_link(id, link)
|