songstats-api 1.3.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: abef0db83768f11fbe5b7b4065be17b37314ba7ae09838218fb679e1ed6ce609
4
- data.tar.gz: e727fe9aa96d85f7cbeca6340453f931c214c3654b0ced5be3ce378f29e4017b
3
+ metadata.gz: 4435e46748e62f3669e038f19ea0f03205f601de6bec3563b0a5ec909843151b
4
+ data.tar.gz: 258b58b810715353304066ac1ab2b6d34946eed0d2571d81ebd27d77d2ff540a
5
5
  SHA512:
6
- metadata.gz: '0058d84c8f6b1af15782760e7d97ecf9e2afbc58735c07c4950902d51abbb470056068016b7a9ec6edf2338635af3eebe150599ae7ece7c7b245d01db365df16'
7
- data.tar.gz: 0a8e2720669bd876f5b5572146aef63d9a9e041fbc04e77b4875b09b095aa38502992da63611bec54eaf00e1762cab1cfa3a0786988771d9d7bde329c6da9af2
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.3.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
 
@@ -16,7 +16,7 @@ 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
@@ -54,21 +54,21 @@ module Songstats
54
54
  response = self.class.get path, headers: { "apiKey" => @api_key }
55
55
  return response.parsed_response if response.success?
56
56
 
57
- raise response.parsed_response
57
+ raise Songstats::Api::Error, response.parsed_response
58
58
  end
59
59
 
60
60
  def post(path, body)
61
61
  response = self.class.post path, body: body, headers: { "apiKey" => @api_key }
62
62
  return response.parsed_response if response.success?
63
63
 
64
- raise response.parsed_response
64
+ raise Songstats::Api::Error, response.parsed_response
65
65
  end
66
66
 
67
67
  def delete(path)
68
68
  response = self.class.delete path, headers: { "apiKey" => @api_key }
69
69
  return response.parsed_response if response.success?
70
70
 
71
- raise response.parsed_response
71
+ raise Songstats::Api::Error, response.parsed_response
72
72
  end
73
73
  end
74
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Songstats
4
4
  module Api
5
- VERSION = "1.3.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.3.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-05-23 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