songstats-api 0.1.6 → 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: 631e5890119c395e9658f0aab8686783f65dc32206a3d86979bf10416a6a40a4
4
- data.tar.gz: 0ee09d130e9d16fa11e4cb8f603552dae02c89b15b7a9b15e8759cf36e2c5d92
3
+ metadata.gz: 9d8df26fc2d79b94ae28d7c834c6d6d05faf8b48e7eeca5b66fb0c0c3916cab6
4
+ data.tar.gz: 0db44faaaea2e1738aaf0bb31a0c498ec840e2d9dca342aecc540807803f28ff
5
5
  SHA512:
6
- metadata.gz: a6c86527fc9403fc0b9c2a4d8dcc14a769cd0bf677f0cddf149e1d5b113549c2389eb2c02ed4072981f368789474eb0767ff7f0e4573d6b482330e310583465f
7
- data.tar.gz: 4f7b2736789d797de57f0e15e97defba5bc3f2e76868785812f4fbe60202e3f6bc95c58272d5e6f598bd8316cae227b8e20603b86a22efab670b7d49b971d991
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 (0.1.6)
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 = "0.1.6"
5
+ VERSION = "1.1.0"
6
6
  end
7
7
  end
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.description = "A simple API wrapper for the Songstats API"
13
13
  spec.homepage = "https://github.com/songtradr/songstats-api"
14
14
  spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
15
- spec.licenses = ['MIT']
15
+ spec.licenses = ["MIT"]
16
16
 
17
17
  # spec.metadata["allowed_push_host"] = "https://rubygems.pkg.github.com/songtradr"
18
18
 
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: 0.1.6
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daryl Findlay