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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66741cd74c3ee019128ba6db6949579b1f53b952f3ddb4e10a50983611b9f42a
4
- data.tar.gz: 908d890645fa89d1ef8cb44d79992ace241ffb8e6bb08b44ac982ef755d6c738
3
+ metadata.gz: 9a6d73f1bc7dae4d2a9f13b8b9a6e79ffc1d7eae7f439bc6cc11b11d83f74a20
4
+ data.tar.gz: a1e58fb1fece05588a000aa3127a76107a361ef889d375b8fe99998683984c46
5
5
  SHA512:
6
- metadata.gz: a35f5bb1e66c5d4f5a34f639023cb91d5d04f6d78218c1a698fbab51dea0f59fd4b94d02321b7560c7c9d5575d53a6e55d8c77e75fb24ab6f837541d5405de7c
7
- data.tar.gz: e8d2da614c14d5fe10a5339ced1521ea1319bef67f26f708455c2e37bf50f96c3cb44a49bc5424bf28bbdbaa10f35971cd41850e993ac39b24040edb2787eca8
6
+ metadata.gz: 8ce059265973ec4d7f7d2e9f0848a3f2495a6e9285012d8328df0daee47741ef5d1a9e49ab73c592cb4cc8056ae19900d4fd658f3f9eede8afe4b471eb58d42c
7
+ data.tar.gz: 687bf1a1f80075abd4b1f23425160d6ec42530a56c3504c8af09bebc5ba04c918969b52180e2dfb215f77532a4640ef5120e161afed27fcbd3a1a09d20f1c637
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.2.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.
@@ -22,7 +24,24 @@ Or install it yourself as:
22
24
 
23
25
  ## Usage
24
26
 
25
- TODO: Write usage instructions here
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
 
@@ -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(id, query, options = {})
61
+ def search(query, options = {})
66
62
  # https://docs.songstats.com/docs/api/d761545339f09-search-artist
67
63
  options[:q] = query
68
- fetch path(id, "/artists/search", options)
64
+ fetch path("", "/artists/search", options)
69
65
  end
70
66
 
71
67
  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)
@@ -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 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
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(id, query, options = {})
66
+ def search(query, options = {})
67
67
  # https://docs.songstats.com/docs/api/c934a2909ba0f-search-label
68
68
  options[:q] = query
69
- fetch path(id, "/labels/search", options)
69
+ fetch path("", "/labels/search", options)
70
70
  end
71
71
 
72
72
  def add_link(id, link)
@@ -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(id, query, options = {})
35
+ def search(query, options = {})
38
36
  # https://docs.songstats.com/docs/api/1f2e4f9b3b1d1-search-track
39
37
  options[:q] = query
40
- fetch path(id, "/tracks/search", options)
38
+ fetch path("", "/tracks/search", options)
41
39
  end
42
40
 
43
41
  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.2.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.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daryl Findlay