songstats-api 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 18a1fa39cd9519d995d56a68bef88761686877d10e12965197af73f778303d23
4
+ data.tar.gz: c11fe9d0f6b1e9b4839a889f24351fbd538824fb9f311328b7377bb4ea45b1e7
5
+ SHA512:
6
+ metadata.gz: da9f560f692d94336deaebacab3cceea1deebfa03cc0a497f94a72340c67501d7b6543ca675458a2c4210f8d5b8beaab89be8f881a6678de26a0087deb742f40
7
+ data.tar.gz: 93f714653c05e04490b1eb08849e14903047fb0016c5ddafdff8497bfd9d8d2e2bd1a8070c7672c268793fe748b57a8044b13edd149d79b2694b8a9c7239b1b3
data/.env.example ADDED
@@ -0,0 +1 @@
1
+ SONGSTATS_API_KEY=
data/.env.test ADDED
@@ -0,0 +1 @@
1
+ SONGSTATS_API_KEY=test-1234-5678-9012-3456
@@ -0,0 +1,18 @@
1
+ name: Ruby
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.0.0
14
+ - name: Run the default task
15
+ run: |
16
+ gem install bundler -v 2.2.3
17
+ bundle install
18
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .env
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ Style/StringLiterals:
2
+ Enabled: true
3
+ EnforcedStyle: double_quotes
4
+
5
+ Style/StringLiteralsInInterpolation:
6
+ Enabled: true
7
+ EnforcedStyle: double_quotes
8
+
9
+ Layout/LineLength:
10
+ Max: 120
11
+
12
+ Metrics/BlockLength:
13
+ Exclude:
14
+ - 'spec/**/*'
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at darylfindlay@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in songstats-api.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ group :development, :test do
11
+ gem "dotenv-rails"
12
+ gem "rspec", "~> 3.0"
13
+ gem "rubocop", "~> 0.80"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,150 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ songstats-api (0.1.1)
5
+ httparty
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionpack (7.1.3.2)
11
+ actionview (= 7.1.3.2)
12
+ activesupport (= 7.1.3.2)
13
+ nokogiri (>= 1.8.5)
14
+ racc
15
+ rack (>= 2.2.4)
16
+ rack-session (>= 1.0.1)
17
+ rack-test (>= 0.6.3)
18
+ rails-dom-testing (~> 2.2)
19
+ rails-html-sanitizer (~> 1.6)
20
+ actionview (7.1.3.2)
21
+ activesupport (= 7.1.3.2)
22
+ builder (~> 3.1)
23
+ erubi (~> 1.11)
24
+ rails-dom-testing (~> 2.2)
25
+ rails-html-sanitizer (~> 1.6)
26
+ activesupport (7.1.3.2)
27
+ base64
28
+ bigdecimal
29
+ concurrent-ruby (~> 1.0, >= 1.0.2)
30
+ connection_pool (>= 2.2.5)
31
+ drb
32
+ i18n (>= 1.6, < 2)
33
+ minitest (>= 5.1)
34
+ mutex_m
35
+ tzinfo (~> 2.0)
36
+ ast (2.4.2)
37
+ base64 (0.2.0)
38
+ bigdecimal (3.1.7)
39
+ builder (3.2.4)
40
+ concurrent-ruby (1.2.3)
41
+ connection_pool (2.4.1)
42
+ crass (1.0.6)
43
+ diff-lcs (1.5.1)
44
+ dotenv (3.1.0)
45
+ dotenv-rails (3.1.0)
46
+ dotenv (= 3.1.0)
47
+ railties (>= 6.1)
48
+ drb (2.2.1)
49
+ erubi (1.12.0)
50
+ httparty (0.21.0)
51
+ mini_mime (>= 1.0.0)
52
+ multi_xml (>= 0.5.2)
53
+ i18n (1.14.4)
54
+ concurrent-ruby (~> 1.0)
55
+ io-console (0.7.2)
56
+ irb (1.12.0)
57
+ rdoc
58
+ reline (>= 0.4.2)
59
+ loofah (2.22.0)
60
+ crass (~> 1.0.2)
61
+ nokogiri (>= 1.12.0)
62
+ mini_mime (1.1.5)
63
+ minitest (5.22.3)
64
+ multi_xml (0.6.0)
65
+ mutex_m (0.2.0)
66
+ nokogiri (1.16.4-arm64-darwin)
67
+ racc (~> 1.4)
68
+ parallel (1.24.0)
69
+ parser (3.3.0.5)
70
+ ast (~> 2.4.1)
71
+ racc
72
+ psych (5.1.2)
73
+ stringio
74
+ racc (1.7.3)
75
+ rack (3.0.10)
76
+ rack-session (2.0.0)
77
+ rack (>= 3.0.0)
78
+ rack-test (2.1.0)
79
+ rack (>= 1.3)
80
+ rackup (2.1.0)
81
+ rack (>= 3)
82
+ webrick (~> 1.8)
83
+ rails-dom-testing (2.2.0)
84
+ activesupport (>= 5.0.0)
85
+ minitest
86
+ nokogiri (>= 1.6)
87
+ rails-html-sanitizer (1.6.0)
88
+ loofah (~> 2.21)
89
+ nokogiri (~> 1.14)
90
+ railties (7.1.3.2)
91
+ actionpack (= 7.1.3.2)
92
+ activesupport (= 7.1.3.2)
93
+ irb
94
+ rackup (>= 1.0.0)
95
+ rake (>= 12.2)
96
+ thor (~> 1.0, >= 1.2.2)
97
+ zeitwerk (~> 2.6)
98
+ rainbow (3.1.1)
99
+ rake (13.2.1)
100
+ rdoc (6.6.3.1)
101
+ psych (>= 4.0.0)
102
+ regexp_parser (2.9.0)
103
+ reline (0.5.1)
104
+ io-console (~> 0.5)
105
+ rexml (3.2.6)
106
+ rspec (3.13.0)
107
+ rspec-core (~> 3.13.0)
108
+ rspec-expectations (~> 3.13.0)
109
+ rspec-mocks (~> 3.13.0)
110
+ rspec-core (3.13.0)
111
+ rspec-support (~> 3.13.0)
112
+ rspec-expectations (3.13.0)
113
+ diff-lcs (>= 1.2.0, < 2.0)
114
+ rspec-support (~> 3.13.0)
115
+ rspec-mocks (3.13.0)
116
+ diff-lcs (>= 1.2.0, < 2.0)
117
+ rspec-support (~> 3.13.0)
118
+ rspec-support (3.13.1)
119
+ rubocop (0.93.1)
120
+ parallel (~> 1.10)
121
+ parser (>= 2.7.1.5)
122
+ rainbow (>= 2.2.2, < 4.0)
123
+ regexp_parser (>= 1.8)
124
+ rexml
125
+ rubocop-ast (>= 0.6.0)
126
+ ruby-progressbar (~> 1.7)
127
+ unicode-display_width (>= 1.4.0, < 2.0)
128
+ rubocop-ast (1.31.2)
129
+ parser (>= 3.3.0.4)
130
+ ruby-progressbar (1.13.0)
131
+ stringio (3.1.0)
132
+ thor (1.3.1)
133
+ tzinfo (2.0.6)
134
+ concurrent-ruby (~> 1.0)
135
+ unicode-display_width (1.8.0)
136
+ webrick (1.8.1)
137
+ zeitwerk (2.6.13)
138
+
139
+ PLATFORMS
140
+ arm64-darwin-22
141
+
142
+ DEPENDENCIES
143
+ dotenv-rails
144
+ rake (~> 13.0)
145
+ rspec (~> 3.0)
146
+ rubocop (~> 0.80)
147
+ songstats-api!
148
+
149
+ BUNDLED WITH
150
+ 2.2.3
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Songstats::Api
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/songstats/api`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'songstats-api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install songstats-api
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/songstats-api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/songstats-api/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+ ## Code of Conduct
38
+
39
+ Everyone interacting in the Songstats::Api project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/songstats-api/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "songstats/api"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "singleton"
4
+
5
+ module Songstats
6
+ module Api
7
+ # Artist class for the Songstats API
8
+ class Artist < Base
9
+ include Singleton
10
+
11
+ def initialize
12
+ super
13
+ @type = "artist"
14
+ end
15
+
16
+ def info(id)
17
+ # https://docs.songstats.com/docs/api/3c84746369ec8-get-artist-info
18
+ fetch path(id, "/artists/info")
19
+ end
20
+
21
+ def activities(id, options = {})
22
+ # https://docs.songstats.com/docs/api/0d3cd6d9e1c4d-get-artist-activities
23
+ options[:source] = "all" unless options.key? :source
24
+ fetch path(id, "/artists/activities", options)
25
+ end
26
+
27
+ def stats(id, source = "all")
28
+ # https://docs.songstats.com/docs/api/6cdcdbb1adaa5-get-artist-current-stats
29
+ fetch path(id, "/artists/stats", source: source)
30
+ end
31
+
32
+ def historic_stats(id, options = {})
33
+ # https://docs.songstats.com/docs/api/a2b71875c3bea-get-artist-historic-stats
34
+ options[:source] = "all" unless options.key? :source
35
+ fetch path(id, "/artists/historic_stats", options)
36
+ end
37
+
38
+ def audience(id, source = "all")
39
+ # https://docs.songstats.com/docs/api/d0486406cfe17-get-artist-audience
40
+ fetch path(id, "/artists/audience", source: source)
41
+ end
42
+
43
+ def audience_details(id, source = "all", country_code = "US")
44
+ # https://docs.songstats.com/docs/api/956j6623vtyd4-get-artist-audience-details
45
+ fetch path(id, "/artists/audience/details", { source: source, country_code: country_code })
46
+ end
47
+
48
+ def catalog(id, options = {})
49
+ # https://docs.songstats.com/docs/api/b5b626840f42e-get-artist-catalog
50
+ fetch path(id, "/artists/catalog", options)
51
+ end
52
+
53
+ def top_tracks(id, options = {})
54
+ # https://docs.songstats.com/docs/api/b25a8506d6eae-get-artist-top-tracks
55
+ options[:source] = "all" unless options.key? :source
56
+ fetch path(id, "/artists/top_tracks", options)
57
+ end
58
+
59
+ def top_playlists(id, options = {})
60
+ # https://docs.songstats.com/docs/api/87fcd0051843e-get-artist-top-playlists
61
+ options[:source] = "all" unless options.key? :source
62
+ fetch path(id, "/artists/top_playlists", options)
63
+ end
64
+
65
+ def search(id, query, options = {})
66
+ # https://docs.songstats.com/docs/api/d761545339f09-search-artist
67
+ options[:q] = query
68
+ fetch path(id, "/artists/search", options)
69
+ end
70
+
71
+ def add_link(id, link)
72
+ # https://docs.songstats.com/docs/api/16f83e3f941f2-add-artist-link
73
+ post path(id, "/artists/link_request", link: link)
74
+ end
75
+
76
+ def delete_link(id, link)
77
+ # https://docs.songstats.com/docs/api/dc58c858fdbb6-delete-artist-link
78
+ delete path(id, "/artists/link_request", link: link)
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "httparty"
4
+
5
+ module Songstats
6
+ module Api
7
+ # Base class for the Songstats API
8
+ class Base
9
+ include HTTParty
10
+
11
+ SONG_STATS_ID_LENGTH = 8
12
+ ISRC_LENGTH = 12
13
+
14
+ base_uri "https://api.songstats.com/enterprise/v1"
15
+
16
+ def initialize
17
+ @api_key = ENV.fetch "SONGSTATS_API_KEY", nil
18
+
19
+ raise "Missing SongStats API key" if @api_key.nil?
20
+ end
21
+
22
+ private
23
+
24
+ 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
+ end
36
+
37
+ def fetch(path)
38
+ response = self.class.get path, headers: { "apiKey" => @api_key }
39
+ return response.parsed_response if response.success?
40
+
41
+ raise response.parsed_response
42
+ end
43
+
44
+ def post(path, body)
45
+ response = self.class.post path, body: body, headers: { "apiKey" => @api_key }
46
+ return response.parsed_response if response.success?
47
+
48
+ raise response.parsed_response
49
+ end
50
+
51
+ def delete(path)
52
+ response = self.class.delete path, headers: { "apiKey" => @api_key }
53
+ return response.parsed_response if response.success?
54
+
55
+ raise response.parsed_response
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Songstats
4
+ module Api
5
+ # Label class for the Songstats API
6
+ class Label < Base
7
+ include Singleton
8
+
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
14
+ end
15
+
16
+ def info(id)
17
+ # https://docs.songstats.com/docs/api/3565af9c48648-get-label-info
18
+ fetch path(id, "/labels/info")
19
+ end
20
+
21
+ def activites(id, options = {})
22
+ # https://docs.songstats.com/docs/api/1f6b7a0a1ee4d-get-label-activities
23
+ options[:source] = "all" unless options.key? :source
24
+ fetch path(id, "/labels/activities", options)
25
+ end
26
+
27
+ def stats(id, options = {})
28
+ # https://docs.songstats.com/docs/api/5891964223175-get-label-current-stats
29
+ options[:source] = "all" unless options.key? :source
30
+ fetch path(id, "/labels/stats", options)
31
+ end
32
+
33
+ def historic_stats(id, options = {})
34
+ # https://docs.songstats.com/docs/api/e0ea5143330a4-get-label-historic-stats
35
+ options[:source] = "all" unless options.key? :source
36
+ fetch path(id, "/labels/historic_stats", options)
37
+ end
38
+
39
+ def audience(id, source = "all")
40
+ # https://docs.songstats.com/docs/api/ba9cd0e9f62ab-get-label-audience
41
+ fetch path(id, "/labels/audience", source: source)
42
+ end
43
+
44
+ def audience_details(id, source = "all", country_code = "US")
45
+ # https://docs.songstats.com/docs/api/907amvb46s0ar-get-label-audience-details
46
+ fetch path(id, "/labels/audience/details", { source: source, country_code: country_code })
47
+ end
48
+
49
+ def catalog(id, options = {})
50
+ # https://docs.songstats.com/docs/api/c05d4ce991ca9-get-label-catalog
51
+ fetch path(id, "/labels/catalog", options)
52
+ end
53
+
54
+ def top_tracks(id, options = {})
55
+ # https://docs.songstats.com/docs/api/5c8071d20b59a-get-label-top-tracks
56
+ options[:source] = "all" unless options.key? :source
57
+ fetch path(id, "/labels/top_tracks", options)
58
+ end
59
+
60
+ def top_playlists(id, options = {})
61
+ # https://docs.songstats.com/docs/api/f3dab6bf2e7de-get-label-top-playlists
62
+ options[:source] = "all" unless options.key? :source
63
+ fetch path(id, "/labels/top_playlists", options)
64
+ end
65
+
66
+ def search(id, query, options = {})
67
+ # https://docs.songstats.com/docs/api/c934a2909ba0f-search-label
68
+ options[:q] = query
69
+ fetch path(id, "/labels/search", options)
70
+ end
71
+
72
+ def add_link(id, link)
73
+ # https://docs.songstats.com/docs/api/32ff3c7990342-add-label-link
74
+ post path(id, "/labels/link_request", link: link)
75
+ end
76
+
77
+ def delete_link(id, link)
78
+ # https://docs.songstats.com/docs/api/f684183faa3b9-delete-label-link
79
+ delete path(id, "/labels/link_request", link: link)
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Songstats
4
+ module Api
5
+ # Track class for the Songstats API
6
+ class Track < Base
7
+ include Singleton
8
+
9
+ def initialize
10
+ super
11
+ @type = "track"
12
+ end
13
+
14
+ def info(id)
15
+ # https://docs.songstats.com/docs/api/3c84746369ec8-get-artist-info
16
+ fetch path(id, "/tracks/info")
17
+ end
18
+
19
+ def activities(id, options = {})
20
+ # https://docs.songstats.com/docs/api/auzfvt1sw074a-get-track-activities
21
+ options[:source] = "all" unless options.key? :source
22
+ fetch path(id, "/tracks/activities", options)
23
+ end
24
+
25
+ def stats(id, options = {})
26
+ # https://docs.songstats.com/docs/api/6659134e76415-get-track-current-stats
27
+ options[:source] = "all" unless options.key? :source
28
+ fetch path(id, "/tracks/stats", options)
29
+ end
30
+
31
+ def historic_stats(id, options = {})
32
+ # https://docs.songstats.com/docs/api/b1071d94ab5fa-get-track-historic-stats
33
+ options[:source] = "all" unless options.key? :source
34
+ fetch path(id, "/tracks/historic_stats", options)
35
+ end
36
+
37
+ def search(id, query, options = {})
38
+ # https://docs.songstats.com/docs/api/1f2e4f9b3b1d1-search-track
39
+ options[:q] = query
40
+ fetch path(id, "/tracks/search", options)
41
+ end
42
+
43
+ def add_link(id, link)
44
+ # https://docs.songstats.com/docs/api/731976e6c48b1-add-track-link
45
+ post path(id, "/tracks/link_request", link: link)
46
+ end
47
+
48
+ def delete_link(id, link)
49
+ # https://docs.songstats.com/docs/api/a5432922893c6-delete-track-link
50
+ delete path(id, "/tracks/link_request", link: link)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Songstats
4
+ module Api
5
+ VERSION = "0.1.1"
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "api/version"
4
+
5
+ module Songstats
6
+ # API module for Songstats
7
+ module Api
8
+ class Error < StandardError; end
9
+
10
+ autoload :Base, "songstats/api/base"
11
+ autoload :Artist, "songstats/api/artist"
12
+ autoload :Track, "songstats/api/track"
13
+ autoload :Label, "songstats/api/label"
14
+ end
15
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/songstats/api/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "songstats-api"
7
+ spec.version = Songstats::Api::VERSION
8
+ spec.authors = ["Daryl Findlay"]
9
+ spec.email = ["darylfindlay@gmail.com"]
10
+
11
+ spec.summary = "A simple API wrapper for the Songstats API"
12
+ spec.description = "A simple API wrapper for the Songstats API"
13
+ spec.homepage = "http://www.songtradr.com"
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
15
+
16
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/songtradr/songstats-api"
20
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ # Uncomment to register a new dependency of your gem
32
+ # spec.add_dependency "example-gem", "~> 1.0"
33
+ spec.add_dependency "httparty"
34
+
35
+ spec.test_files = spec.files.grep(%r{\A(?:test|spec|features)/})
36
+
37
+ # For more information and examples about making a new gem, checkout our
38
+ # guide at: https://bundler.io/guides/creating_gem.html
39
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: songstats-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Daryl Findlay
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-04-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: A simple API wrapper for the Songstats API
28
+ email:
29
+ - darylfindlay@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".env.example"
35
+ - ".env.test"
36
+ - ".github/workflows/main.yml"
37
+ - ".gitignore"
38
+ - ".rspec"
39
+ - ".rubocop.yml"
40
+ - CODE_OF_CONDUCT.md
41
+ - Gemfile
42
+ - Gemfile.lock
43
+ - README.md
44
+ - Rakefile
45
+ - bin/console
46
+ - bin/setup
47
+ - lib/songstats/api.rb
48
+ - lib/songstats/api/artist.rb
49
+ - lib/songstats/api/base.rb
50
+ - lib/songstats/api/label.rb
51
+ - lib/songstats/api/track.rb
52
+ - lib/songstats/api/version.rb
53
+ - songstats-api.gemspec
54
+ homepage: http://www.songtradr.com
55
+ licenses: []
56
+ metadata:
57
+ homepage_uri: http://www.songtradr.com
58
+ source_code_uri: https://github.com/songtradr/songstats-api
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 2.4.0
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.2.3
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: A simple API wrapper for the Songstats API
78
+ test_files: []