musicube_api_client_ruby 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +9 -0
- data/README.md +223 -0
- data/Rakefile +10 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/docs/AllowedValuesApi.md +200 -0
- data/docs/CategoryMediumDTO.md +22 -0
- data/docs/CategoryMinimalDTO.md +18 -0
- data/docs/ConfigAccessDTO.md +20 -0
- data/docs/ConfigIdentifierDTO.md +20 -0
- data/docs/ContributorTypeDTO.md +18 -0
- data/docs/ErrorResponse.md +26 -0
- data/docs/FieldSummaryDTO.md +22 -0
- data/docs/FileDTO.md +50 -0
- data/docs/FileListDTO.md +24 -0
- data/docs/FileMinimalWithUrlDTO.md +22 -0
- data/docs/FileSmallDTO.md +46 -0
- data/docs/FileUploadDTO.md +22 -0
- data/docs/FileWIthUrlDTO.md +20 -0
- data/docs/FilesSummaryDTO.md +30 -0
- data/docs/ForgotPasswordDTO.md +20 -0
- data/docs/GenreDTO.md +20 -0
- data/docs/GenreMinimalDTO.md +18 -0
- data/docs/GenresSummaryDTO.md +22 -0
- data/docs/InitPutRecordingAudioDTO.md +22 -0
- data/docs/JwtTokenDTO.md +22 -0
- data/docs/LoginDTO.md +24 -0
- data/docs/MusicalFeaturesDTO.md +186 -0
- data/docs/PLineDTO.md +20 -0
- data/docs/PartyApi.md +75 -0
- data/docs/PartyLargeDTO.md +32 -0
- data/docs/PartySmallDTO.md +20 -0
- data/docs/PlaylistApi.md +221 -0
- data/docs/PlaylistLargeDTO.md +38 -0
- data/docs/ProductMediumDTO.md +34 -0
- data/docs/ProductPartyDTO.md +20 -0
- data/docs/RecordingApi.md +789 -0
- data/docs/RecordingForSimilaritySearchDTO.md +20 -0
- data/docs/RecordingGenrePredictionDTO.md +22 -0
- data/docs/RecordingLargeDTO.md +40 -0
- data/docs/RecordingListDTO.md +24 -0
- data/docs/RecordingMediumDTO.md +36 -0
- data/docs/RecordingMinimalWithMusicalFeaturesDTO.md +20 -0
- data/docs/RecordingMinimalWithTaggramsDTO.md +22 -0
- data/docs/RecordingMinimalWithTagstrengthsDTO.md +20 -0
- data/docs/RecordingPartyDTO.md +20 -0
- data/docs/RecordingPlaylistDTO.md +24 -0
- data/docs/RecordingSmallDTO.md +24 -0
- data/docs/RecordingTagSmallDTO.md +18 -0
- data/docs/SaveFileRecordingDTO.md +236 -0
- data/docs/SavePlaylistDTO.md +34 -0
- data/docs/SaveRecordingGenreDTO.md +22 -0
- data/docs/SaveRecordingPartyDTO.md +20 -0
- data/docs/SaveRecordingPlaylistDTO.md +22 -0
- data/docs/SaveRecordingTagDTO.md +20 -0
- data/docs/SaveReferrerDTO.md +20 -0
- data/docs/SaveTaggramsDTO.md +82 -0
- data/docs/SaveUserDTO.md +28 -0
- data/docs/SearchFilterValuesDTO.md +98 -0
- data/docs/SearchRecordingGranularAbstractionDTO.md +20 -0
- data/docs/SearchRecordingGranularDTO.md +22 -0
- data/docs/SignUpDTO.md +24 -0
- data/docs/TagDTO.md +22 -0
- data/docs/TagSmallDTO.md +20 -0
- data/docs/TaggramDTO.md +26 -0
- data/docs/TagsSummaryDTO.md +22 -0
- data/docs/TagstrengthDTO.md +26 -0
- data/docs/TitleDTO.md +18 -0
- data/docs/TokenRequest.md +18 -0
- data/docs/TrackToMediumProductDTO.md +22 -0
- data/docs/UpdatePasswordDTO.md +20 -0
- data/docs/UsageDTO.md +18 -0
- data/docs/UserApi.md +1936 -0
- data/docs/UserDTO.md +56 -0
- data/git_push.sh +57 -0
- data/lib/musicube_api_client_ruby/api/allowed_values_api.rb +213 -0
- data/lib/musicube_api_client_ruby/api/party_api.rb +84 -0
- data/lib/musicube_api_client_ruby/api/playlist_api.rb +222 -0
- data/lib/musicube_api_client_ruby/api/recording_api.rb +900 -0
- data/lib/musicube_api_client_ruby/api/user_api.rb +2642 -0
- data/lib/musicube_api_client_ruby/api_client.rb +428 -0
- data/lib/musicube_api_client_ruby/api_error.rb +58 -0
- data/lib/musicube_api_client_ruby/configuration.rb +380 -0
- data/lib/musicube_api_client_ruby/models/category_medium_dto.rb +250 -0
- data/lib/musicube_api_client_ruby/models/category_minimal_dto.rb +225 -0
- data/lib/musicube_api_client_ruby/models/config_access_dto.rb +287 -0
- data/lib/musicube_api_client_ruby/models/config_identifier_dto.rb +239 -0
- data/lib/musicube_api_client_ruby/models/contributor_type_dto.rb +225 -0
- data/lib/musicube_api_client_ruby/models/error_response.rb +276 -0
- data/lib/musicube_api_client_ruby/models/field_summary_dto.rb +253 -0
- data/lib/musicube_api_client_ruby/models/file_dto.rb +450 -0
- data/lib/musicube_api_client_ruby/models/file_list_dto.rb +269 -0
- data/lib/musicube_api_client_ruby/models/file_minimal_with_url_dto.rb +253 -0
- data/lib/musicube_api_client_ruby/models/file_small_dto.rb +432 -0
- data/lib/musicube_api_client_ruby/models/file_upload_dto.rb +244 -0
- data/lib/musicube_api_client_ruby/models/file_w_ith_url_dto.rb +239 -0
- data/lib/musicube_api_client_ruby/models/files_summary_dto.rb +287 -0
- data/lib/musicube_api_client_ruby/models/forgot_password_dto.rb +267 -0
- data/lib/musicube_api_client_ruby/models/genre_dto.rb +239 -0
- data/lib/musicube_api_client_ruby/models/genre_minimal_dto.rb +225 -0
- data/lib/musicube_api_client_ruby/models/genres_summary_dto.rb +248 -0
- data/lib/musicube_api_client_ruby/models/init_put_recording_audio_dto.rb +238 -0
- data/lib/musicube_api_client_ruby/models/jwt_token_dto.rb +248 -0
- data/lib/musicube_api_client_ruby/models/login_dto.rb +257 -0
- data/lib/musicube_api_client_ruby/models/musical_features_dto.rb +1532 -0
- data/lib/musicube_api_client_ruby/models/p_line_dto.rb +234 -0
- data/lib/musicube_api_client_ruby/models/party_large_dto.rb +288 -0
- data/lib/musicube_api_client_ruby/models/party_small_dto.rb +239 -0
- data/lib/musicube_api_client_ruby/models/playlist_large_dto.rb +353 -0
- data/lib/musicube_api_client_ruby/models/product_medium_dto.rb +316 -0
- data/lib/musicube_api_client_ruby/models/product_party_dto.rb +236 -0
- data/lib/musicube_api_client_ruby/models/recording_for_similarity_search_dto.rb +239 -0
- data/lib/musicube_api_client_ruby/models/recording_genre_prediction_dto.rb +253 -0
- data/lib/musicube_api_client_ruby/models/recording_large_dto.rb +366 -0
- data/lib/musicube_api_client_ruby/models/recording_list_dto.rb +269 -0
- data/lib/musicube_api_client_ruby/models/recording_medium_dto.rb +340 -0
- data/lib/musicube_api_client_ruby/models/recording_minimal_with_musical_features_dto.rb +236 -0
- data/lib/musicube_api_client_ruby/models/recording_minimal_with_taggrams_dto.rb +248 -0
- data/lib/musicube_api_client_ruby/models/recording_minimal_with_tagstrengths_dto.rb +236 -0
- data/lib/musicube_api_client_ruby/models/recording_party_dto.rb +236 -0
- data/lib/musicube_api_client_ruby/models/recording_playlist_dto.rb +247 -0
- data/lib/musicube_api_client_ruby/models/recording_small_dto.rb +268 -0
- data/lib/musicube_api_client_ruby/models/recording_tag_small_dto.rb +225 -0
- data/lib/musicube_api_client_ruby/models/save_file_recording_dto.rb +1847 -0
- data/lib/musicube_api_client_ruby/models/save_playlist_dto.rb +350 -0
- data/lib/musicube_api_client_ruby/models/save_recording_genre_dto.rb +243 -0
- data/lib/musicube_api_client_ruby/models/save_recording_party_dto.rb +273 -0
- data/lib/musicube_api_client_ruby/models/save_recording_playlist_dto.rb +248 -0
- data/lib/musicube_api_client_ruby/models/save_recording_tag_dto.rb +234 -0
- data/lib/musicube_api_client_ruby/models/save_referrer_dto.rb +229 -0
- data/lib/musicube_api_client_ruby/models/save_taggrams_dto.rb +574 -0
- data/lib/musicube_api_client_ruby/models/save_user_dto.rb +317 -0
- data/lib/musicube_api_client_ruby/models/search_filter_values_dto.rb +867 -0
- data/lib/musicube_api_client_ruby/models/search_recording_granular_abstraction_dto.rb +270 -0
- data/lib/musicube_api_client_ruby/models/search_recording_granular_dto.rb +245 -0
- data/lib/musicube_api_client_ruby/models/sign_up_dto.rb +262 -0
- data/lib/musicube_api_client_ruby/models/tag_dto.rb +250 -0
- data/lib/musicube_api_client_ruby/models/tag_small_dto.rb +239 -0
- data/lib/musicube_api_client_ruby/models/taggram_dto.rb +271 -0
- data/lib/musicube_api_client_ruby/models/tags_summary_dto.rb +250 -0
- data/lib/musicube_api_client_ruby/models/tagstrength_dto.rb +269 -0
- data/lib/musicube_api_client_ruby/models/title_dto.rb +225 -0
- data/lib/musicube_api_client_ruby/models/token_request.rb +224 -0
- data/lib/musicube_api_client_ruby/models/track_to_medium_product_dto.rb +248 -0
- data/lib/musicube_api_client_ruby/models/update_password_dto.rb +238 -0
- data/lib/musicube_api_client_ruby/models/usage_dto.rb +220 -0
- data/lib/musicube_api_client_ruby/models/user_dto.rb +481 -0
- data/lib/musicube_api_client_ruby/version.rb +15 -0
- data/lib/musicube_api_client_ruby.rb +108 -0
- data/musicube_api_client_ruby.gemspec +39 -0
- data/openapi-generator-config.yaml +9 -0
- data/spec/api/allowed_values_api_spec.rb +68 -0
- data/spec/api/party_api_spec.rb +46 -0
- data/spec/api/playlist_api_spec.rb +72 -0
- data/spec/api/recording_api_spec.rb +192 -0
- data/spec/api/user_api_spec.rb +507 -0
- data/spec/api_client_spec.rb +223 -0
- data/spec/configuration_spec.rb +82 -0
- data/spec/models/category_medium_dto_spec.rb +46 -0
- data/spec/models/category_minimal_dto_spec.rb +34 -0
- data/spec/models/config_access_dto_spec.rb +48 -0
- data/spec/models/config_identifier_dto_spec.rb +40 -0
- data/spec/models/contributor_type_dto_spec.rb +34 -0
- data/spec/models/error_response_spec.rb +58 -0
- data/spec/models/field_summary_dto_spec.rb +46 -0
- data/spec/models/file_dto_spec.rb +142 -0
- data/spec/models/file_list_dto_spec.rb +52 -0
- data/spec/models/file_minimal_with_url_dto_spec.rb +46 -0
- data/spec/models/file_small_dto_spec.rb +130 -0
- data/spec/models/file_upload_dto_spec.rb +46 -0
- data/spec/models/file_w_ith_url_dto_spec.rb +40 -0
- data/spec/models/files_summary_dto_spec.rb +70 -0
- data/spec/models/forgot_password_dto_spec.rb +44 -0
- data/spec/models/genre_dto_spec.rb +40 -0
- data/spec/models/genre_minimal_dto_spec.rb +34 -0
- data/spec/models/genres_summary_dto_spec.rb +46 -0
- data/spec/models/init_put_recording_audio_dto_spec.rb +46 -0
- data/spec/models/jwt_token_dto_spec.rb +46 -0
- data/spec/models/login_dto_spec.rb +52 -0
- data/spec/models/musical_features_dto_spec.rb +706 -0
- data/spec/models/p_line_dto_spec.rb +40 -0
- data/spec/models/party_large_dto_spec.rb +76 -0
- data/spec/models/party_small_dto_spec.rb +40 -0
- data/spec/models/playlist_large_dto_spec.rb +98 -0
- data/spec/models/product_medium_dto_spec.rb +82 -0
- data/spec/models/product_party_dto_spec.rb +40 -0
- data/spec/models/recording_for_similarity_search_dto_spec.rb +40 -0
- data/spec/models/recording_genre_prediction_dto_spec.rb +46 -0
- data/spec/models/recording_large_dto_spec.rb +100 -0
- data/spec/models/recording_list_dto_spec.rb +52 -0
- data/spec/models/recording_medium_dto_spec.rb +88 -0
- data/spec/models/recording_minimal_with_musical_features_dto_spec.rb +40 -0
- data/spec/models/recording_minimal_with_taggrams_dto_spec.rb +46 -0
- data/spec/models/recording_minimal_with_tagstrengths_dto_spec.rb +40 -0
- data/spec/models/recording_party_dto_spec.rb +40 -0
- data/spec/models/recording_playlist_dto_spec.rb +52 -0
- data/spec/models/recording_small_dto_spec.rb +52 -0
- data/spec/models/recording_tag_small_dto_spec.rb +34 -0
- data/spec/models/save_file_recording_dto_spec.rb +880 -0
- data/spec/models/save_playlist_dto_spec.rb +86 -0
- data/spec/models/save_recording_genre_dto_spec.rb +46 -0
- data/spec/models/save_recording_party_dto_spec.rb +44 -0
- data/spec/models/save_recording_playlist_dto_spec.rb +46 -0
- data/spec/models/save_recording_tag_dto_spec.rb +40 -0
- data/spec/models/save_referrer_dto_spec.rb +40 -0
- data/spec/models/save_taggrams_dto_spec.rb +226 -0
- data/spec/models/save_user_dto_spec.rb +72 -0
- data/spec/models/search_filter_values_dto_spec.rb +274 -0
- data/spec/models/search_recording_granular_abstraction_dto_spec.rb +44 -0
- data/spec/models/search_recording_granular_dto_spec.rb +46 -0
- data/spec/models/sign_up_dto_spec.rb +52 -0
- data/spec/models/tag_dto_spec.rb +46 -0
- data/spec/models/tag_small_dto_spec.rb +40 -0
- data/spec/models/taggram_dto_spec.rb +58 -0
- data/spec/models/tags_summary_dto_spec.rb +46 -0
- data/spec/models/tagstrength_dto_spec.rb +58 -0
- data/spec/models/title_dto_spec.rb +34 -0
- data/spec/models/token_request_spec.rb +34 -0
- data/spec/models/track_to_medium_product_dto_spec.rb +46 -0
- data/spec/models/update_password_dto_spec.rb +40 -0
- data/spec/models/usage_dto_spec.rb +34 -0
- data/spec/models/user_dto_spec.rb +148 -0
- data/spec/musicube_api_client_ruby_spec.rb +11 -0
- data/spec/spec_helper.rb +111 -0
- metadata +415 -0
@@ -0,0 +1,428 @@
|
|
1
|
+
=begin
|
2
|
+
#Songtradr API
|
3
|
+
|
4
|
+
#This is the Songtradr API. Use it to retrieve deep music metadata and trigger processes like auto-tagging. You can also use the API to manage your account and musicube cloud data. **Authentication** 1. Reach out to support@songtradr.com to receive a free account or use your login data if you are already signed up. 2. To authenticate, you need to login via the POST /api/v1/user/login endpoint. 3. The endpoint responds with a jwtToken which you can use in all following API requests as a bearer token. **Rate Limiting** The current limit is 120 Requests per minute. Reach out to us via support@songtradr.com if you need to request more. **Getting Started with auto-tagging** 1. If you want to get your own files auto-tagged, use the POST /api/v1/user/file/{name}/initUpload endpoint. It responds with a presigned S3 link where you can upload your file. 2. You can check the processing status of your file via the GET /api/v1/user/file/{name}/filesStatus endpoint. 3. As soon as processing is done, you can request the generated data via the GET /api/v1/user/files endpoint. **Getting Started with search** You can either search the released music via the /public/recording endpoints or your own private uploaded music via the /user/file/ endpoints. 1. If you want to search the world's released music, a good starting point is the GET /api/v1/public/recording/search endpoint. Please find the extensive list of parameters that serve as semantic search filters. 2. If you want to search your own previously uploaded music, a good starting point is the GET GET /api/v1/user/files endpoint. It has the same extensive list of parameters that serve as semantic search filters.
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 1.12.21
|
7
|
+
Contact: info@songtradr.com
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 6.6.0
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'date'
|
14
|
+
require 'json'
|
15
|
+
require 'logger'
|
16
|
+
require 'tempfile'
|
17
|
+
require 'time'
|
18
|
+
require 'faraday'
|
19
|
+
require 'faraday/multipart' if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
|
20
|
+
|
21
|
+
module MusicubeApiClientRuby
|
22
|
+
class ApiClient
|
23
|
+
# The Configuration object holding settings to be used in the API client.
|
24
|
+
attr_accessor :config
|
25
|
+
|
26
|
+
# Defines the headers to be used in HTTP requests of all API calls by default.
|
27
|
+
#
|
28
|
+
# @return [Hash]
|
29
|
+
attr_accessor :default_headers
|
30
|
+
|
31
|
+
# Initializes the ApiClient
|
32
|
+
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
|
33
|
+
def initialize(config = Configuration.default)
|
34
|
+
@config = config
|
35
|
+
@user_agent = "OpenAPI-Generator/#{VERSION}/ruby"
|
36
|
+
@default_headers = {
|
37
|
+
'Content-Type' => 'application/json',
|
38
|
+
'User-Agent' => @user_agent
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.default
|
43
|
+
@@default ||= ApiClient.new
|
44
|
+
end
|
45
|
+
|
46
|
+
# Call an API with given options.
|
47
|
+
#
|
48
|
+
# @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
|
49
|
+
# the data deserialized from response body (could be nil), response status code and response headers.
|
50
|
+
def call_api(http_method, path, opts = {})
|
51
|
+
begin
|
52
|
+
response = connection(opts).public_send(http_method.to_sym.downcase) do |req|
|
53
|
+
build_request(http_method, path, req, opts)
|
54
|
+
end
|
55
|
+
|
56
|
+
if config.debugging
|
57
|
+
config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
58
|
+
end
|
59
|
+
|
60
|
+
unless response.success?
|
61
|
+
if response.status == 0 && response.respond_to?(:return_message)
|
62
|
+
# Errors from libcurl will be made visible here
|
63
|
+
fail ApiError.new(code: 0,
|
64
|
+
message: response.return_message)
|
65
|
+
else
|
66
|
+
fail ApiError.new(code: response.status,
|
67
|
+
response_headers: response.headers,
|
68
|
+
response_body: response.body),
|
69
|
+
response.reason_phrase
|
70
|
+
end
|
71
|
+
end
|
72
|
+
rescue Faraday::TimeoutError
|
73
|
+
fail ApiError.new('Connection timed out')
|
74
|
+
rescue Faraday::ConnectionFailed
|
75
|
+
fail ApiError.new('Connection failed')
|
76
|
+
end
|
77
|
+
|
78
|
+
if opts[:return_type]
|
79
|
+
data = deserialize(response, opts[:return_type])
|
80
|
+
else
|
81
|
+
data = nil
|
82
|
+
end
|
83
|
+
return data, response.status, response.headers
|
84
|
+
end
|
85
|
+
|
86
|
+
# Builds the HTTP request
|
87
|
+
#
|
88
|
+
# @param [String] http_method HTTP method/verb (e.g. POST)
|
89
|
+
# @param [String] path URL path (e.g. /account/new)
|
90
|
+
# @option opts [Hash] :header_params Header parameters
|
91
|
+
# @option opts [Hash] :query_params Query parameters
|
92
|
+
# @option opts [Hash] :form_params Query parameters
|
93
|
+
# @option opts [Object] :body HTTP body (JSON/XML)
|
94
|
+
# @return [Faraday::Request] A Faraday Request
|
95
|
+
def build_request(http_method, path, request, opts = {})
|
96
|
+
url = build_request_url(path, opts)
|
97
|
+
http_method = http_method.to_sym.downcase
|
98
|
+
|
99
|
+
header_params = @default_headers.merge(opts[:header_params] || {})
|
100
|
+
query_params = opts[:query_params] || {}
|
101
|
+
form_params = opts[:form_params] || {}
|
102
|
+
|
103
|
+
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
104
|
+
|
105
|
+
if [:post, :patch, :put, :delete].include?(http_method)
|
106
|
+
req_body = build_request_body(header_params, form_params, opts[:body])
|
107
|
+
if config.debugging
|
108
|
+
config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
request.headers = header_params
|
112
|
+
request.body = req_body
|
113
|
+
|
114
|
+
# Overload default options only if provided
|
115
|
+
request.options.params_encoder = config.params_encoder if config.params_encoder
|
116
|
+
request.options.timeout = config.timeout if config.timeout
|
117
|
+
|
118
|
+
request.url url
|
119
|
+
request.params = query_params
|
120
|
+
download_file(request) if opts[:return_type] == 'File' || opts[:return_type] == 'Binary'
|
121
|
+
request
|
122
|
+
end
|
123
|
+
|
124
|
+
# Builds the HTTP request body
|
125
|
+
#
|
126
|
+
# @param [Hash] header_params Header parameters
|
127
|
+
# @param [Hash] form_params Query parameters
|
128
|
+
# @param [Object] body HTTP body (JSON/XML)
|
129
|
+
# @return [String] HTTP body data in the form of string
|
130
|
+
def build_request_body(header_params, form_params, body)
|
131
|
+
# http form
|
132
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded'
|
133
|
+
data = URI.encode_www_form(form_params)
|
134
|
+
elsif header_params['Content-Type'] == 'multipart/form-data'
|
135
|
+
data = {}
|
136
|
+
form_params.each do |key, value|
|
137
|
+
case value
|
138
|
+
when ::File, ::Tempfile
|
139
|
+
# TODO hardcode to application/octet-stream, need better way to detect content type
|
140
|
+
data[key] = Faraday::FilePart.new(value.path, 'application/octet-stream', value.path)
|
141
|
+
when ::Array, nil
|
142
|
+
# let Faraday handle Array and nil parameters
|
143
|
+
data[key] = value
|
144
|
+
else
|
145
|
+
data[key] = value.to_s
|
146
|
+
end
|
147
|
+
end
|
148
|
+
elsif body
|
149
|
+
data = body.is_a?(String) ? body : body.to_json
|
150
|
+
else
|
151
|
+
data = nil
|
152
|
+
end
|
153
|
+
data
|
154
|
+
end
|
155
|
+
|
156
|
+
def download_file(request)
|
157
|
+
@stream = []
|
158
|
+
|
159
|
+
# handle streaming Responses
|
160
|
+
request.options.on_data = Proc.new do |chunk, overall_received_bytes|
|
161
|
+
@stream << chunk
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def connection(opts)
|
166
|
+
opts[:header_params]['Content-Type'] == 'multipart/form-data' ? connection_multipart : connection_regular
|
167
|
+
end
|
168
|
+
|
169
|
+
def connection_multipart
|
170
|
+
@connection_multipart ||= build_connection do |conn|
|
171
|
+
conn.request :multipart
|
172
|
+
conn.request :url_encoded
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def connection_regular
|
177
|
+
@connection_regular ||= build_connection
|
178
|
+
end
|
179
|
+
|
180
|
+
def build_connection
|
181
|
+
Faraday.new(url: config.base_url, ssl: ssl_options, proxy: config.proxy) do |conn|
|
182
|
+
basic_auth(conn)
|
183
|
+
config.configure_middleware(conn)
|
184
|
+
yield(conn) if block_given?
|
185
|
+
conn.adapter(Faraday.default_adapter)
|
186
|
+
config.configure_connection(conn)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def ssl_options
|
191
|
+
{
|
192
|
+
ca_file: config.ssl_ca_file,
|
193
|
+
verify: config.ssl_verify,
|
194
|
+
verify_mode: config.ssl_verify_mode,
|
195
|
+
client_cert: config.ssl_client_cert,
|
196
|
+
client_key: config.ssl_client_key
|
197
|
+
}
|
198
|
+
end
|
199
|
+
|
200
|
+
def basic_auth(conn)
|
201
|
+
if config.username && config.password
|
202
|
+
if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
|
203
|
+
conn.request(:authorization, :basic, config.username, config.password)
|
204
|
+
else
|
205
|
+
conn.request(:basic_auth, config.username, config.password)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
# Check if the given MIME is a JSON MIME.
|
211
|
+
# JSON MIME examples:
|
212
|
+
# application/json
|
213
|
+
# application/json; charset=UTF8
|
214
|
+
# APPLICATION/JSON
|
215
|
+
# */*
|
216
|
+
# @param [String] mime MIME
|
217
|
+
# @return [Boolean] True if the MIME is application/json
|
218
|
+
def json_mime?(mime)
|
219
|
+
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
|
220
|
+
end
|
221
|
+
|
222
|
+
# Deserialize the response to the given return type.
|
223
|
+
#
|
224
|
+
# @param [Response] response HTTP response
|
225
|
+
# @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
|
226
|
+
def deserialize(response, return_type)
|
227
|
+
body = response.body
|
228
|
+
|
229
|
+
# handle file downloading - return the File instance processed in request callbacks
|
230
|
+
# note that response body is empty when the file is written in chunks in request on_body callback
|
231
|
+
if return_type == 'File'
|
232
|
+
if @config.return_binary_data == true
|
233
|
+
# return byte stream
|
234
|
+
encoding = body.encoding
|
235
|
+
return @stream.join.force_encoding(encoding)
|
236
|
+
else
|
237
|
+
# return file instead of binary data
|
238
|
+
content_disposition = response.headers['Content-Disposition']
|
239
|
+
if content_disposition && content_disposition =~ /filename=/i
|
240
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
241
|
+
prefix = sanitize_filename(filename)
|
242
|
+
else
|
243
|
+
prefix = 'download-'
|
244
|
+
end
|
245
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
246
|
+
encoding = body.encoding
|
247
|
+
@tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
248
|
+
@tempfile.write(@stream.join.force_encoding(encoding))
|
249
|
+
@tempfile.close
|
250
|
+
@config.logger.info "Temp file written to #{@tempfile.path}, please copy the file to a proper folder "\
|
251
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
252
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
253
|
+
"explicitly with `tempfile.delete`"
|
254
|
+
return @tempfile
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
return nil if body.nil? || body.empty?
|
259
|
+
|
260
|
+
# return response body directly for String return type
|
261
|
+
return body if return_type == 'String'
|
262
|
+
|
263
|
+
# ensuring a default content type
|
264
|
+
content_type = response.headers['Content-Type'] || 'application/json'
|
265
|
+
|
266
|
+
fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
267
|
+
|
268
|
+
begin
|
269
|
+
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
270
|
+
rescue JSON::ParserError => e
|
271
|
+
if %w(String Date Time).include?(return_type)
|
272
|
+
data = body
|
273
|
+
else
|
274
|
+
raise e
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
convert_to_type data, return_type
|
279
|
+
end
|
280
|
+
|
281
|
+
# Convert data to the given return type.
|
282
|
+
# @param [Object] data Data to be converted
|
283
|
+
# @param [String] return_type Return type
|
284
|
+
# @return [Mixed] Data in a particular type
|
285
|
+
def convert_to_type(data, return_type)
|
286
|
+
return nil if data.nil?
|
287
|
+
case return_type
|
288
|
+
when 'String'
|
289
|
+
data.to_s
|
290
|
+
when 'Integer'
|
291
|
+
data.to_i
|
292
|
+
when 'Float'
|
293
|
+
data.to_f
|
294
|
+
when 'Boolean'
|
295
|
+
data == true
|
296
|
+
when 'Time'
|
297
|
+
# parse date time (expecting ISO 8601 format)
|
298
|
+
Time.parse data
|
299
|
+
when 'Date'
|
300
|
+
# parse date time (expecting ISO 8601 format)
|
301
|
+
Date.parse data
|
302
|
+
when 'Object'
|
303
|
+
# generic object (usually a Hash), return directly
|
304
|
+
data
|
305
|
+
when /\AArray<(.+)>\z/
|
306
|
+
# e.g. Array<Pet>
|
307
|
+
sub_type = $1
|
308
|
+
data.map { |item| convert_to_type(item, sub_type) }
|
309
|
+
when /\AHash\<String, (.+)\>\z/
|
310
|
+
# e.g. Hash<String, Integer>
|
311
|
+
sub_type = $1
|
312
|
+
{}.tap do |hash|
|
313
|
+
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
314
|
+
end
|
315
|
+
else
|
316
|
+
# models (e.g. Pet) or oneOf
|
317
|
+
klass = MusicubeApiClientRuby.const_get(return_type)
|
318
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
# Sanitize filename by removing path.
|
323
|
+
# e.g. ../../sun.gif becomes sun.gif
|
324
|
+
#
|
325
|
+
# @param [String] filename the filename to be sanitized
|
326
|
+
# @return [String] the sanitized filename
|
327
|
+
def sanitize_filename(filename)
|
328
|
+
filename.gsub(/.*[\/\\]/, '')
|
329
|
+
end
|
330
|
+
|
331
|
+
def build_request_url(path, opts = {})
|
332
|
+
# Add leading and trailing slashes to path
|
333
|
+
path = "/#{path}".gsub(/\/+/, '/')
|
334
|
+
@config.base_url(opts[:operation]) + path
|
335
|
+
end
|
336
|
+
|
337
|
+
# Update header and query params based on authentication settings.
|
338
|
+
#
|
339
|
+
# @param [Hash] header_params Header parameters
|
340
|
+
# @param [Hash] query_params Query parameters
|
341
|
+
# @param [String] auth_names Authentication scheme name
|
342
|
+
def update_params_for_auth!(header_params, query_params, auth_names)
|
343
|
+
Array(auth_names).each do |auth_name|
|
344
|
+
auth_setting = @config.auth_settings[auth_name]
|
345
|
+
next unless auth_setting
|
346
|
+
case auth_setting[:in]
|
347
|
+
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
348
|
+
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
349
|
+
else fail ArgumentError, 'Authentication token must be in `query` or `header`'
|
350
|
+
end
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
# Sets user agent in HTTP header
|
355
|
+
#
|
356
|
+
# @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
|
357
|
+
def user_agent=(user_agent)
|
358
|
+
@user_agent = user_agent
|
359
|
+
@default_headers['User-Agent'] = @user_agent
|
360
|
+
end
|
361
|
+
|
362
|
+
# Return Accept header based on an array of accepts provided.
|
363
|
+
# @param [Array] accepts array for Accept
|
364
|
+
# @return [String] the Accept header (e.g. application/json)
|
365
|
+
def select_header_accept(accepts)
|
366
|
+
return nil if accepts.nil? || accepts.empty?
|
367
|
+
# use JSON when present, otherwise use all of the provided
|
368
|
+
json_accept = accepts.find { |s| json_mime?(s) }
|
369
|
+
json_accept || accepts.join(',')
|
370
|
+
end
|
371
|
+
|
372
|
+
# Return Content-Type header based on an array of content types provided.
|
373
|
+
# @param [Array] content_types array for Content-Type
|
374
|
+
# @return [String] the Content-Type header (e.g. application/json)
|
375
|
+
def select_header_content_type(content_types)
|
376
|
+
# return nil by default
|
377
|
+
return if content_types.nil? || content_types.empty?
|
378
|
+
# use JSON when present, otherwise use the first one
|
379
|
+
json_content_type = content_types.find { |s| json_mime?(s) }
|
380
|
+
json_content_type || content_types.first
|
381
|
+
end
|
382
|
+
|
383
|
+
# Convert object (array, hash, object, etc) to JSON string.
|
384
|
+
# @param [Object] model object to be converted into JSON string
|
385
|
+
# @return [String] JSON string representation of the object
|
386
|
+
def object_to_http_body(model)
|
387
|
+
return model if model.nil? || model.is_a?(String)
|
388
|
+
local_body = nil
|
389
|
+
if model.is_a?(Array)
|
390
|
+
local_body = model.map { |m| object_to_hash(m) }
|
391
|
+
else
|
392
|
+
local_body = object_to_hash(model)
|
393
|
+
end
|
394
|
+
local_body.to_json
|
395
|
+
end
|
396
|
+
|
397
|
+
# Convert object(non-array) to hash.
|
398
|
+
# @param [Object] obj object to be converted into JSON string
|
399
|
+
# @return [String] JSON string representation of the object
|
400
|
+
def object_to_hash(obj)
|
401
|
+
if obj.respond_to?(:to_hash)
|
402
|
+
obj.to_hash
|
403
|
+
else
|
404
|
+
obj
|
405
|
+
end
|
406
|
+
end
|
407
|
+
|
408
|
+
# Build parameter value according to the given collection format.
|
409
|
+
# @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
|
410
|
+
def build_collection_param(param, collection_format)
|
411
|
+
case collection_format
|
412
|
+
when :csv
|
413
|
+
param.join(',')
|
414
|
+
when :ssv
|
415
|
+
param.join(' ')
|
416
|
+
when :tsv
|
417
|
+
param.join("\t")
|
418
|
+
when :pipes
|
419
|
+
param.join('|')
|
420
|
+
when :multi
|
421
|
+
# return the array directly as typhoeus will handle it as expected
|
422
|
+
param
|
423
|
+
else
|
424
|
+
fail "unknown collection format: #{collection_format.inspect}"
|
425
|
+
end
|
426
|
+
end
|
427
|
+
end
|
428
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
=begin
|
2
|
+
#Songtradr API
|
3
|
+
|
4
|
+
#This is the Songtradr API. Use it to retrieve deep music metadata and trigger processes like auto-tagging. You can also use the API to manage your account and musicube cloud data. **Authentication** 1. Reach out to support@songtradr.com to receive a free account or use your login data if you are already signed up. 2. To authenticate, you need to login via the POST /api/v1/user/login endpoint. 3. The endpoint responds with a jwtToken which you can use in all following API requests as a bearer token. **Rate Limiting** The current limit is 120 Requests per minute. Reach out to us via support@songtradr.com if you need to request more. **Getting Started with auto-tagging** 1. If you want to get your own files auto-tagged, use the POST /api/v1/user/file/{name}/initUpload endpoint. It responds with a presigned S3 link where you can upload your file. 2. You can check the processing status of your file via the GET /api/v1/user/file/{name}/filesStatus endpoint. 3. As soon as processing is done, you can request the generated data via the GET /api/v1/user/files endpoint. **Getting Started with search** You can either search the released music via the /public/recording endpoints or your own private uploaded music via the /user/file/ endpoints. 1. If you want to search the world's released music, a good starting point is the GET /api/v1/public/recording/search endpoint. Please find the extensive list of parameters that serve as semantic search filters. 2. If you want to search your own previously uploaded music, a good starting point is the GET GET /api/v1/user/files endpoint. It has the same extensive list of parameters that serve as semantic search filters.
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 1.12.21
|
7
|
+
Contact: info@songtradr.com
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 6.6.0
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
module MusicubeApiClientRuby
|
14
|
+
class ApiError < StandardError
|
15
|
+
attr_reader :code, :response_headers, :response_body
|
16
|
+
|
17
|
+
# Usage examples:
|
18
|
+
# ApiError.new
|
19
|
+
# ApiError.new("message")
|
20
|
+
# ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
|
21
|
+
# ApiError.new(:code => 404, :message => "Not Found")
|
22
|
+
def initialize(arg = nil)
|
23
|
+
if arg.is_a? Hash
|
24
|
+
if arg.key?(:message) || arg.key?('message')
|
25
|
+
super(arg[:message] || arg['message'])
|
26
|
+
else
|
27
|
+
super arg
|
28
|
+
end
|
29
|
+
|
30
|
+
arg.each do |k, v|
|
31
|
+
instance_variable_set "@#{k}", v
|
32
|
+
end
|
33
|
+
else
|
34
|
+
super arg
|
35
|
+
@message = arg
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Override to_s to display a friendly error message
|
40
|
+
def to_s
|
41
|
+
message
|
42
|
+
end
|
43
|
+
|
44
|
+
def message
|
45
|
+
if @message.nil?
|
46
|
+
msg = "Error message: the server returns an error"
|
47
|
+
else
|
48
|
+
msg = @message
|
49
|
+
end
|
50
|
+
|
51
|
+
msg += "\nHTTP status code: #{code}" if code
|
52
|
+
msg += "\nResponse headers: #{response_headers}" if response_headers
|
53
|
+
msg += "\nResponse body: #{response_body}" if response_body
|
54
|
+
|
55
|
+
msg
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|