mux_ruby 1.0.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.
- checksums.yaml +7 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +79 -0
- data/LICENSE +7 -0
- data/README.md +121 -0
- data/Rakefile +10 -0
- data/docs/AbridgedVideoView.md +18 -0
- data/docs/Asset.md +27 -0
- data/docs/AssetErrors.md +9 -0
- data/docs/AssetMaster.md +9 -0
- data/docs/AssetResponse.md +8 -0
- data/docs/AssetStaticRenditions.md +9 -0
- data/docs/AssetStaticRenditionsFiles.md +13 -0
- data/docs/AssetsApi.md +476 -0
- data/docs/BreakdownValue.md +12 -0
- data/docs/CreateAssetRequest.md +13 -0
- data/docs/CreateLiveStreamRequest.md +9 -0
- data/docs/CreatePlaybackIDRequest.md +8 -0
- data/docs/CreatePlaybackIDResponse.md +8 -0
- data/docs/CreateUploadRequest.md +10 -0
- data/docs/DirectUploadsApi.md +214 -0
- data/docs/Error.md +15 -0
- data/docs/ErrorsApi.md +64 -0
- data/docs/ExportsApi.md +56 -0
- data/docs/FilterValue.md +9 -0
- data/docs/FiltersApi.md +118 -0
- data/docs/GetAssetInputInfoResponse.md +8 -0
- data/docs/GetAssetPlaybackIDResponse.md +8 -0
- data/docs/GetMetricTimeseriesDataResponse.md +10 -0
- data/docs/GetOverallValuesResponse.md +10 -0
- data/docs/InputFile.md +9 -0
- data/docs/InputInfo.md +9 -0
- data/docs/InputSettings.md +10 -0
- data/docs/InputSettingsOverlaySettings.md +14 -0
- data/docs/InputTrack.md +18 -0
- data/docs/Insight.md +13 -0
- data/docs/ListAllMetricValuesResponse.md +10 -0
- data/docs/ListAssetsResponse.md +8 -0
- data/docs/ListBreakdownValuesResponse.md +10 -0
- data/docs/ListErrorsResponse.md +10 -0
- data/docs/ListExportsResponse.md +10 -0
- data/docs/ListFilterValuesResponse.md +10 -0
- data/docs/ListFiltersResponse.md +10 -0
- data/docs/ListFiltersResponseData.md +9 -0
- data/docs/ListInsightsResponse.md +10 -0
- data/docs/ListLiveStreamsResponse.md +8 -0
- data/docs/ListSigningKeysResponse.md +8 -0
- data/docs/ListUploadsResponse.md +8 -0
- data/docs/ListVideoViewsResponse.md +10 -0
- data/docs/LiveStream.md +17 -0
- data/docs/LiveStreamResponse.md +8 -0
- data/docs/LiveStreamsApi.md +420 -0
- data/docs/Metric.md +12 -0
- data/docs/MetricsApi.md +322 -0
- data/docs/OverallValues.md +11 -0
- data/docs/PlaybackID.md +9 -0
- data/docs/PlaybackPolicy.md +7 -0
- data/docs/Score.md +13 -0
- data/docs/SignalLiveStreamCompleteResponse.md +8 -0
- data/docs/SigningKey.md +10 -0
- data/docs/SigningKeyResponse.md +8 -0
- data/docs/Track.md +17 -0
- data/docs/URLSigningKeysApi.md +215 -0
- data/docs/UpdateAssetMP4SupportRequest.md +8 -0
- data/docs/Upload.md +15 -0
- data/docs/UploadError.md +9 -0
- data/docs/UploadResponse.md +8 -0
- data/docs/VideoView.md +117 -0
- data/docs/VideoViewEvent.md +11 -0
- data/docs/VideoViewResponse.md +9 -0
- data/docs/VideoViewsApi.md +126 -0
- data/examples/data/exercise-errors.rb +23 -0
- data/examples/data/exercise-exports.rb +22 -0
- data/examples/data/exercise-filters.rb +29 -0
- data/examples/data/exercise-metrics.rb +52 -0
- data/examples/data/exercise-video-views.rb +30 -0
- data/examples/video/create-live-stream.rb +25 -0
- data/examples/video/exercise-assets.rb +95 -0
- data/examples/video/exercise-live-streams.rb +89 -0
- data/examples/video/exercise-signing-keys.rb +46 -0
- data/examples/video/exercise-uploads.rb +49 -0
- data/examples/video/ingest.rb +37 -0
- data/examples/video/list-everything.rb +48 -0
- data/github-ruby-sdk.png +0 -0
- data/lib/mux_ruby/api/assets_api.rb +507 -0
- data/lib/mux_ruby/api/direct_uploads_api.rb +224 -0
- data/lib/mux_ruby/api/errors_api.rb +69 -0
- data/lib/mux_ruby/api/exports_api.rb +63 -0
- data/lib/mux_ruby/api/filters_api.rb +128 -0
- data/lib/mux_ruby/api/live_streams_api.rb +440 -0
- data/lib/mux_ruby/api/metrics_api.rb +393 -0
- data/lib/mux_ruby/api/url_signing_keys_api.rb +219 -0
- data/lib/mux_ruby/api/video_views_api.rb +140 -0
- data/lib/mux_ruby/api_client.rb +400 -0
- data/lib/mux_ruby/api_error.rb +44 -0
- data/lib/mux_ruby/configuration.rb +244 -0
- data/lib/mux_ruby/models/abridged_video_view.rb +274 -0
- data/lib/mux_ruby/models/asset.rb +409 -0
- data/lib/mux_ruby/models/asset_errors.rb +195 -0
- data/lib/mux_ruby/models/asset_master.rb +193 -0
- data/lib/mux_ruby/models/asset_response.rb +184 -0
- data/lib/mux_ruby/models/asset_static_renditions.rb +232 -0
- data/lib/mux_ruby/models/asset_static_renditions_files.rb +279 -0
- data/lib/mux_ruby/models/breakdown_value.rb +220 -0
- data/lib/mux_ruby/models/create_asset_request.rb +267 -0
- data/lib/mux_ruby/models/create_live_stream_request.rb +195 -0
- data/lib/mux_ruby/models/create_playback_id_request.rb +184 -0
- data/lib/mux_ruby/models/create_playback_id_response.rb +184 -0
- data/lib/mux_ruby/models/create_upload_request.rb +235 -0
- data/lib/mux_ruby/models/error.rb +247 -0
- data/lib/mux_ruby/models/filter_value.rb +193 -0
- data/lib/mux_ruby/models/get_asset_input_info_response.rb +186 -0
- data/lib/mux_ruby/models/get_asset_playback_id_response.rb +184 -0
- data/lib/mux_ruby/models/get_metric_timeseries_data_response.rb +206 -0
- data/lib/mux_ruby/models/get_overall_values_response.rb +204 -0
- data/lib/mux_ruby/models/input_file.rb +195 -0
- data/lib/mux_ruby/models/input_info.rb +193 -0
- data/lib/mux_ruby/models/input_settings.rb +203 -0
- data/lib/mux_ruby/models/input_settings_overlay_settings.rb +238 -0
- data/lib/mux_ruby/models/input_track.rb +274 -0
- data/lib/mux_ruby/models/insight.rb +229 -0
- data/lib/mux_ruby/models/list_all_metric_values_response.rb +206 -0
- data/lib/mux_ruby/models/list_assets_response.rb +186 -0
- data/lib/mux_ruby/models/list_breakdown_values_response.rb +206 -0
- data/lib/mux_ruby/models/list_errors_response.rb +206 -0
- data/lib/mux_ruby/models/list_exports_response.rb +206 -0
- data/lib/mux_ruby/models/list_filter_values_response.rb +206 -0
- data/lib/mux_ruby/models/list_filters_response.rb +204 -0
- data/lib/mux_ruby/models/list_filters_response_data.rb +197 -0
- data/lib/mux_ruby/models/list_insights_response.rb +206 -0
- data/lib/mux_ruby/models/list_live_streams_response.rb +186 -0
- data/lib/mux_ruby/models/list_signing_keys_response.rb +186 -0
- data/lib/mux_ruby/models/list_uploads_response.rb +186 -0
- data/lib/mux_ruby/models/list_video_views_response.rb +206 -0
- data/lib/mux_ruby/models/live_stream.rb +269 -0
- data/lib/mux_ruby/models/live_stream_response.rb +184 -0
- data/lib/mux_ruby/models/metric.rb +220 -0
- data/lib/mux_ruby/models/overall_values.rb +211 -0
- data/lib/mux_ruby/models/playback_id.rb +193 -0
- data/lib/mux_ruby/models/playback_policy.rb +31 -0
- data/lib/mux_ruby/models/score.rb +231 -0
- data/lib/mux_ruby/models/signal_live_stream_complete_response.rb +184 -0
- data/lib/mux_ruby/models/signing_key.rb +202 -0
- data/lib/mux_ruby/models/signing_key_response.rb +184 -0
- data/lib/mux_ruby/models/track.rb +265 -0
- data/lib/mux_ruby/models/update_asset_mp4_support_request.rb +219 -0
- data/lib/mux_ruby/models/upload.rb +311 -0
- data/lib/mux_ruby/models/upload_error.rb +194 -0
- data/lib/mux_ruby/models/upload_response.rb +184 -0
- data/lib/mux_ruby/models/video_view.rb +1167 -0
- data/lib/mux_ruby/models/video_view_event.rb +211 -0
- data/lib/mux_ruby/models/video_view_response.rb +195 -0
- data/lib/mux_ruby/version.rb +8 -0
- data/lib/mux_ruby.rb +97 -0
- data/mux_ruby.gemspec +38 -0
- data/spec/api/assets_api_spec.rb +136 -0
- data/spec/api/direct_uploads_api_spec.rb +74 -0
- data/spec/api/errors_api_spec.rb +41 -0
- data/spec/api/exports_api_spec.rb +39 -0
- data/spec/api/filters_api_spec.rb +55 -0
- data/spec/api/live_streams_api_spec.rb +122 -0
- data/spec/api/metrics_api_spec.rb +110 -0
- data/spec/api/url_signing_keys_api_spec.rb +76 -0
- data/spec/api/video_views_api_spec.rb +58 -0
- data/spec/api_client_spec.rb +219 -0
- data/spec/configuration_spec.rb +35 -0
- data/spec/models/abridged_video_view_spec.rb +94 -0
- data/spec/models/asset_errors_spec.rb +40 -0
- data/spec/models/asset_master_spec.rb +40 -0
- data/spec/models/asset_response_spec.rb +34 -0
- data/spec/models/asset_spec.rb +156 -0
- data/spec/models/asset_static_renditions_files_spec.rb +72 -0
- data/spec/models/asset_static_renditions_spec.rb +44 -0
- data/spec/models/breakdown_value_spec.rb +58 -0
- data/spec/models/create_asset_request_spec.rb +68 -0
- data/spec/models/create_live_stream_request_spec.rb +40 -0
- data/spec/models/create_playback_id_request_spec.rb +34 -0
- data/spec/models/create_playback_id_response_spec.rb +34 -0
- data/spec/models/create_upload_request_spec.rb +46 -0
- data/spec/models/error_spec.rb +76 -0
- data/spec/models/filter_value_spec.rb +40 -0
- data/spec/models/get_asset_input_info_response_spec.rb +34 -0
- data/spec/models/get_asset_playback_id_response_spec.rb +34 -0
- data/spec/models/get_metric_timeseries_data_response_spec.rb +46 -0
- data/spec/models/get_overall_values_response_spec.rb +46 -0
- data/spec/models/input_file_spec.rb +40 -0
- data/spec/models/input_info_spec.rb +40 -0
- data/spec/models/input_settings_overlay_settings_spec.rb +70 -0
- data/spec/models/input_settings_spec.rb +46 -0
- data/spec/models/input_track_spec.rb +94 -0
- data/spec/models/insight_spec.rb +64 -0
- data/spec/models/list_all_metric_values_response_spec.rb +46 -0
- data/spec/models/list_assets_response_spec.rb +34 -0
- data/spec/models/list_breakdown_values_response_spec.rb +46 -0
- data/spec/models/list_errors_response_spec.rb +46 -0
- data/spec/models/list_exports_response_spec.rb +46 -0
- data/spec/models/list_filter_values_response_spec.rb +46 -0
- data/spec/models/list_filters_response_data_spec.rb +40 -0
- data/spec/models/list_filters_response_spec.rb +46 -0
- data/spec/models/list_insights_response_spec.rb +46 -0
- data/spec/models/list_live_streams_response_spec.rb +34 -0
- data/spec/models/list_signing_keys_response_spec.rb +34 -0
- data/spec/models/list_uploads_response_spec.rb +34 -0
- data/spec/models/list_video_views_response_spec.rb +46 -0
- data/spec/models/live_stream_response_spec.rb +34 -0
- data/spec/models/live_stream_spec.rb +88 -0
- data/spec/models/metric_spec.rb +58 -0
- data/spec/models/overall_values_spec.rb +52 -0
- data/spec/models/playback_id_spec.rb +40 -0
- data/spec/models/playback_policy_spec.rb +28 -0
- data/spec/models/score_spec.rb +64 -0
- data/spec/models/signal_live_stream_complete_response_spec.rb +34 -0
- data/spec/models/signing_key_response_spec.rb +34 -0
- data/spec/models/signing_key_spec.rb +46 -0
- data/spec/models/track_spec.rb +88 -0
- data/spec/models/update_asset_mp4_support_request_spec.rb +38 -0
- data/spec/models/upload_error_spec.rb +40 -0
- data/spec/models/upload_response_spec.rb +34 -0
- data/spec/models/upload_spec.rb +80 -0
- data/spec/models/video_view_event_spec.rb +52 -0
- data/spec/models/video_view_response_spec.rb +40 -0
- data/spec/models/video_view_spec.rb +688 -0
- data/spec/spec_helper.rb +104 -0
- metadata +514 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
# Mux Ruby - Copyright 2019 Mux Inc.
|
|
3
|
+
# NOTE: This file is auto generated. Do not edit this file manually.
|
|
4
|
+
=end
|
|
5
|
+
|
|
6
|
+
require 'uri'
|
|
7
|
+
|
|
8
|
+
module MuxRuby
|
|
9
|
+
class VideoViewsApi
|
|
10
|
+
attr_accessor :api_client
|
|
11
|
+
|
|
12
|
+
def initialize(api_client = ApiClient.default)
|
|
13
|
+
@api_client = api_client
|
|
14
|
+
end
|
|
15
|
+
# Get a Video View
|
|
16
|
+
# Returns the details of a video view
|
|
17
|
+
# @param video_view_id ID of the Video View
|
|
18
|
+
# @param [Hash] opts the optional parameters
|
|
19
|
+
# @return [VideoViewResponse]
|
|
20
|
+
def get_video_view(video_view_id, opts = {})
|
|
21
|
+
data, _status_code, _headers = get_video_view_with_http_info(video_view_id, opts)
|
|
22
|
+
data
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Get a Video View
|
|
26
|
+
# Returns the details of a video view
|
|
27
|
+
# @param video_view_id ID of the Video View
|
|
28
|
+
# @param [Hash] opts the optional parameters
|
|
29
|
+
# @return [Array<(VideoViewResponse, Fixnum, Hash)>] VideoViewResponse data, response status code and response headers
|
|
30
|
+
def get_video_view_with_http_info(video_view_id, opts = {})
|
|
31
|
+
if @api_client.config.debugging
|
|
32
|
+
@api_client.config.logger.debug 'Calling API: VideoViewsApi.get_video_view ...'
|
|
33
|
+
end
|
|
34
|
+
# verify the required parameter 'video_view_id' is set
|
|
35
|
+
if @api_client.config.client_side_validation && video_view_id.nil?
|
|
36
|
+
fail ArgumentError, "Missing the required parameter 'video_view_id' when calling VideoViewsApi.get_video_view"
|
|
37
|
+
end
|
|
38
|
+
# resource path
|
|
39
|
+
local_var_path = '/data/v1/video-views/{VIDEO_VIEW_ID}'.sub('{' + 'VIDEO_VIEW_ID' + '}', video_view_id.to_s)
|
|
40
|
+
|
|
41
|
+
# query parameters
|
|
42
|
+
query_params = {}
|
|
43
|
+
|
|
44
|
+
# header parameters
|
|
45
|
+
header_params = {}
|
|
46
|
+
# HTTP header 'Accept' (if needed)
|
|
47
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
|
48
|
+
|
|
49
|
+
# form parameters
|
|
50
|
+
form_params = {}
|
|
51
|
+
|
|
52
|
+
# http body (model)
|
|
53
|
+
post_body = nil
|
|
54
|
+
auth_names = ['accessToken']
|
|
55
|
+
data, status_code, headers = @api_client.call_api(:GET, local_var_path,
|
|
56
|
+
:header_params => header_params,
|
|
57
|
+
:query_params => query_params,
|
|
58
|
+
:form_params => form_params,
|
|
59
|
+
:body => post_body,
|
|
60
|
+
:auth_names => auth_names,
|
|
61
|
+
:return_type => 'VideoViewResponse')
|
|
62
|
+
if @api_client.config.debugging
|
|
63
|
+
@api_client.config.logger.debug "API called: VideoViewsApi#get_video_view\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
|
64
|
+
end
|
|
65
|
+
return data, status_code, headers
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# List Video Views
|
|
69
|
+
# Returns a list of video views
|
|
70
|
+
# @param [Hash] opts the optional parameters
|
|
71
|
+
# @option opts [Integer] :limit Number of items to include in the response (default to 25)
|
|
72
|
+
# @option opts [Integer] :page Offset by this many pages, of the size of `limit` (default to 1)
|
|
73
|
+
# @option opts [String] :viewer_id Viewer ID to filter results by. This value may be provided by the integration, or may be created by Mux.
|
|
74
|
+
# @option opts [Integer] :error_id Filter video views by the provided error ID (as returned in the error_type_id field in the list video views endpoint). If you provide any as the error ID, this will filter the results to those with any error.
|
|
75
|
+
# @option opts [String] :order_direction Sort order.
|
|
76
|
+
# @option opts [Array<String>] :filters Filter key:value pairs. Must be provided as an array query string parameter (e.g. filters[]=operating_system:windows&filters[]=country:US). Possible filter names are the same as returned by the List Filters endpoint.
|
|
77
|
+
# @option opts [Array<String>] :timeframe Timeframe window to limit results by. Must be provided as an array query string parameter (e.g. timeframe[]=). Accepted formats are... * array of epoch timestamps e.g. timeframe[]=1498867200&timeframe[]=1498953600 * duration string e.g. timeframe[]=24:hours or timeframe[]=7:days.
|
|
78
|
+
# @return [ListVideoViewsResponse]
|
|
79
|
+
def list_video_views(opts = {})
|
|
80
|
+
data, _status_code, _headers = list_video_views_with_http_info(opts)
|
|
81
|
+
data
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# List Video Views
|
|
85
|
+
# Returns a list of video views
|
|
86
|
+
# @param [Hash] opts the optional parameters
|
|
87
|
+
# @option opts [Integer] :limit Number of items to include in the response
|
|
88
|
+
# @option opts [Integer] :page Offset by this many pages, of the size of `limit`
|
|
89
|
+
# @option opts [String] :viewer_id Viewer ID to filter results by. This value may be provided by the integration, or may be created by Mux.
|
|
90
|
+
# @option opts [Integer] :error_id Filter video views by the provided error ID (as returned in the error_type_id field in the list video views endpoint). If you provide any as the error ID, this will filter the results to those with any error.
|
|
91
|
+
# @option opts [String] :order_direction Sort order.
|
|
92
|
+
# @option opts [Array<String>] :filters Filter key:value pairs. Must be provided as an array query string parameter (e.g. filters[]=operating_system:windows&filters[]=country:US). Possible filter names are the same as returned by the List Filters endpoint.
|
|
93
|
+
# @option opts [Array<String>] :timeframe Timeframe window to limit results by. Must be provided as an array query string parameter (e.g. timeframe[]=). Accepted formats are... * array of epoch timestamps e.g. timeframe[]=1498867200&timeframe[]=1498953600 * duration string e.g. timeframe[]=24:hours or timeframe[]=7:days.
|
|
94
|
+
# @return [Array<(ListVideoViewsResponse, Fixnum, Hash)>] ListVideoViewsResponse data, response status code and response headers
|
|
95
|
+
def list_video_views_with_http_info(opts = {})
|
|
96
|
+
if @api_client.config.debugging
|
|
97
|
+
@api_client.config.logger.debug 'Calling API: VideoViewsApi.list_video_views ...'
|
|
98
|
+
end
|
|
99
|
+
if @api_client.config.client_side_validation && opts[:'order_direction'] && !['asc', 'desc'].include?(opts[:'order_direction'])
|
|
100
|
+
fail ArgumentError, 'invalid value for "order_direction", must be one of asc, desc'
|
|
101
|
+
end
|
|
102
|
+
# resource path
|
|
103
|
+
local_var_path = '/data/v1/video-views'
|
|
104
|
+
|
|
105
|
+
# query parameters
|
|
106
|
+
query_params = {}
|
|
107
|
+
query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
|
|
108
|
+
query_params[:'page'] = opts[:'page'] if !opts[:'page'].nil?
|
|
109
|
+
query_params[:'viewer_id'] = opts[:'viewer_id'] if !opts[:'viewer_id'].nil?
|
|
110
|
+
query_params[:'error_id'] = opts[:'error_id'] if !opts[:'error_id'].nil?
|
|
111
|
+
query_params[:'order_direction'] = opts[:'order_direction'] if !opts[:'order_direction'].nil?
|
|
112
|
+
query_params[:'filters[]'] = @api_client.build_collection_param(opts[:'filters'], :multi) if !opts[:'filters'].nil?
|
|
113
|
+
query_params[:'timeframe[]'] = @api_client.build_collection_param(opts[:'timeframe'], :multi) if !opts[:'timeframe'].nil?
|
|
114
|
+
|
|
115
|
+
# header parameters
|
|
116
|
+
header_params = {}
|
|
117
|
+
# HTTP header 'Accept' (if needed)
|
|
118
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
|
119
|
+
|
|
120
|
+
# form parameters
|
|
121
|
+
form_params = {}
|
|
122
|
+
|
|
123
|
+
# http body (model)
|
|
124
|
+
post_body = nil
|
|
125
|
+
auth_names = ['accessToken']
|
|
126
|
+
data, status_code, headers = @api_client.call_api(:GET, local_var_path,
|
|
127
|
+
:header_params => header_params,
|
|
128
|
+
:query_params => query_params,
|
|
129
|
+
:form_params => form_params,
|
|
130
|
+
:body => post_body,
|
|
131
|
+
:auth_names => auth_names,
|
|
132
|
+
:return_type => 'ListVideoViewsResponse')
|
|
133
|
+
if @api_client.config.debugging
|
|
134
|
+
@api_client.config.logger.debug "API called: VideoViewsApi#list_video_views\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
|
135
|
+
end
|
|
136
|
+
return data, status_code, headers
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
end
|
|
140
|
+
end
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
# Mux Ruby - Copyright 2019 Mux Inc.
|
|
3
|
+
# NOTE: This file is auto generated. Do not edit this file manually.
|
|
4
|
+
=end
|
|
5
|
+
|
|
6
|
+
require 'date'
|
|
7
|
+
require 'json'
|
|
8
|
+
require 'logger'
|
|
9
|
+
require 'tempfile'
|
|
10
|
+
require 'typhoeus'
|
|
11
|
+
require 'uri'
|
|
12
|
+
|
|
13
|
+
module MuxRuby
|
|
14
|
+
class ApiClient
|
|
15
|
+
# The Configuration object holding settings to be used in the API client.
|
|
16
|
+
attr_accessor :config
|
|
17
|
+
|
|
18
|
+
# Defines the headers to be used in HTTP requests of all API calls by default.
|
|
19
|
+
#
|
|
20
|
+
# @return [Hash]
|
|
21
|
+
attr_accessor :default_headers
|
|
22
|
+
|
|
23
|
+
# Initializes the ApiClient
|
|
24
|
+
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
|
|
25
|
+
def initialize(config = Configuration.default)
|
|
26
|
+
@config = config
|
|
27
|
+
@user_agent = "Mux Ruby | #{VERSION}"
|
|
28
|
+
@default_headers = {
|
|
29
|
+
'Content-Type' => 'application/json',
|
|
30
|
+
'User-Agent' => @user_agent
|
|
31
|
+
}
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.default
|
|
35
|
+
@@default ||= ApiClient.new
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Call an API with given options.
|
|
39
|
+
#
|
|
40
|
+
# @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
|
|
41
|
+
# the data deserialized from response body (could be nil), response status code and response headers.
|
|
42
|
+
def call_api(http_method, path, opts = {})
|
|
43
|
+
request = build_request(http_method, path, opts)
|
|
44
|
+
response = request.run
|
|
45
|
+
|
|
46
|
+
if @config.debugging
|
|
47
|
+
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
unless response.success?
|
|
51
|
+
if response.timed_out?
|
|
52
|
+
fail ApiError.new('Connection timed out')
|
|
53
|
+
elsif response.code == 0
|
|
54
|
+
# Errors from libcurl will be made visible here
|
|
55
|
+
fail ApiError.new(:code => 0,
|
|
56
|
+
:message => response.return_message)
|
|
57
|
+
elsif response.code == 401
|
|
58
|
+
fail UnauthorizedError.new(:code => response.code,
|
|
59
|
+
:response_headers => response.headers,
|
|
60
|
+
:response_body => response.body),
|
|
61
|
+
response.status_message
|
|
62
|
+
elsif response.code == 403
|
|
63
|
+
fail ForbiddenError.new(:code => response.code,
|
|
64
|
+
:response_headers => response.headers,
|
|
65
|
+
:response_body => response.body),
|
|
66
|
+
response.status_message
|
|
67
|
+
elsif response.code == 404
|
|
68
|
+
fail NotFoundError.new(:code => response.code,
|
|
69
|
+
:response_headers => response.headers,
|
|
70
|
+
:response_body => response.body),
|
|
71
|
+
response.status_message
|
|
72
|
+
elsif 500 <= response.code <= 599
|
|
73
|
+
fail ServiceError.new(:code => response.code,
|
|
74
|
+
:response_headers => response.headers,
|
|
75
|
+
:response_body => response.body),
|
|
76
|
+
response.status_message
|
|
77
|
+
else
|
|
78
|
+
fail ApiError.new(:code => response.code,
|
|
79
|
+
:response_headers => response.headers,
|
|
80
|
+
:response_body => response.body),
|
|
81
|
+
response.status_message
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
if opts[:return_type]
|
|
86
|
+
data = deserialize(response, opts[:return_type])
|
|
87
|
+
else
|
|
88
|
+
data = nil
|
|
89
|
+
end
|
|
90
|
+
return data, response.code, response.headers
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Builds the HTTP request
|
|
94
|
+
#
|
|
95
|
+
# @param [String] http_method HTTP method/verb (e.g. POST)
|
|
96
|
+
# @param [String] path URL path (e.g. /account/new)
|
|
97
|
+
# @option opts [Hash] :header_params Header parameters
|
|
98
|
+
# @option opts [Hash] :query_params Query parameters
|
|
99
|
+
# @option opts [Hash] :form_params Query parameters
|
|
100
|
+
# @option opts [Object] :body HTTP body (JSON/XML)
|
|
101
|
+
# @return [Typhoeus::Request] A Typhoeus Request
|
|
102
|
+
def build_request(http_method, path, opts = {})
|
|
103
|
+
url = build_request_url(path)
|
|
104
|
+
http_method = http_method.to_sym.downcase
|
|
105
|
+
|
|
106
|
+
header_params = @default_headers.merge(opts[:header_params] || {})
|
|
107
|
+
query_params = opts[:query_params] || {}
|
|
108
|
+
form_params = opts[:form_params] || {}
|
|
109
|
+
|
|
110
|
+
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
|
111
|
+
|
|
112
|
+
# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
|
|
113
|
+
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
|
|
114
|
+
|
|
115
|
+
req_opts = {
|
|
116
|
+
:method => http_method,
|
|
117
|
+
:headers => header_params,
|
|
118
|
+
:params => query_params,
|
|
119
|
+
:params_encoding => :multi,
|
|
120
|
+
:timeout => @config.timeout,
|
|
121
|
+
:ssl_verifypeer => @config.verify_ssl,
|
|
122
|
+
:ssl_verifyhost => _verify_ssl_host,
|
|
123
|
+
:sslcert => @config.cert_file,
|
|
124
|
+
:sslkey => @config.key_file,
|
|
125
|
+
:verbose => @config.debugging
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
# set custom cert, if provided
|
|
129
|
+
req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
|
|
130
|
+
|
|
131
|
+
if [:post, :patch, :put, :delete].include?(http_method)
|
|
132
|
+
req_body = build_request_body(header_params, form_params, opts[:body])
|
|
133
|
+
req_opts.update :body => req_body
|
|
134
|
+
if @config.debugging
|
|
135
|
+
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
request = Typhoeus::Request.new(url, req_opts)
|
|
140
|
+
download_file(request) if opts[:return_type] == 'File'
|
|
141
|
+
request
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# Check if the given MIME is a JSON MIME.
|
|
145
|
+
# JSON MIME examples:
|
|
146
|
+
# application/json
|
|
147
|
+
# application/json; charset=UTF8
|
|
148
|
+
# APPLICATION/JSON
|
|
149
|
+
# */*
|
|
150
|
+
# @param [String] mime MIME
|
|
151
|
+
# @return [Boolean] True if the MIME is application/json
|
|
152
|
+
def json_mime?(mime)
|
|
153
|
+
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# Deserialize the response to the given return type.
|
|
157
|
+
#
|
|
158
|
+
# @param [Response] response HTTP response
|
|
159
|
+
# @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
|
|
160
|
+
def deserialize(response, return_type)
|
|
161
|
+
body = response.body
|
|
162
|
+
|
|
163
|
+
# handle file downloading - return the File instance processed in request callbacks
|
|
164
|
+
# note that response body is empty when the file is written in chunks in request on_body callback
|
|
165
|
+
return @tempfile if return_type == 'File'
|
|
166
|
+
|
|
167
|
+
return nil if body.nil? || body.empty?
|
|
168
|
+
|
|
169
|
+
# return response body directly for String return type
|
|
170
|
+
return body if return_type == 'String'
|
|
171
|
+
|
|
172
|
+
# ensuring a default content type
|
|
173
|
+
content_type = response.headers['Content-Type'] || 'application/json'
|
|
174
|
+
|
|
175
|
+
fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
|
176
|
+
|
|
177
|
+
begin
|
|
178
|
+
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
|
179
|
+
rescue JSON::ParserError => e
|
|
180
|
+
if %w(String Date DateTime).include?(return_type)
|
|
181
|
+
data = body
|
|
182
|
+
else
|
|
183
|
+
raise e
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
convert_to_type data, return_type
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# Convert data to the given return type.
|
|
191
|
+
# @param [Object] data Data to be converted
|
|
192
|
+
# @param [String] return_type Return type
|
|
193
|
+
# @return [Mixed] Data in a particular type
|
|
194
|
+
def convert_to_type(data, return_type)
|
|
195
|
+
return nil if data.nil?
|
|
196
|
+
case return_type
|
|
197
|
+
when 'String'
|
|
198
|
+
data.to_s
|
|
199
|
+
when 'Integer'
|
|
200
|
+
data.to_i
|
|
201
|
+
when 'Float'
|
|
202
|
+
data.to_f
|
|
203
|
+
when 'BOOLEAN'
|
|
204
|
+
data == true
|
|
205
|
+
when 'DateTime'
|
|
206
|
+
# parse date time (expecting ISO 8601 format)
|
|
207
|
+
DateTime.parse data
|
|
208
|
+
when 'Date'
|
|
209
|
+
# parse date time (expecting ISO 8601 format)
|
|
210
|
+
Date.parse data
|
|
211
|
+
when 'Object'
|
|
212
|
+
# generic object (usually a Hash), return directly
|
|
213
|
+
data
|
|
214
|
+
when /\AArray<(.+)>\z/
|
|
215
|
+
# e.g. Array<Pet>
|
|
216
|
+
sub_type = $1
|
|
217
|
+
data.map { |item| convert_to_type(item, sub_type) }
|
|
218
|
+
when /\AHash\<String, (.+)\>\z/
|
|
219
|
+
# e.g. Hash<String, Integer>
|
|
220
|
+
sub_type = $1
|
|
221
|
+
{}.tap do |hash|
|
|
222
|
+
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
|
223
|
+
end
|
|
224
|
+
else
|
|
225
|
+
# models, e.g. Pet
|
|
226
|
+
MuxRuby.const_get(return_type).build_from_hash(data)
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
# Save response body into a file in (the defined) temporary folder, using the filename
|
|
231
|
+
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
|
232
|
+
# The response body is written to the file in chunks in order to handle files which
|
|
233
|
+
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
|
234
|
+
# process can use.
|
|
235
|
+
#
|
|
236
|
+
# @see Configuration#temp_folder_path
|
|
237
|
+
def download_file(request)
|
|
238
|
+
tempfile = nil
|
|
239
|
+
encoding = nil
|
|
240
|
+
request.on_headers do |response|
|
|
241
|
+
content_disposition = response.headers['Content-Disposition']
|
|
242
|
+
if content_disposition && content_disposition =~ /filename=/i
|
|
243
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
|
244
|
+
prefix = sanitize_filename(filename)
|
|
245
|
+
else
|
|
246
|
+
prefix = 'download-'
|
|
247
|
+
end
|
|
248
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
|
249
|
+
encoding = response.body.encoding
|
|
250
|
+
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
|
251
|
+
@tempfile = tempfile
|
|
252
|
+
end
|
|
253
|
+
request.on_body do |chunk|
|
|
254
|
+
chunk.force_encoding(encoding)
|
|
255
|
+
tempfile.write(chunk)
|
|
256
|
+
end
|
|
257
|
+
request.on_complete do |response|
|
|
258
|
+
tempfile.close if tempfile
|
|
259
|
+
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
|
260
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
|
261
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
|
262
|
+
"explicitly with `tempfile.delete`"
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
# Sanitize filename by removing path.
|
|
267
|
+
# e.g. ../../sun.gif becomes sun.gif
|
|
268
|
+
#
|
|
269
|
+
# @param [String] filename the filename to be sanitized
|
|
270
|
+
# @return [String] the sanitized filename
|
|
271
|
+
def sanitize_filename(filename)
|
|
272
|
+
filename.gsub(/.*[\/\\]/, '')
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
def build_request_url(path)
|
|
276
|
+
# Add leading and trailing slashes to path
|
|
277
|
+
path = "/#{path}".gsub(/\/+/, '/')
|
|
278
|
+
URI.encode(@config.base_url + path)
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
# Builds the HTTP request body
|
|
282
|
+
#
|
|
283
|
+
# @param [Hash] header_params Header parameters
|
|
284
|
+
# @param [Hash] form_params Query parameters
|
|
285
|
+
# @param [Object] body HTTP body (JSON/XML)
|
|
286
|
+
# @return [String] HTTP body data in the form of string
|
|
287
|
+
def build_request_body(header_params, form_params, body)
|
|
288
|
+
# http form
|
|
289
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
|
290
|
+
header_params['Content-Type'] == 'multipart/form-data'
|
|
291
|
+
data = {}
|
|
292
|
+
form_params.each do |key, value|
|
|
293
|
+
case value
|
|
294
|
+
when ::File, ::Array, nil
|
|
295
|
+
# let typhoeus handle File, Array and nil parameters
|
|
296
|
+
data[key] = value
|
|
297
|
+
else
|
|
298
|
+
data[key] = value.to_s
|
|
299
|
+
end
|
|
300
|
+
end
|
|
301
|
+
elsif body
|
|
302
|
+
data = body.is_a?(String) ? body : body.to_json
|
|
303
|
+
else
|
|
304
|
+
data = nil
|
|
305
|
+
end
|
|
306
|
+
data
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
# Update hearder and query params based on authentication settings.
|
|
310
|
+
#
|
|
311
|
+
# @param [Hash] header_params Header parameters
|
|
312
|
+
# @param [Hash] query_params Query parameters
|
|
313
|
+
# @param [String] auth_names Authentication scheme name
|
|
314
|
+
def update_params_for_auth!(header_params, query_params, auth_names)
|
|
315
|
+
Array(auth_names).each do |auth_name|
|
|
316
|
+
auth_setting = @config.auth_settings[auth_name]
|
|
317
|
+
next unless auth_setting
|
|
318
|
+
case auth_setting[:in]
|
|
319
|
+
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
|
320
|
+
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
|
321
|
+
else fail ArgumentError, 'Authentication token must be in `query` of `header`'
|
|
322
|
+
end
|
|
323
|
+
end
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
# Sets user agent in HTTP header
|
|
327
|
+
#
|
|
328
|
+
# @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
|
|
329
|
+
def user_agent=(user_agent)
|
|
330
|
+
@user_agent = user_agent
|
|
331
|
+
@default_headers['User-Agent'] = @user_agent
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
# Return Accept header based on an array of accepts provided.
|
|
335
|
+
# @param [Array] accepts array for Accept
|
|
336
|
+
# @return [String] the Accept header (e.g. application/json)
|
|
337
|
+
def select_header_accept(accepts)
|
|
338
|
+
return nil if accepts.nil? || accepts.empty?
|
|
339
|
+
# use JSON when present, otherwise use all of the provided
|
|
340
|
+
json_accept = accepts.find { |s| json_mime?(s) }
|
|
341
|
+
json_accept || accepts.join(',')
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
# Return Content-Type header based on an array of content types provided.
|
|
345
|
+
# @param [Array] content_types array for Content-Type
|
|
346
|
+
# @return [String] the Content-Type header (e.g. application/json)
|
|
347
|
+
def select_header_content_type(content_types)
|
|
348
|
+
# use application/json by default
|
|
349
|
+
return 'application/json' if content_types.nil? || content_types.empty?
|
|
350
|
+
# use JSON when present, otherwise use the first one
|
|
351
|
+
json_content_type = content_types.find { |s| json_mime?(s) }
|
|
352
|
+
json_content_type || content_types.first
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
# Convert object (array, hash, object, etc) to JSON string.
|
|
356
|
+
# @param [Object] model object to be converted into JSON string
|
|
357
|
+
# @return [String] JSON string representation of the object
|
|
358
|
+
def object_to_http_body(model)
|
|
359
|
+
return model if model.nil? || model.is_a?(String)
|
|
360
|
+
local_body = nil
|
|
361
|
+
if model.is_a?(Array)
|
|
362
|
+
local_body = model.map { |m| object_to_hash(m) }
|
|
363
|
+
else
|
|
364
|
+
local_body = object_to_hash(model)
|
|
365
|
+
end
|
|
366
|
+
local_body.to_json
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
# Convert object(non-array) to hash.
|
|
370
|
+
# @param [Object] obj object to be converted into JSON string
|
|
371
|
+
# @return [String] JSON string representation of the object
|
|
372
|
+
def object_to_hash(obj)
|
|
373
|
+
if obj.respond_to?(:to_hash)
|
|
374
|
+
obj.to_hash
|
|
375
|
+
else
|
|
376
|
+
obj
|
|
377
|
+
end
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
# Build parameter value according to the given collection format.
|
|
381
|
+
# @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
|
|
382
|
+
def build_collection_param(param, collection_format)
|
|
383
|
+
case collection_format
|
|
384
|
+
when :csv
|
|
385
|
+
param.join(',')
|
|
386
|
+
when :ssv
|
|
387
|
+
param.join(' ')
|
|
388
|
+
when :tsv
|
|
389
|
+
param.join("\t")
|
|
390
|
+
when :pipes
|
|
391
|
+
param.join('|')
|
|
392
|
+
when :multi
|
|
393
|
+
# return the array directly as typhoeus will handle it as expected
|
|
394
|
+
param
|
|
395
|
+
else
|
|
396
|
+
fail "unknown collection format: #{collection_format.inspect}"
|
|
397
|
+
end
|
|
398
|
+
end
|
|
399
|
+
end
|
|
400
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
# Mux Ruby - Copyright 2019 Mux Inc.
|
|
3
|
+
# NOTE: This file is auto generated. Do not edit this file manually.
|
|
4
|
+
=end
|
|
5
|
+
|
|
6
|
+
module MuxRuby
|
|
7
|
+
class ApiError < StandardError
|
|
8
|
+
attr_reader :code, :response_headers, :response_body
|
|
9
|
+
|
|
10
|
+
# Usage examples:
|
|
11
|
+
# ApiError.new
|
|
12
|
+
# ApiError.new("message")
|
|
13
|
+
# ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
|
|
14
|
+
# ApiError.new(:code => 404, :message => "Not Found")
|
|
15
|
+
def initialize(arg = nil)
|
|
16
|
+
if arg.is_a? Hash
|
|
17
|
+
if arg.key?(:message) || arg.key?('message')
|
|
18
|
+
super(arg[:message] || arg['message'])
|
|
19
|
+
else
|
|
20
|
+
super arg
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
arg.each do |k, v|
|
|
24
|
+
instance_variable_set "@#{k}", v
|
|
25
|
+
end
|
|
26
|
+
else
|
|
27
|
+
super arg
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
class NotFoundError < ApiError
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class UnauthorizedError < ApiError
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
class ForbiddenError < ApiError
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class ServiceError < ApiError
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|