Class: SpotifyWebApi::EpisodesController

Inherits:
BaseController show all
Defined in:
lib/spotify_web_api/controllers/episodes_controller.rb

Overview

EpisodesController

Constant Summary

Constants inherited from BaseController

BaseController::GLOBAL_ERRORS

Instance Attribute Summary

Attributes inherited from BaseController

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseController

#initialize, #new_api_call_builder, #new_parameter, #new_request_builder, #new_response_handler, user_agent

Constructor Details

This class inherits a constructor from SpotifyWebApi::BaseController

Instance Method Details

#check_users_saved_episodes(ids) ⇒ Array[TrueClass | FalseClass]

Check if one or more episodes is already saved in the current Spotify user’s ‘Your Episodes’ library.<br/> This API endpoint is in __beta__ and could change without warning. Please share any feedback that you have, or issues that you discover, in our [developer community forum](community.spotify.com/t5/Spotify-for-Developers/bd-p/Spotif y_Developer)..

Parameters:

  • ids (String)

    Required parameter: Example:

Returns:

  • (Array[TrueClass | FalseClass])

    response from the API call



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/spotify_web_api/controllers/episodes_controller.rb', line 210

def check_users_saved_episodes(ids)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/me/episodes/contains',
                                 Server::DEFAULT)
               .query_param(new_parameter(ids, key: 'ids'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('oauth_2_0')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:deserialize_primitive_types))
                .is_api_response(true)
                .is_response_array(true)
                .is_primitive_response(true)
                .local_error('401',
                             "Bad or expired token. This can happen if the user revoked a'\
                              ' token or\nthe access token has expired. You should'\
                              ' re-authenticate the user.\n",
                             UnauthorizedException)
                .local_error('403',
                             "Bad OAuth request (wrong consumer key, bad nonce, expired'\
                              '\ntimestamp...). Unfortunately, re-authenticating the user'\
                              ' won't help here.\n",
                             ForbiddenException)
                .local_error('429',
                             "The app has exceeded its rate limits.\n",
                             TooManyRequestsException))
    .execute
end

#get_an_episode(id, market: nil) ⇒ EpisodeObject

Get Spotify catalog information for a single episode identified by its unique Spotify ID.

Parameters:

  • id (String)

    Required parameter: Example:

  • market (String) (defaults to: nil)

    Optional parameter: Example:

Returns:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/spotify_web_api/controllers/episodes_controller.rb', line 14

def get_an_episode(id,
                   market: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/episodes/{id}',
                                 Server::DEFAULT)
               .template_param(new_parameter(id, key: 'id')
                                .should_encode(true))
               .query_param(new_parameter(market, key: 'market'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('oauth_2_0')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(EpisodeObject.method(:from_hash))
                .is_api_response(true)
                .local_error('401',
                             "Bad or expired token. This can happen if the user revoked a'\
                              ' token or\nthe access token has expired. You should'\
                              ' re-authenticate the user.\n",
                             UnauthorizedException)
                .local_error('403',
                             "Bad OAuth request (wrong consumer key, bad nonce, expired'\
                              '\ntimestamp...). Unfortunately, re-authenticating the user'\
                              ' won't help here.\n",
                             ForbiddenException)
                .local_error('429',
                             "The app has exceeded its rate limits.\n",
                             TooManyRequestsException))
    .execute
end

#get_multiple_episodes(ids, market: nil) ⇒ ManyEpisodes

Get Spotify catalog information for several episodes based on their Spotify IDs.

Parameters:

  • ids (String)

    Required parameter: Example:

  • market (String) (defaults to: nil)

    Optional parameter: Example:

Returns:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/spotify_web_api/controllers/episodes_controller.rb', line 50

def get_multiple_episodes(ids,
                          market: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/episodes',
                                 Server::DEFAULT)
               .query_param(new_parameter(ids, key: 'ids'))
               .query_param(new_parameter(market, key: 'market'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('oauth_2_0')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(ManyEpisodes.method(:from_hash))
                .is_api_response(true)
                .local_error('401',
                             "Bad or expired token. This can happen if the user revoked a'\
                              ' token or\nthe access token has expired. You should'\
                              ' re-authenticate the user.\n",
                             UnauthorizedException)
                .local_error('403',
                             "Bad OAuth request (wrong consumer key, bad nonce, expired'\
                              '\ntimestamp...). Unfortunately, re-authenticating the user'\
                              ' won't help here.\n",
                             ForbiddenException)
                .local_error('429',
                             "The app has exceeded its rate limits.\n",
                             TooManyRequestsException))
    .execute
end

#get_users_saved_episodes(market: nil, limit: 20, offset: 0) ⇒ PagingSavedEpisodeObject

Get a list of the episodes saved in the current Spotify user’s library.<br/> This API endpoint is in __beta__ and could change without warning. Please share any feedback that you have, or issues that you discover, in our [developer community forum](community.spotify.com/t5/Spotify-for-Developers/bd-p/Spotif y_Developer).

Parameters:

  • market (String) (defaults to: nil)

    Optional parameter: Example:

  • limit (Integer) (defaults to: 20)

    Optional parameter: Example:20

  • offset (Integer) (defaults to: 0)

    Optional parameter: Example:0

Returns:



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/spotify_web_api/controllers/episodes_controller.rb', line 91

def get_users_saved_episodes(market: nil,
                             limit: 20,
                             offset: 0)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/me/episodes',
                                 Server::DEFAULT)
               .query_param(new_parameter(market, key: 'market'))
               .query_param(new_parameter(limit, key: 'limit'))
               .query_param(new_parameter(offset, key: 'offset'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('oauth_2_0')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(PagingSavedEpisodeObject.method(:from_hash))
                .is_api_response(true)
                .local_error('401',
                             "Bad or expired token. This can happen if the user revoked a'\
                              ' token or\nthe access token has expired. You should'\
                              ' re-authenticate the user.\n",
                             UnauthorizedException)
                .local_error('403',
                             "Bad OAuth request (wrong consumer key, bad nonce, expired'\
                              '\ntimestamp...). Unfortunately, re-authenticating the user'\
                              ' won't help here.\n",
                             ForbiddenException)
                .local_error('429',
                             "The app has exceeded its rate limits.\n",
                             TooManyRequestsException))
    .execute
end

#remove_episodes_user(ids, body: nil) ⇒ void

This method returns an undefined value.

Remove one or more episodes from the current user’s library.<br/> This API endpoint is in __beta__ and could change without warning. Please share any feedback that you have, or issues that you discover, in our [developer community forum](community.spotify.com/t5/Spotify-for-Developers/bd-p/Spotif y_Developer).

Parameters:

  • ids (String)

    Required parameter: Example:

  • body (MeEpisodesRequest1) (defaults to: nil)

    Optional parameter: Example:



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/spotify_web_api/controllers/episodes_controller.rb', line 171

def remove_episodes_user(ids,
                         body: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::DELETE,
                                 '/me/episodes',
                                 Server::DEFAULT)
               .query_param(new_parameter(ids, key: 'ids'))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('oauth_2_0')))
    .response(new_response_handler
                .is_response_void(true)
                .is_api_response(true)
                .local_error('401',
                             "Bad or expired token. This can happen if the user revoked a'\
                              ' token or\nthe access token has expired. You should'\
                              ' re-authenticate the user.\n",
                             UnauthorizedException)
                .local_error('403',
                             "Bad OAuth request (wrong consumer key, bad nonce, expired'\
                              '\ntimestamp...). Unfortunately, re-authenticating the user'\
                              ' won't help here.\n",
                             ForbiddenException)
                .local_error('429',
                             "The app has exceeded its rate limits.\n",
                             TooManyRequestsException))
    .execute
end

#save_episodes_user(ids, body: nil) ⇒ void

This method returns an undefined value.

Save one or more episodes to the current user’s library.<br/> This API endpoint is in __beta__ and could change without warning. Please share any feedback that you have, or issues that you discover, in our [developer community forum](community.spotify.com/t5/Spotify-for-Developers/bd-p/Spotif y_Developer).

Parameters:

  • ids (String)

    Required parameter: Example:

  • body (MeEpisodesRequest) (defaults to: nil)

    Optional parameter: Example:



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/spotify_web_api/controllers/episodes_controller.rb', line 132

def save_episodes_user(ids,
                       body: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/me/episodes',
                                 Server::DEFAULT)
               .query_param(new_parameter(ids, key: 'ids'))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('oauth_2_0')))
    .response(new_response_handler
                .is_response_void(true)
                .is_api_response(true)
                .local_error('401',
                             "Bad or expired token. This can happen if the user revoked a'\
                              ' token or\nthe access token has expired. You should'\
                              ' re-authenticate the user.\n",
                             UnauthorizedException)
                .local_error('403',
                             "Bad OAuth request (wrong consumer key, bad nonce, expired'\
                              '\ntimestamp...). Unfortunately, re-authenticating the user'\
                              ' won't help here.\n",
                             ForbiddenException)
                .local_error('429',
                             "The app has exceeded its rate limits.\n",
                             TooManyRequestsException))
    .execute
end