spotifyrb 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.env.example +3 -0
  3. data/.github/FUNDING.yml +5 -0
  4. data/.github/dependabot.yml +11 -0
  5. data/.github/workflows/ci.yml +42 -0
  6. data/.gitignore +9 -0
  7. data/.rubocop.yml +8 -0
  8. data/Gemfile +11 -0
  9. data/Gemfile.lock +124 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +574 -0
  12. data/Rakefile +10 -0
  13. data/bin/console +19 -0
  14. data/bin/setup +8 -0
  15. data/lib/spotify/client.rb +56 -0
  16. data/lib/spotify/collection.rb +82 -0
  17. data/lib/spotify/error.rb +4 -0
  18. data/lib/spotify/error_generator.rb +128 -0
  19. data/lib/spotify/oauth.rb +61 -0
  20. data/lib/spotify/object.rb +19 -0
  21. data/lib/spotify/objects/album.rb +4 -0
  22. data/lib/spotify/objects/artist.rb +4 -0
  23. data/lib/spotify/objects/audiobook.rb +4 -0
  24. data/lib/spotify/objects/device.rb +4 -0
  25. data/lib/spotify/objects/episode.rb +4 -0
  26. data/lib/spotify/objects/player.rb +4 -0
  27. data/lib/spotify/objects/playlist.rb +4 -0
  28. data/lib/spotify/objects/show.rb +4 -0
  29. data/lib/spotify/objects/snapshot.rb +4 -0
  30. data/lib/spotify/objects/track.rb +4 -0
  31. data/lib/spotify/objects/user.rb +4 -0
  32. data/lib/spotify/resource.rb +64 -0
  33. data/lib/spotify/resources/albums.rb +16 -0
  34. data/lib/spotify/resources/artists.rb +20 -0
  35. data/lib/spotify/resources/me.rb +13 -0
  36. data/lib/spotify/resources/player.rb +46 -0
  37. data/lib/spotify/resources/playlists.rb +37 -0
  38. data/lib/spotify/resources/search.rb +10 -0
  39. data/lib/spotify/resources/users.rb +13 -0
  40. data/lib/spotify/version.rb +3 -0
  41. data/lib/spotify.rb +36 -0
  42. data/lib/spotifyrb.rb +1 -0
  43. data/spotifyrb.gemspec +29 -0
  44. metadata +111 -0
data/README.md ADDED
@@ -0,0 +1,574 @@
1
+ # SpotifyRB
2
+
3
+ SpotifyRB is the easiest and most complete Ruby library for the [Spotify API](https://developer.spotify.com/documentation/web-api).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem "spotifyrb"
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### Set Client Details
16
+
17
+ Firstly you'll need to set a Client ID and an Access Token.
18
+
19
+ An access token is required because the Spotify API requires authentication.
20
+
21
+ ```ruby
22
+ @client = Spotify::Client.new(access_token: "xyz123")
23
+ ```
24
+
25
+ ### Resources
26
+
27
+ The gem maps as closely as we can to the Spotify API so you can easily convert API examples to gem code.
28
+
29
+ Responses are created as objects like `Spotify::Channel`. Having types like `Spotify::User` is handy for understanding what
30
+ type of object you're working with. They're built using OpenStruct so you can easily access data in a Ruby-ish way.
31
+
32
+ ### Pagination
33
+
34
+ Some of the endpoints return pages of results. The result object will have a `data` key to access the results, as well as metadata like `cursor`
35
+ for retrieving the next and previous pages. This can be used by using `before` and `after` parameters, on API endpoints that support it.
36
+
37
+ An example of using collections, including pagination:
38
+
39
+ ```ruby
40
+ results = @client.clips.list(broadcaster_id: 123)
41
+ #=> Spotify::Collection
42
+
43
+ results.total
44
+ #=> 30
45
+
46
+ results.data
47
+ #=> [#<Spotify::Clip>, #<Spotify::Clip>]
48
+
49
+ results.each do |result|
50
+ puts result.id
51
+ end
52
+
53
+ results.first
54
+ #=> #<Spotify::Clip>
55
+
56
+ results.last
57
+ #=> #<Spotify::Clip>
58
+
59
+ results.cursor
60
+ #=> "abc123"
61
+
62
+ # Retrieve the next page
63
+ @client.clips.list(broadcaster_id: 123, after: results.cursor)
64
+ #=> Spotify::Collection
65
+ ```
66
+
67
+ ### OAuth
68
+
69
+ This library includes the ability to create, refresh and revoke OAuth tokens.
70
+
71
+ ```ruby
72
+ # Firstly, set the client details
73
+ @oauth = Spotify::OAuth.new(client_id: "", client_secret: "")
74
+
75
+ # Create a Token
76
+ # grant_type can be either "authorization_code" or "client_credentials"
77
+ # scope is a space-delimited list of scopes. This is optional depending on the grant_type
78
+ @oauth.create(grant_type: "", scope: "")
79
+
80
+ # Refresh a Token
81
+ @oauth.refresh(refresh_token: "")
82
+
83
+ # Device Code Grant Flow
84
+ # scopes is required and is a space-delimited list of scopes
85
+ # https://dev.spotify.tv/docs/authentication/getting-tokens-oauth/#device-code-grant-flow
86
+ @oauth.device(scopes: "bits:read channel:read:subscriptions")
87
+
88
+ # Validate an Access Token
89
+ # Returns false if the token is invalid
90
+ @oauth.validate(token: "")
91
+
92
+ # Revoke a Token
93
+ @oauth.revoke(token: "")
94
+ ```
95
+
96
+ ### Users
97
+
98
+ ```ruby
99
+ # Retrieves a user by their ID
100
+ @client.users.retrieve(id: 141981764)
101
+
102
+ # Retrieves multiple users by their IDs
103
+ # Requires an array of IDs
104
+ @client.users.retrieve(ids: [141981764, 72938118])
105
+
106
+ # Retrieves a user by their username
107
+ @client.users.retrieve(username: "spotifydev")
108
+
109
+ # Retrieves multiple users by their usernames
110
+ # Requires an array of IDs
111
+ @client.users.retrieve(usernames: ["spotifydev", "deanpcmad"])
112
+
113
+ # Update the currently authenticated user's description
114
+ # Required scope: user:edit
115
+ @client.users.update(description: "New Description")
116
+
117
+ # Returns Blocked users for a broadcaster
118
+ # Required scope: user:read:blocked_users
119
+ @client.users.blocks(broadcaster_id: 141981764)
120
+
121
+ # Blocks a user
122
+ # Required scope: user:manage:blocked_users
123
+ @client.users.block_user(target_user_id: 141981764)
124
+
125
+ # Unblocks a user
126
+ # Required scope: user:manage:blocked_users
127
+ @client.users.unblock_user(target_user_id: 141981764)
128
+
129
+ # Get a User's Chat Color
130
+ @client.users.get_color(user_id: 123)
131
+
132
+ # Or get multiple users' chat colors
133
+ # Returns a collection
134
+ @client.users.get_color(user_ids: "123,321")
135
+
136
+ # Update a User's Chat Color
137
+ # Requires user:manage:chat_color
138
+ # user_id must be the currently authenticated user
139
+ # Current allowed colours: blue, blue_violet, cadet_blue, chocolate, coral, dodger_blue, firebrick, golden_rod, green, hot_pink, orange_red, red, sea_green, spring_green, yellow_green
140
+ # For Turbo and Prime users, a hex colour code is allowed.
141
+ @client.users.update_color(user_id: 123, color: "blue")
142
+
143
+ # Get Emotes a User has
144
+ # Required scope: user:read:emotes
145
+ @client.users.emotes(user_id: 123)
146
+ @client.users.emotes(user_id: 123, broadcaster_id: 321)
147
+ @client.users.emotes(user_id: 123, after: "abc123")
148
+ ```
149
+
150
+ ### Channels
151
+
152
+ ```ruby
153
+ # Retrieve a channel by their ID
154
+ @client.channels.retrieve(id: 141981764)
155
+
156
+ # Retrieve a list of broadcasters a specified user follows
157
+ # user_id must match the currently authenticated user
158
+ # Required scope: user:read:follows
159
+ @client.channels.followed user_id: 123123
160
+
161
+ # Retrieve a list of users that follow a specified broadcaster
162
+ # broadcaster_id must match the currently authenticated user or
163
+ # a moderator of the specified broadcaster
164
+ # Required scope: moderator:read:followers
165
+ @client.channels.followers broadcaster_id: 123123
166
+
167
+ # Retrieve the number of Followers a broadcaster has
168
+ @client.channels.follows_count(broadcaster_id: 141981764)
169
+
170
+ # Retrieve the number of Subscribers and Subscriber Points a broadcaster has
171
+ # Required scope: channel:read:subscriptions
172
+ @client.channels.subscribers_count(broadcaster_id: 141981764)
173
+
174
+ # Update the currently authenticated channel details
175
+ # Required scope: channel:manage:broadcast
176
+ # Parameters which are allowed: game_id, title, broadcaster_language, delay
177
+ attributes = {title: "My new title"}
178
+ @client.channels.update(broadcaster_id: 141981764, attributes)
179
+
180
+ # Retrieves editors for a channel
181
+ @client.channels.editors(broadcaster_id: 141981764)
182
+ ```
183
+
184
+ ### Videos
185
+
186
+ ```ruby
187
+ # Retrieves a list of videos
188
+ # Available parameters: user_id or game_id
189
+ @client.videos.list(user_id: 12345)
190
+ @client.videos.list(game_id: 12345)
191
+
192
+ # Retrieves a video by its ID
193
+ @client.videos.retrieve(id: 12345)
194
+ ```
195
+
196
+ ### Clips
197
+
198
+ ```ruby
199
+ # Retrieves a list of clips
200
+ # Available parameters: broadcaster_id or game_id
201
+ @client.clips.list(user_id: 12345)
202
+ @client.clips.list(game_id: 12345)
203
+
204
+ # Retrieves a clip by its ID.
205
+ # Clip IDs are alphanumeric. e.g. AwkwardHelplessSalamanderSwiftRage
206
+ @client.clips.retrieve(id: "AwkwardHelplessSalamanderSwiftRage")
207
+
208
+ # Create a clip of a given Channel
209
+ # Required scope: clips:edit
210
+ @client.clips.create(broadcaster_id: 1234)
211
+ ```
212
+
213
+ ### Emotes
214
+
215
+ ```ruby
216
+ # Retrieve all global emotes
217
+ @client.emotes.global
218
+
219
+ # Retrieve emotes for a channel
220
+ @client.emotes.channel(broadcaster_id: 141981764)
221
+
222
+ # Retrieve emotes for an emote set
223
+ @client.emotes.sets(emote_set_id: 301590448)
224
+ ```
225
+
226
+ ### Badges
227
+
228
+ ```ruby
229
+ # Retrieve all global badges
230
+ @client.badges.global
231
+
232
+ # Retrieve badges for a channel
233
+ @client.badges.channel(broadcaster_id: 141981764)
234
+ ```
235
+
236
+ ### Games
237
+
238
+ ```ruby
239
+ # Retrieves a game by ID
240
+ @client.games.retrieve(id: 514974)
241
+
242
+ # Retrieves multiple games by IDs
243
+ # Requires an array of IDs
244
+ @client.games.retrieve(ids: [66402, 514974])
245
+
246
+ # Retrieves a game by name
247
+ @client.games.retrieve(name: "Battlefield 4")
248
+
249
+ # Retrieves multiple games by names
250
+ # Requires an array of IDs
251
+ @client.games.retrieve(names: ["Battlefield 4", "Battlefield 2042"])
252
+ ```
253
+
254
+ ### EventSub Subscriptions
255
+
256
+ These require an application OAuth access token.
257
+
258
+ ```ruby
259
+ # Retrieves a list of EventSub Subscriptions
260
+ # Available parameters: status, type, after
261
+ @client.eventsub_subscriptions.list
262
+ @client.eventsub_subscriptions.list(status: "enabled")
263
+ @client.eventsub_subscriptions.list(type: "channel.follow")
264
+
265
+ # Create an EventSub Subscription
266
+ @client.eventsub_subscriptions.create(
267
+ type: "channel.follow",
268
+ version: 1,
269
+ condition: {broadcaster_user_id: 123},
270
+ transport: {method: "webhook", callback: "webhook_url", secret: "secret"}
271
+ )
272
+
273
+ # Delete an EventSub Subscription
274
+ # IDs are UUIDs
275
+ @client.eventsub_subscriptions.delete(id: "abc12-abc12-abc12")
276
+ ```
277
+
278
+ ### Banned Events
279
+
280
+ ```ruby
281
+ # Retrieves all ban and un-ban events for a channel
282
+ # Available parameters: user_id
283
+ @client.banned_events.list(broadcaster_id: 123)
284
+ ```
285
+
286
+ ### Banned Users
287
+
288
+ ```ruby
289
+ # Retrieves all banned and timed-out users for a channel
290
+ # Available parameters: user_id
291
+ @client.banned_users.list(broadcaster_id: 123)
292
+ ```
293
+
294
+ ```ruby
295
+ # Ban/Timeout a user from a broadcaster's channel
296
+ # Required scope: moderator:manage:banned_users
297
+ # A reason is required
298
+ # To time a user out, a duration is required. If no duration is set, the user will be banned.
299
+ @client.banned_users.create broadcaster_id: 123, moderator_id: 321, user_id: 112233, reason: "testing", duration: 60
300
+ ```
301
+
302
+ ```ruby
303
+ # Unban/untimeout a user from a broadcaster's channel
304
+ # Required scope: moderator:manage:banned_users
305
+ @client.banned_users.delete broadcaster_id: 123, moderator_id: 321, user_id: 112233
306
+ ```
307
+
308
+ ### Send Chat Announcement
309
+
310
+ ```ruby
311
+ # Sends an announcement to the broadcaster's chat room
312
+ # Requires moderator:manage:announcements
313
+ # moderator_id can be either the currently authenticated moderator or the broadcaster
314
+ # color can be either blue, green, orange, purple, primary. If left blank, primary is default
315
+ @client.announcements.create broadcaster_id: 123, moderator_id: 123, message: "test message", color: "purple"
316
+ ```
317
+
318
+ ### Create a Shoutout
319
+
320
+ ```ruby
321
+ # Creates a Shoutout for a broadcaster
322
+ # Requires moderator:manage:shoutouts
323
+ # From: the ID of the Broadcaster creating the Shoutout
324
+ # To: the ID of the Broadcaster the Shoutout will be for
325
+ # moderator_id can be either the currently authenticated moderator or the broadcaster
326
+ @client.shoutouts.create from: 123, to: 321, moderator_id: 123
327
+ ```
328
+
329
+ ### Moderators
330
+
331
+ ```ruby
332
+ # List all channels a user has moderator privileges on
333
+ # Required scope: user:read:moderated_channels
334
+ # user_id must be the currently authenticated user
335
+ @client.moderators.channels user_id: 123
336
+ ```
337
+
338
+ ```ruby
339
+ # List all moderators for a broadcaster
340
+ # Required scope: moderation:read
341
+ # broadcaster_id must be the currently authenticated user
342
+ @client.moderators.list broadcaster_id: 123
343
+ ```
344
+
345
+ ```ruby
346
+ # Add a Moderator
347
+ # Required scope: channel:manage:moderators
348
+ # broadcaster_id must be the currently authenticated user
349
+ @client.moderators.create broadcaster_id: 123, user_id: 321
350
+ ```
351
+
352
+ ```ruby
353
+ # Remove a Moderator
354
+ # Required scope: channel:manage:moderators
355
+ # broadcaster_id must be the currently authenticated user
356
+ @client.moderators.delete broadcaster_id: 123, user_id: 321
357
+ ```
358
+
359
+ ### VIPs
360
+
361
+ ```ruby
362
+ # List all VIPs for a broadcaster
363
+ # Required scope: channel:read:vips or channel:manage:vips
364
+ # broadcaster_id must be the currently authenticated user
365
+ @client.vips.list broadcaster_id: 123
366
+ ```
367
+
368
+ ```ruby
369
+ # Add a VIP
370
+ # Required scope: channel:manage:vips
371
+ # broadcaster_id must be the currently authenticated user
372
+ @client.vips.create broadcaster_id: 123, user_id: 321
373
+ ```
374
+
375
+ ```ruby
376
+ # Remove a VIP
377
+ # Required scope: channel:manage:vips
378
+ # broadcaster_id must be the currently authenticated user
379
+ @client.vips.delete broadcaster_id: 123, user_id: 321
380
+ ```
381
+
382
+ ### Raids
383
+
384
+ ```ruby
385
+ # Starts a raid
386
+ # Requires channel:manage:raids
387
+ # from_broadcaster_id must be the authenticated user
388
+ @client.raids.create from_broadcaster_id: 123, to_broadcaster_id: 321
389
+ ```
390
+
391
+ ```ruby
392
+ # Requires channel:manage:raids
393
+ # broadcaster_id must be the authenticated user
394
+ @client.raids.delete broadcaster_id: 123
395
+ ```
396
+
397
+ ### Chat Messages
398
+
399
+ ```ruby
400
+ # Send a chat message to a broadcaster's chat room
401
+ # Requires an app or user access token that includes user:write:chat then either user:bot or channel:bot
402
+ # sender_id must be the currently authenticated user
403
+ # reply_to is optional and is the UUID of the message to reply to
404
+ @client.chat_messages.create broadcaster_id: 123, sender_id: 321, message: "A test message", reply_to: "aabbcc"
405
+
406
+ # Removes a single chat message from the broadcaster's chat room
407
+ # Requires moderator:manage:chat_messages
408
+ # moderator_id can be either the currently authenticated moderator or the broadcaster
409
+ @client.chat_messages.delete broadcaster_id: 123, moderator_id: 123, message_id: "abc123-abc123"
410
+ ```
411
+
412
+ ### Whispers
413
+
414
+ ```ruby
415
+ # Send a Whisper
416
+ # Required scope: user:manage:whispers
417
+ # from_user_id must be the currently authenticated user's ID and have a verified phone number
418
+ @client.whispers.create from_user_id: 123, to_user_id: 321, message: "this is a test"
419
+ ```
420
+
421
+ ### AutoMod
422
+
423
+ ```ruby
424
+ # Check if a message meets the channel's AutoMod requirements
425
+ # Required scope: moderation:read
426
+ # id is a developer-generated identifier for mapping messages to results.
427
+ @client.automod.check_status_multiple broadcaster_id: 123, id: "abc123", text: "Is this message allowed?"
428
+
429
+ #> #<Spotify::AutomodStatus msg_id="abc123", is_permitted=true>
430
+ ```
431
+
432
+ ```ruby
433
+ # Check if multiple messages meet the channel's AutoMod requirements
434
+ # messages must be an array of hashes and must include msg_id and msg_text
435
+ # Returns a collection
436
+ messages = [{msg_id: "abc1", msg_text: "is this allowed?"}, {msg_id: "abc2", msg_text: "What about this?"}]
437
+ @client.automod.check_status_multiple broadcaster_id: 123, messages: messages
438
+ ```
439
+
440
+ ```ruby
441
+ # Get AutoMod settings
442
+ # Required scope: moderator:read:automod_settings
443
+ # moderator_id can be either the currently authenticated moderator or the broadcaster
444
+ @client.automod.settings broadcaster_id: 123, moderator_id: 321
445
+ ```
446
+
447
+ ```ruby
448
+ # Update AutoMod settings
449
+ # Required scope: moderator:manage:automod_settings
450
+ # moderator_id can be either the currently authenticated moderator or the broadcaster
451
+ # As this is a PUT method, it overwrites all options so all fields you want set should be supplied
452
+ @client.automod.update_settings broadcaster_id: 123, moderator_id: 321, swearing: 1
453
+ ```
454
+
455
+ ### Creator Goals
456
+
457
+ ```ruby
458
+ # List all active creator goals
459
+ # Required scope: channel:read:goals
460
+ # broadcaster_id must match the currently authenticated user
461
+ @client.goals.list broadcaster_id: 123
462
+ ```
463
+
464
+ ### Blocked Terms
465
+
466
+ ```ruby
467
+ # List all blocked terms
468
+ # Required scope: moderator:read:blocked_terms
469
+ # moderator_id can be either the currently authenticated moderator or the broadcaster
470
+ @client.blocked_terms.list broadcaster_id: 123, moderator_id: 321
471
+ ```
472
+
473
+ ```ruby
474
+ # Create a blocked term
475
+ # Required scope: moderator:manage:blocked_terms
476
+ # moderator_id can be either the currently authenticated moderator or the broadcaster
477
+ @client.blocked_terms.create broadcaster_id: 123, moderator_id: 321, text: "term to block"
478
+ ```
479
+
480
+ ```ruby
481
+ # Delete a blocked term
482
+ # Required scope: moderator:manage:blocked_terms
483
+ # moderator_id can be either the currently authenticated moderator or the broadcaster
484
+ @client.blocked_terms.delete broadcaster_id: 123, moderator_id: 321, id: "abc12-12abc"
485
+ ```
486
+
487
+ ### Charity Campaigns
488
+
489
+ ```ruby
490
+ # Gets information about the charity campaign that a broadcaster is running
491
+ # Required scope: channel:read:charity
492
+ # broadcaster_id must match the currently authenticated user
493
+ @client.charity_campaigns.list broadcaster_id: 123
494
+ ```
495
+
496
+ ### Chatters
497
+
498
+ ```ruby
499
+ # Gets the list of users that are connected to the specified broadcaster’s chat session
500
+ # Required scope: moderator:read:chatters
501
+ # broadcaster_id must match the currently authenticated user
502
+ @client.chatters.list broadcaster_id: 123, moderator_id: 123
503
+ ```
504
+
505
+ ### Channel Points Custom Rewards
506
+
507
+ ```ruby
508
+ # Gets a list of custom rewards for a specific channel
509
+ # Required scope: channel:read:redemptions
510
+ # broadcaster_id must match the currently authenticated user
511
+ @client.custom_rewards.list broadcaster_id: 123
512
+
513
+ # Create a custom reward
514
+ # Required scope: channel:manage:redemptions
515
+ # broadcaster_id must match the currently authenticated user
516
+ @client.custom_rewards.create broadcaster_id: 123, title: "New Reward", cost: 1000
517
+
518
+ # Update a custom reward
519
+ # Required scope: channel:manage:redemptions
520
+ # broadcaster_id must match the currently authenticated user
521
+ @client.custom_rewards.update broadcaster_id: 123, reward_id: 321, title: "Updated Reward"
522
+
523
+ # Delete a custom reward
524
+ # Required scope: channel:manage:redemptions
525
+ # broadcaster_id must match the currently authenticated user
526
+ @client.custom_rewards.delete broadcaster_id: 123, reward_id: 321
527
+ ```
528
+
529
+ ### Channel Points Custom Reward Redemptions
530
+
531
+ ```ruby
532
+ # Gets a list of custom reward redemptions for a specific channel
533
+ # Required scope: channel:read:redemptions
534
+ # broadcaster_id must match the currently authenticated user
535
+ @client.custom_reward_redemptions.list broadcaster_id: 123, reward_id: 321, status: "UNFULFILLED"
536
+
537
+ # Update a custom reward redemption status
538
+ # Required scope: channel:manage:redemptions
539
+ # broadcaster_id must match the currently authenticated user
540
+ # Status can be FULFILLED or CANCELED
541
+ @client.custom_reward_redemptions.update broadcaster_id: 123, reward_id: 321, redemption_id: 123, status: "FULFILLED"
542
+ ```
543
+
544
+ ### Unban Requests
545
+
546
+ ```ruby
547
+ # Retrieves a list of Unban Requests for a broadcaster
548
+ # Required scope: moderator:read:unban_requests or moderator:manage:unban_requests
549
+ # moderator_id must match the currently authenticated user
550
+ @client.unban_requests.list broadcaster_id: 123, moderator_id: 123, status: "pending"
551
+
552
+ # Resolve an Unban Request
553
+ # Required scope: moderator:manage:unban_requests
554
+ # moderator_id must match the currently authenticated user
555
+ @client.unban_requests.resolve broadcaster_id: 123, moderator_id: 123, id: "abc123", status: "approved"
556
+ ```
557
+
558
+ ### Warnings
559
+
560
+ ```ruby
561
+ # Sends a warning to a user
562
+ # Required scope: moderator:manage:warnings
563
+ # moderator_id must match the currently authenticated user
564
+ @client.warnings.create broadcaster_id: 123, moderator_id: 123, user_id: 321, reason: "dont do that"
565
+ ```
566
+
567
+
568
+ ## Contributing
569
+
570
+ Bug reports and pull requests are welcome on GitHub at https://github.com/deanpcmad/spotifyrb.
571
+
572
+ ## License
573
+
574
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "spotify"
5
+
6
+ # Load environment variables from .env file
7
+ require 'dotenv/load'
8
+
9
+ # You can add fixtures and/or initialization code here to make experimenting
10
+ # with your gem easier. You can also use a different console, if you like.
11
+
12
+ # (If you use this, don't forget to add pry to your Gemfile!)
13
+ # require "pry"
14
+ # Pry.start
15
+
16
+ @client = Spotify::Client.new(access_token: ENV["SPOTIFY_ACCESS_TOKEN"])
17
+
18
+ require "irb"
19
+ 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,56 @@
1
+ module Spotify
2
+ class Client
3
+ BASE_URL = "https://api.spotify.com/v1"
4
+
5
+ attr_reader :access_token, :adapter
6
+
7
+ def initialize(access_token:, adapter: Faraday.default_adapter)
8
+ @access_token = access_token
9
+ @adapter = adapter
10
+ end
11
+
12
+ def me
13
+ MeResource.new(self)
14
+ end
15
+
16
+ def search
17
+ SearchResource.new(self)
18
+ end
19
+
20
+ def player
21
+ PlayerResource.new(self)
22
+ end
23
+
24
+ def users
25
+ UsersResource.new(self)
26
+ end
27
+
28
+ def albums
29
+ AlbumsResource.new(self)
30
+ end
31
+
32
+ def artists
33
+ ArtistsResource.new(self)
34
+ end
35
+
36
+ def playlists
37
+ PlaylistsResource.new(self)
38
+ end
39
+
40
+ def connection
41
+ @connection ||= Faraday.new(BASE_URL) do |conn|
42
+ conn.request :authorization, :Bearer, access_token
43
+
44
+ conn.headers = {
45
+ "User-Agent" => "spotifyrb/v#{VERSION} (github.com/deanpcmad/spotifyrb)"
46
+ }
47
+
48
+ conn.request :json
49
+
50
+ conn.response :json, content_type: "application/json"
51
+
52
+ conn.adapter adapter, @stubs
53
+ end
54
+ end
55
+ end
56
+ end