songstats-api 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66741cd74c3ee019128ba6db6949579b1f53b952f3ddb4e10a50983611b9f42a
4
- data.tar.gz: 908d890645fa89d1ef8cb44d79992ace241ffb8e6bb08b44ac982ef755d6c738
3
+ metadata.gz: 9d8df26fc2d79b94ae28d7c834c6d6d05faf8b48e7eeca5b66fb0c0c3916cab6
4
+ data.tar.gz: 0db44faaaea2e1738aaf0bb31a0c498ec840e2d9dca342aecc540807803f28ff
5
5
  SHA512:
6
- metadata.gz: a35f5bb1e66c5d4f5a34f639023cb91d5d04f6d78218c1a698fbab51dea0f59fd4b94d02321b7560c7c9d5575d53a6e55d8c77e75fb24ab6f837541d5405de7c
7
- data.tar.gz: e8d2da614c14d5fe10a5339ced1521ea1319bef67f26f708455c2e37bf50f96c3cb44a49bc5424bf28bbdbaa10f35971cd41850e993ac39b24040edb2787eca8
6
+ metadata.gz: 23ffaa30f77ef53d95556ce21a7f702f1c225c7d91b9a1dd217d2956b6a9efcf387bde7550ec3ba263605820c04c8081be63421686f36edd6176c367465cc9eb
7
+ data.tar.gz: 6613a579154f5b7e718909a0f417884619cd159dd6073644960056bcf0c522f89e31c45fed0c51a5c4c53f9b9604af344041868c7ee5b583b60a260c1c7fd83d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- songstats-api (1.0.0)
4
+ songstats-api (1.1.0)
5
5
  httparty
6
6
 
7
7
  GEM
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.
@@ -62,10 +62,10 @@ module Songstats
62
62
  fetch path(id, "/artists/top_playlists", options)
63
63
  end
64
64
 
65
- def search(id, query, options = {})
65
+ def search(query, options = {})
66
66
  # https://docs.songstats.com/docs/api/d761545339f09-search-artist
67
67
  options[:q] = query
68
- fetch path(id, "/artists/search", options)
68
+ fetch path("", "/artists/search", options)
69
69
  end
70
70
 
71
71
  def add_link(id, link)
@@ -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
- path += case id.size
26
- when ISRC_LENGTH
27
- "?isrc=#{id}"
28
- when SONG_STATS_ID_LENGTH
29
- "?songstats_#{@type}_id=#{id}"
30
- else
31
- "?spotify_#{@type}_id=#{id}"
32
- end
33
- options.each { |key, value| path += "&#{key}=#{value}" }
34
- path
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)
@@ -7,10 +7,12 @@ module Songstats
7
7
  include Singleton
8
8
 
9
9
  # override because the label id is either songstats_label_id or beatport_label_id
10
- def path(id, path, options = {})
11
- path += id.size == SONG_STATS_ID_LENGTH ? "?songstats_label_id=#{id}" : "?beatport_label_id=#{id}"
12
- options.each { |key, value| path += "&#{key}=#{value}" }
13
- path
10
+ def query_string(id)
11
+ return "songstats_label_id=#{id}" if id.size == SONG_STATS_ID_LENGTH
12
+
13
+ return "" if id.size.zero?
14
+
15
+ "beatport_label_id=#{id}"
14
16
  end
15
17
 
16
18
  def info(id)
@@ -63,10 +65,10 @@ module Songstats
63
65
  fetch path(id, "/labels/top_playlists", options)
64
66
  end
65
67
 
66
- def search(id, query, options = {})
68
+ def search(query, options = {})
67
69
  # https://docs.songstats.com/docs/api/c934a2909ba0f-search-label
68
70
  options[:q] = query
69
- fetch path(id, "/labels/search", options)
71
+ fetch path("", "/labels/search", options)
70
72
  end
71
73
 
72
74
  def add_link(id, link)
@@ -34,10 +34,10 @@ module Songstats
34
34
  fetch path(id, "/tracks/historic_stats", options)
35
35
  end
36
36
 
37
- def search(id, query, options = {})
37
+ def search(query, options = {})
38
38
  # https://docs.songstats.com/docs/api/1f2e4f9b3b1d1-search-track
39
39
  options[:q] = query
40
- fetch path(id, "/tracks/search", options)
40
+ fetch path("", "/tracks/search", options)
41
41
  end
42
42
 
43
43
  def add_link(id, link)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Songstats
4
4
  module Api
5
- VERSION = "1.0.0"
5
+ VERSION = "1.1.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: songstats-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daryl Findlay