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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a6d73f1bc7dae4d2a9f13b8b9a6e79ffc1d7eae7f439bc6cc11b11d83f74a20
4
- data.tar.gz: a1e58fb1fece05588a000aa3127a76107a361ef889d375b8fe99998683984c46
3
+ metadata.gz: 4435e46748e62f3669e038f19ea0f03205f601de6bec3563b0a5ec909843151b
4
+ data.tar.gz: 258b58b810715353304066ac1ab2b6d34946eed0d2571d81ebd27d77d2ff540a
5
5
  SHA512:
6
- metadata.gz: 8ce059265973ec4d7f7d2e9f0848a3f2495a6e9285012d8328df0daee47741ef5d1a9e49ab73c592cb4cc8056ae19900d4fd658f3f9eede8afe4b471eb58d42c
7
- data.tar.gz: 687bf1a1f80075abd4b1f23425160d6ec42530a56c3504c8af09bebc5ba04c918969b52180e2dfb215f77532a4640ef5120e161afed27fcbd3a1a09d20f1c637
6
+ metadata.gz: 457df44f7cdc558acc43684787b70034c1f90576e8e0c1471a69b1f1b1f6b6b7e43cb5527d17c67a42a5db9ba09817bdb7937bad544343b3c0bf3bf421c3535d
7
+ data.tar.gz: 676eabfa8b92ba961877b68a1a9bbca39c10314cd721681215b7b84eab4f3a7abe25d2e756ca2c89c02a5b44f1caa85cfc38cb2faf0cd54d1dcc30cd1e780783
data/.env.example CHANGED
@@ -1 +1,2 @@
1
1
  SONGSTATS_API_KEY=
2
+ SONGSTATS_CHARTS_API_KEY=
data/.env.test CHANGED
@@ -1 +1,2 @@
1
1
  SONGSTATS_API_KEY=test-1234-5678-9012-3456
2
+ SONGSTATS_CHARTS_API_KEY=test-1234-5678-9012-3456
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- songstats-api (1.2.0)
4
+ songstats-api (1.4.0)
5
5
  httparty
6
6
 
7
7
  GEM
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
 
@@ -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
@@ -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
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Songstats
4
4
  module Api
5
- VERSION = "1.2.0"
5
+ VERSION = "1.4.0"
6
6
  end
7
7
  end
data/lib/songstats/api.rb CHANGED
@@ -11,5 +11,6 @@ module Songstats
11
11
  autoload :Artist, "songstats/api/artist"
12
12
  autoload :Track, "songstats/api/track"
13
13
  autoload :Label, "songstats/api/label"
14
+ autoload :Chart, "songstats/api/chart"
14
15
  end
15
16
  end
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.2.0
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-04-12 00:00:00.000000000 Z
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