wsc_sdk 1.3.1
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/.circleci/config.yml +146 -0
- data/.circleci/docker/build/Dockerfile +3 -0
- data/.circleci/helpers/add_preamble.rb +29 -0
- data/.circleci/helpers/build_docs.sh +5 -0
- data/.circleci/helpers/build_gem.sh +5 -0
- data/.circleci/helpers/debundle-context.sh +14 -0
- data/.circleci/helpers/finalize_release.sh +24 -0
- data/.circleci/helpers/publish_docs.sh +10 -0
- data/.circleci/helpers/release_gem.sh +8 -0
- data/.circleci/helpers/setup.sh +11 -0
- data/.circleci/helpers/setup_aws.sh +13 -0
- data/.circleci/helpers/setup_gem.sh +2 -0
- data/.circleci/helpers/setup_git.sh +27 -0
- data/.circleci/helpers/setup_rubygems.sh +15 -0
- data/.circleci/helpers/test_integration.sh +12 -0
- data/.circleci/helpers/test_unit.sh +6 -0
- data/.circleci/jobs/publish-production.sh +17 -0
- data/.circleci/jobs/publish-staging.sh +17 -0
- data/.circleci/jobs/release-production.sh +21 -0
- data/.circleci/jobs/test-integration.sh +9 -0
- data/.circleci/jobs/test-unit.sh +9 -0
- data/.circleci/tag_repo.rb +46 -0
- data/.gitignore +28 -0
- data/.rspec +2 -0
- data/.yard/config +2 -0
- data/.yard/template/default/fulldoc/html/css/custom.css +151 -0
- data/.yard/template/default/layout/html/footer.erb +0 -0
- data/.yard/template/default/layout/html/headers.erb +10 -0
- data/.yard/template/default/layout/html/layout.erb +45 -0
- data/.yard/template/default/layout/html/setup.rb +24 -0
- data/.yardopts +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +99 -0
- data/LICENSE.txt +28 -0
- data/README.md +397 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/doc/Hash.html +291 -0
- data/doc/WscSdk.html +570 -0
- data/doc/WscSdk/ApiResponse.html +242 -0
- data/doc/WscSdk/Attributes.html +128 -0
- data/doc/WscSdk/Attributes/Mode.html +191 -0
- data/doc/WscSdk/Attributes/Type.html +389 -0
- data/doc/WscSdk/Client.html +2677 -0
- data/doc/WscSdk/Configuration.html +595 -0
- data/doc/WscSdk/Endpoint.html +2974 -0
- data/doc/WscSdk/Endpoints.html +141 -0
- data/doc/WscSdk/Endpoints/CustomStreamTargets.html +383 -0
- data/doc/WscSdk/Endpoints/LiveStreams.html +197 -0
- data/doc/WscSdk/Endpoints/OutputStreamTargets.html +180 -0
- data/doc/WscSdk/Endpoints/Outputs.html +180 -0
- data/doc/WscSdk/Endpoints/StreamTargets.html +446 -0
- data/doc/WscSdk/Endpoints/Transcoders.html +197 -0
- data/doc/WscSdk/Endpoints/UllStreamTargets.html +383 -0
- data/doc/WscSdk/Endpoints/WowzaStreamTargets.html +383 -0
- data/doc/WscSdk/Enum.html +225 -0
- data/doc/WscSdk/Enums.html +321 -0
- data/doc/WscSdk/Enums/BillingMode.html +188 -0
- data/doc/WscSdk/Enums/BroadcastLocation.html +396 -0
- data/doc/WscSdk/Enums/BufferSize.html +301 -0
- data/doc/WscSdk/Enums/ClosedCaptionType.html +221 -0
- data/doc/WscSdk/Enums/CustomProvider.html +252 -0
- data/doc/WscSdk/Enums/DeliveryMethod.html +188 -0
- data/doc/WscSdk/Enums/DeliveryType.html +188 -0
- data/doc/WscSdk/Enums/Encoder.html +460 -0
- data/doc/WscSdk/Enums/Errors.html +555 -0
- data/doc/WscSdk/Enums/IdleTimeout.html +398 -0
- data/doc/WscSdk/Enums/ImagePosition.html +220 -0
- data/doc/WscSdk/Enums/ModelMode.html +175 -0
- data/doc/WscSdk/Enums/ModelType.html +373 -0
- data/doc/WscSdk/Enums/PlayerType.html +188 -0
- data/doc/WscSdk/Enums/Protocol.html +204 -0
- data/doc/WscSdk/Enums/TargetDeliveryProtocol.html +188 -0
- data/doc/WscSdk/Enums/TranscoderType.html +188 -0
- data/doc/WscSdk/Enums/UserRegion.html +383 -0
- data/doc/WscSdk/Enums/WowzaProvider.html +188 -0
- data/doc/WscSdk/Errors.html +683 -0
- data/doc/WscSdk/Loggable.html +346 -0
- data/doc/WscSdk/Model.html +3316 -0
- data/doc/WscSdk/ModelList.html +442 -0
- data/doc/WscSdk/ModelTemplate.html +267 -0
- data/doc/WscSdk/Models.html +141 -0
- data/doc/WscSdk/Models/CustomStreamTarget.html +192 -0
- data/doc/WscSdk/Models/Error.html +351 -0
- data/doc/WscSdk/Models/LiveStream.html +601 -0
- data/doc/WscSdk/Models/LiveStreamConnectionCode.html +192 -0
- data/doc/WscSdk/Models/LiveStreamState.html +200 -0
- data/doc/WscSdk/Models/LiveStreamStats.html +200 -0
- data/doc/WscSdk/Models/LiveStreamThumbnailUrl.html +200 -0
- data/doc/WscSdk/Models/Output.html +294 -0
- data/doc/WscSdk/Models/OutputStreamTarget.html +274 -0
- data/doc/WscSdk/Models/StreamTarget.html +273 -0
- data/doc/WscSdk/Models/Transcoder.html +793 -0
- data/doc/WscSdk/Models/TranscoderBooleanStat.html +278 -0
- data/doc/WscSdk/Models/TranscoderConnectionCode.html +192 -0
- data/doc/WscSdk/Models/TranscoderFloatStat.html +278 -0
- data/doc/WscSdk/Models/TranscoderIntegerStat.html +278 -0
- data/doc/WscSdk/Models/TranscoderState.html +196 -0
- data/doc/WscSdk/Models/TranscoderStats.html +196 -0
- data/doc/WscSdk/Models/TranscoderStreamTargetState.html +192 -0
- data/doc/WscSdk/Models/TranscoderStringStat.html +278 -0
- data/doc/WscSdk/Models/TranscoderThumbnailUrl.html +196 -0
- data/doc/WscSdk/Models/UllStreamTarget.html +360 -0
- data/doc/WscSdk/Models/WowzaStreamTarget.html +380 -0
- data/doc/WscSdk/Pagination.html +1277 -0
- data/doc/WscSdk/Schema.html +861 -0
- data/doc/WscSdk/SchemaAttribute.html +2400 -0
- data/doc/WscSdk/Templates.html +141 -0
- data/doc/WscSdk/Templates/CustomStreamTarget.html +1045 -0
- data/doc/WscSdk/Templates/LiveStream.html +1432 -0
- data/doc/WscSdk/Templates/Output.html +829 -0
- data/doc/WscSdk/Templates/Transcoder.html +699 -0
- data/doc/WscSdk/Templates/UllStreamTarget.html +411 -0
- data/doc/WscSdk/Templates/WowzaStreamTarget.html +447 -0
- data/doc/WscSdk/TranscoderSharedMethods.html +1113 -0
- data/doc/_index.html +705 -0
- data/doc/class_list.html +51 -0
- data/doc/css/bootstrap.css +5 -0
- data/doc/css/common.css +1 -0
- data/doc/css/custom.css +151 -0
- data/doc/css/full_list.css +58 -0
- data/doc/css/style.css +496 -0
- data/doc/file.README.html +570 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +17 -0
- data/doc/images/wsc-ruby-1800x400.png +0 -0
- data/doc/index.html +570 -0
- data/doc/js/app.js +292 -0
- data/doc/js/full_list.js +216 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +1731 -0
- data/doc/top-level-namespace.html +182 -0
- data/examples/client.rb +40 -0
- data/examples/helpers.rb +100 -0
- data/examples/live_streams/create.rb +39 -0
- data/examples/live_streams/delete.rb +32 -0
- data/examples/live_streams/find.rb +22 -0
- data/examples/live_streams/flood.rb +126 -0
- data/examples/live_streams/list.rb +24 -0
- data/examples/live_streams/regenerate_connection_code.rb +29 -0
- data/examples/live_streams/reset.rb +32 -0
- data/examples/live_streams/reset_and_wait.rb +51 -0
- data/examples/live_streams/start.rb +33 -0
- data/examples/live_streams/start_and_wait.rb +51 -0
- data/examples/live_streams/state.rb +33 -0
- data/examples/live_streams/stats.rb +43 -0
- data/examples/live_streams/stop.rb +33 -0
- data/examples/live_streams/stop_and_wait.rb +51 -0
- data/examples/live_streams/thumbnail_url.rb +46 -0
- data/examples/live_streams/update.rb +43 -0
- data/examples/live_streams/workflow.rb +165 -0
- data/examples/output_stream_targets/create.rb +56 -0
- data/examples/output_stream_targets/delete.rb +45 -0
- data/examples/output_stream_targets/find.rb +37 -0
- data/examples/output_stream_targets/list.rb +36 -0
- data/examples/output_stream_targets/update.rb +56 -0
- data/examples/outputs/create.rb +49 -0
- data/examples/outputs/delete.rb +39 -0
- data/examples/outputs/find.rb +31 -0
- data/examples/outputs/list.rb +29 -0
- data/examples/outputs/update.rb +50 -0
- data/examples/stream_targets/custom/create.rb +42 -0
- data/examples/stream_targets/custom/delete.rb +31 -0
- data/examples/stream_targets/custom/find.rb +23 -0
- data/examples/stream_targets/custom/list.rb +24 -0
- data/examples/stream_targets/custom/update.rb +43 -0
- data/examples/stream_targets/list.rb +24 -0
- data/examples/stream_targets/ull/create.rb +41 -0
- data/examples/stream_targets/ull/delete.rb +31 -0
- data/examples/stream_targets/ull/find.rb +23 -0
- data/examples/stream_targets/ull/list.rb +24 -0
- data/examples/stream_targets/ull/update.rb +43 -0
- data/examples/stream_targets/wowza/create.rb +42 -0
- data/examples/stream_targets/wowza/delete.rb +31 -0
- data/examples/stream_targets/wowza/find.rb +23 -0
- data/examples/stream_targets/wowza/list.rb +23 -0
- data/examples/stream_targets/wowza/update.rb +43 -0
- data/examples/transcoders/create.rb +39 -0
- data/examples/transcoders/delete.rb +31 -0
- data/examples/transcoders/find.rb +23 -0
- data/examples/transcoders/list.rb +24 -0
- data/examples/transcoders/reset.rb +32 -0
- data/examples/transcoders/reset_and_wait.rb +48 -0
- data/examples/transcoders/start.rb +33 -0
- data/examples/transcoders/start_and_wait.rb +50 -0
- data/examples/transcoders/state.rb +33 -0
- data/examples/transcoders/stats.rb +43 -0
- data/examples/transcoders/stop.rb +33 -0
- data/examples/transcoders/stop_and_wait.rb +50 -0
- data/examples/transcoders/thumbnail_url.rb +46 -0
- data/examples/transcoders/update.rb +43 -0
- data/images/wsc-ruby-1800x400.png +0 -0
- data/lib/wsc_sdk.rb +81 -0
- data/lib/wsc_sdk/client.rb +417 -0
- data/lib/wsc_sdk/configuration.rb +21 -0
- data/lib/wsc_sdk/constants.rb +29 -0
- data/lib/wsc_sdk/endpoint.rb +492 -0
- data/lib/wsc_sdk/endpoints/custom_stream_targets.rb +44 -0
- data/lib/wsc_sdk/endpoints/live_streams.rb +34 -0
- data/lib/wsc_sdk/endpoints/output_stream_targets.rb +17 -0
- data/lib/wsc_sdk/endpoints/outputs.rb +17 -0
- data/lib/wsc_sdk/endpoints/stream_targets.rb +45 -0
- data/lib/wsc_sdk/endpoints/transcoders.rb +38 -0
- data/lib/wsc_sdk/endpoints/ull_stream_targets.rb +44 -0
- data/lib/wsc_sdk/endpoints/wowza_stream_targets.rb +44 -0
- data/lib/wsc_sdk/enums.rb +31 -0
- data/lib/wsc_sdk/enums/billing_mode.rb +20 -0
- data/lib/wsc_sdk/enums/broadcast_location.rb +58 -0
- data/lib/wsc_sdk/enums/buffer_size.rb +41 -0
- data/lib/wsc_sdk/enums/closed_caption_type.rb +26 -0
- data/lib/wsc_sdk/enums/custom_provider.rb +32 -0
- data/lib/wsc_sdk/enums/delivery_method.rb +20 -0
- data/lib/wsc_sdk/enums/delivery_type.rb +20 -0
- data/lib/wsc_sdk/enums/encoder.rb +71 -0
- data/lib/wsc_sdk/enums/idle_timeout.rb +50 -0
- data/lib/wsc_sdk/enums/image_position.rb +26 -0
- data/lib/wsc_sdk/enums/player_type.rb +20 -0
- data/lib/wsc_sdk/enums/protocol.rb +23 -0
- data/lib/wsc_sdk/enums/target_delivery_protocol.rb +20 -0
- data/lib/wsc_sdk/enums/transcoder_type.rb +20 -0
- data/lib/wsc_sdk/enums/wowza_provider.rb +20 -0
- data/lib/wsc_sdk/errors.rb +115 -0
- data/lib/wsc_sdk/model.rb +515 -0
- data/lib/wsc_sdk/model_list.rb +42 -0
- data/lib/wsc_sdk/model_template.rb +27 -0
- data/lib/wsc_sdk/models/custom_stream_target.rb +34 -0
- data/lib/wsc_sdk/models/error.rb +53 -0
- data/lib/wsc_sdk/models/live_stream.rb +130 -0
- data/lib/wsc_sdk/models/live_stream_connection_code.rb +31 -0
- data/lib/wsc_sdk/models/live_stream_state.rb +20 -0
- data/lib/wsc_sdk/models/live_stream_stats.rb +20 -0
- data/lib/wsc_sdk/models/live_stream_thumbnail_url.rb +20 -0
- data/lib/wsc_sdk/models/output.rb +61 -0
- data/lib/wsc_sdk/models/output_stream_target.rb +37 -0
- data/lib/wsc_sdk/models/stream_target.rb +29 -0
- data/lib/wsc_sdk/models/transcoder.rb +135 -0
- data/lib/wsc_sdk/models/transcoder_boolean_stat.rb +41 -0
- data/lib/wsc_sdk/models/transcoder_connection_code.rb +29 -0
- data/lib/wsc_sdk/models/transcoder_float_stat.rb +40 -0
- data/lib/wsc_sdk/models/transcoder_integer_stat.rb +40 -0
- data/lib/wsc_sdk/models/transcoder_state.rb +31 -0
- data/lib/wsc_sdk/models/transcoder_stats.rb +51 -0
- data/lib/wsc_sdk/models/transcoder_stream_target_state.rb +29 -0
- data/lib/wsc_sdk/models/transcoder_string_stat.rb +40 -0
- data/lib/wsc_sdk/models/transcoder_thumbnail_url.rb +29 -0
- data/lib/wsc_sdk/models/ull_stream_target.rb +54 -0
- data/lib/wsc_sdk/models/wowza_stream_target.rb +60 -0
- data/lib/wsc_sdk/modules/api_response.rb +24 -0
- data/lib/wsc_sdk/modules/loggable.rb +44 -0
- data/lib/wsc_sdk/modules/transcoder_shared_methods.rb +221 -0
- data/lib/wsc_sdk/pagination.rb +89 -0
- data/lib/wsc_sdk/schema.rb +140 -0
- data/lib/wsc_sdk/schema_attribute.rb +349 -0
- data/lib/wsc_sdk/templates/custom_stream_target.rb +154 -0
- data/lib/wsc_sdk/templates/live_stream.rb +234 -0
- data/lib/wsc_sdk/templates/output.rb +133 -0
- data/lib/wsc_sdk/templates/transcoder.rb +97 -0
- data/lib/wsc_sdk/templates/ull_stream_target.rb +49 -0
- data/lib/wsc_sdk/templates/wowza_stream_target.rb +57 -0
- data/lib/wsc_sdk/version.rb +7 -0
- data/wsc_sdk.gemspec +48 -0
- metadata +460 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
####> This code and all components © 2015 – 2019 Wowza Media Systems, LLC. All rights reserved.
|
|
2
|
+
####> This code is licensed pursuant to the BSD 3-Clause License.
|
|
3
|
+
|
|
4
|
+
require "wsc_sdk"
|
|
5
|
+
require_relative "../client" # Get our client
|
|
6
|
+
require_relative "../helpers" # Include some helpers to make the code more direct
|
|
7
|
+
|
|
8
|
+
# Ensure the args passed in are present
|
|
9
|
+
arguments = ask_for_arguments(__FILE__, transcoder_id: nil)
|
|
10
|
+
|
|
11
|
+
# Extract some data into convenience variables
|
|
12
|
+
transcoders = $client.transcoders
|
|
13
|
+
transcoder_id = arguments[0]
|
|
14
|
+
|
|
15
|
+
# Request the transcoder object
|
|
16
|
+
transcoder = transcoders.find(transcoder_id)
|
|
17
|
+
|
|
18
|
+
# Handle an API error (in the helpers.rb file)
|
|
19
|
+
handle_api_error(transcoder, "There was an error finding the transcoder") unless transcoder.success?
|
|
20
|
+
|
|
21
|
+
# Get the result of starting the transcoder. We add a code block, which
|
|
22
|
+
# instructs the SDK to enter a wait loop, and periodically polls the API
|
|
23
|
+
# for the transcoder state until either the `started` state is returned or
|
|
24
|
+
# the timeout period is reached.
|
|
25
|
+
state = transcoder.start do |wait_state, transcoder_state|
|
|
26
|
+
# This code will execute each time the state of the transcoder is polled
|
|
27
|
+
# during the wait loop. You can check the wait_state to determine what the
|
|
28
|
+
# outcomes of each request are.
|
|
29
|
+
|
|
30
|
+
if wait_state == :waiting
|
|
31
|
+
# We're still waiting for the started state to be returned
|
|
32
|
+
puts "Waiting..."
|
|
33
|
+
elsif wait_state == :complete
|
|
34
|
+
# We've successfully started the transcoder, so output the completed state
|
|
35
|
+
# Defined in helpers.rb
|
|
36
|
+
output_model_attributes(transcoder_state, "Completed Transcoder State:")
|
|
37
|
+
elsif wait_state == :timeout
|
|
38
|
+
# A timeout occurs if the start state isn't reached within the timeout
|
|
39
|
+
# limit, which defaults to 30 seconds.
|
|
40
|
+
|
|
41
|
+
puts "TIMEOUT: Could not start the transcoder within the timeout period."
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Handle an API error. (In the helpers.rb file)
|
|
46
|
+
handle_api_error(state, "There was an error starting the transcoder") unless state.success?
|
|
47
|
+
|
|
48
|
+
# Output the transcoder state
|
|
49
|
+
# Defined in helpers.rb
|
|
50
|
+
output_model_attributes(state, "Final Transcoder State:")
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
####> This code and all components © 2015 – 2019 Wowza Media Systems, LLC. All rights reserved.
|
|
2
|
+
####> This code is licensed pursuant to the BSD 3-Clause License.
|
|
3
|
+
|
|
4
|
+
require "wsc_sdk"
|
|
5
|
+
require_relative "../client" # Get our client
|
|
6
|
+
require_relative "../helpers" # Include some helpers to make the code more direct
|
|
7
|
+
|
|
8
|
+
# Ensure the args passed in are present
|
|
9
|
+
arguments = ask_for_arguments(__FILE__, transcoder_id: nil)
|
|
10
|
+
|
|
11
|
+
# Extract some data into convenience variables
|
|
12
|
+
transcoders = $client.transcoders
|
|
13
|
+
transcoder_id = arguments[0]
|
|
14
|
+
|
|
15
|
+
# Request the transcoder object
|
|
16
|
+
transcoder = transcoders.find(transcoder_id)
|
|
17
|
+
|
|
18
|
+
# Handle an API error (in the helpers.rb file)
|
|
19
|
+
handle_api_error(transcoder, "There was an error finding the transcoder") unless transcoder.success?
|
|
20
|
+
|
|
21
|
+
# Get the result of stopping the transcoder
|
|
22
|
+
#
|
|
23
|
+
# NOTE: You can also stop and wait for the transcoder state to transition to
|
|
24
|
+
# a stopped state. See the `stop_and_wait` example.
|
|
25
|
+
#
|
|
26
|
+
state = transcoder.state
|
|
27
|
+
|
|
28
|
+
# Handle an API error (in the helpers.rb file)
|
|
29
|
+
handle_api_error(state, "There was an error getting the transcoder state") unless state.success?
|
|
30
|
+
|
|
31
|
+
# Output the transcoder state
|
|
32
|
+
# Defined in helpers.rb
|
|
33
|
+
output_model_attributes(state, "Transcoder State:")
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
####> This code and all components © 2015 – 2019 Wowza Media Systems, LLC. All rights reserved.
|
|
2
|
+
####> This code is licensed pursuant to the BSD 3-Clause License.
|
|
3
|
+
|
|
4
|
+
require "wsc_sdk"
|
|
5
|
+
require_relative "../client" # Get our client
|
|
6
|
+
require_relative "../helpers" # Include some helpers to make the code more direct
|
|
7
|
+
|
|
8
|
+
# Ensure the args passed in are present
|
|
9
|
+
arguments = ask_for_arguments(__FILE__, transcoder_id: nil)
|
|
10
|
+
|
|
11
|
+
# Extract some data into convenience variables
|
|
12
|
+
transcoders = $client.transcoders
|
|
13
|
+
transcoder_id = arguments[0]
|
|
14
|
+
|
|
15
|
+
# Request the transcoder object
|
|
16
|
+
transcoder = transcoders.find(transcoder_id)
|
|
17
|
+
|
|
18
|
+
# Handle an API error (in the helpers.rb file)
|
|
19
|
+
handle_api_error(transcoder, "There was an error finding the transcoder") unless transcoder.success?
|
|
20
|
+
|
|
21
|
+
# Request the transcoder state
|
|
22
|
+
state = transcoder.state
|
|
23
|
+
|
|
24
|
+
# Handle an API error (in the helpers.rb file)
|
|
25
|
+
handle_api_error(state, "There was an error getting the transcoder state") unless state.success?
|
|
26
|
+
|
|
27
|
+
# Ensure the transcoder is started
|
|
28
|
+
if state.state != 'started'
|
|
29
|
+
# Start the transcoder and wait
|
|
30
|
+
result = transcoder.start do |wait_state, transcoder_state|
|
|
31
|
+
puts "Waiting for transcoder to start"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Request the current statistics from the transcoder
|
|
36
|
+
stats = transcoder.stats
|
|
37
|
+
|
|
38
|
+
# Handle an API error (in the helpers.rb file)
|
|
39
|
+
handle_api_error(stats, "There was an error getting the transcoder stats") unless stats.success?
|
|
40
|
+
|
|
41
|
+
# Output the current transcoder statistics
|
|
42
|
+
# Defined in helpers.rb
|
|
43
|
+
output_model_attributes(stats, "Transcoder Stats:")
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
####> This code and all components © 2015 – 2019 Wowza Media Systems, LLC. All rights reserved.
|
|
2
|
+
####> This code is licensed pursuant to the BSD 3-Clause License.
|
|
3
|
+
|
|
4
|
+
require "wsc_sdk"
|
|
5
|
+
require_relative "../client" # Get our client
|
|
6
|
+
require_relative "../helpers" # Include some helpers to make the code more direct
|
|
7
|
+
|
|
8
|
+
# Ensure the args passed in are present
|
|
9
|
+
arguments = ask_for_arguments(__FILE__, transcoder_id: nil)
|
|
10
|
+
|
|
11
|
+
# Extract some data into convenience variables
|
|
12
|
+
transcoders = $client.transcoders
|
|
13
|
+
transcoder_id = arguments[0]
|
|
14
|
+
|
|
15
|
+
# Request the transcoder object
|
|
16
|
+
transcoder = transcoders.find(transcoder_id)
|
|
17
|
+
|
|
18
|
+
# Handle an API error (in the helpers.rb file)
|
|
19
|
+
handle_api_error(transcoder, "There was an error finding the transcoder") unless transcoder.success?
|
|
20
|
+
|
|
21
|
+
# Get the result of stopping the transcoder
|
|
22
|
+
#
|
|
23
|
+
# NOTE: You can also stop and wait for the transcoder state to transition to
|
|
24
|
+
# a stopped state. See the `stop_and_wait` example.
|
|
25
|
+
#
|
|
26
|
+
state = transcoder.stop
|
|
27
|
+
|
|
28
|
+
# Handle an API error (in the helpers.rb file)
|
|
29
|
+
handle_api_error(state, "There was an error getting the transcoder state") unless state.success?
|
|
30
|
+
|
|
31
|
+
# Output the transcoder state
|
|
32
|
+
# Defined in helpers.rb
|
|
33
|
+
output_model_attributes(state, "Transcoder State:")
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
####> This code and all components © 2015 – 2019 Wowza Media Systems, LLC. All rights reserved.
|
|
2
|
+
####> This code is licensed pursuant to the BSD 3-Clause License.
|
|
3
|
+
|
|
4
|
+
require "wsc_sdk"
|
|
5
|
+
require_relative "../client" # Get our client
|
|
6
|
+
require_relative "../helpers" # Include some helpers to make the code more direct
|
|
7
|
+
|
|
8
|
+
# Ensure the args passed in are present
|
|
9
|
+
arguments = ask_for_arguments(__FILE__, transcoder_id: nil)
|
|
10
|
+
|
|
11
|
+
# Extract some data into convenience variables
|
|
12
|
+
transcoders = $client.transcoders
|
|
13
|
+
transcoder_id = arguments[0]
|
|
14
|
+
|
|
15
|
+
# Request the transcoder object
|
|
16
|
+
transcoder = transcoders.find(transcoder_id)
|
|
17
|
+
|
|
18
|
+
# Handle an API error (in the helpers.rb file)
|
|
19
|
+
handle_api_error(transcoder, "There was an error finding the transcoder") unless transcoder.success?
|
|
20
|
+
|
|
21
|
+
# Get the result of stopping the transcoder. We add a code block, which
|
|
22
|
+
# instructs the SDK to enter a wait loop and periodically polls the API
|
|
23
|
+
# for the transcoder state until either the `stopped` state is returned or
|
|
24
|
+
# the timeout period is reached.
|
|
25
|
+
state = transcoder.stop do |wait_state, transcoder_state|
|
|
26
|
+
# This code will execute each time the state of the transcoder is polled
|
|
27
|
+
# during the wait loop. You can check the wait_state to determine what the
|
|
28
|
+
# outcomes of each request are.
|
|
29
|
+
|
|
30
|
+
if wait_state == :waiting
|
|
31
|
+
# We're still waiting for the stopped state to be returned
|
|
32
|
+
puts "Waiting..."
|
|
33
|
+
elsif wait_state == :complete
|
|
34
|
+
# We've successfully stopped the transcoder, so output the completed state
|
|
35
|
+
# Defined in helpers.rb
|
|
36
|
+
output_model_attributes(transcoder_state, "Transcoder State:")
|
|
37
|
+
elsif wait_state == :timeout
|
|
38
|
+
# A timeout occurs if the stop state isn't reached within the timeout
|
|
39
|
+
# limit, which defaults to 30 seconds.
|
|
40
|
+
|
|
41
|
+
puts "TIMEOUT: Could not stop the transcoder within the timeout period."
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Handle an API error (in the helpers.rb file)
|
|
46
|
+
handle_api_error(state, "There was an error stopping the transcoder") unless state.success?
|
|
47
|
+
|
|
48
|
+
# Output the transcoder state
|
|
49
|
+
# Defined in helpers.rb
|
|
50
|
+
output_model_attributes(state, "Transcoder State:")
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
####> This code and all components © 2015 – 2019 Wowza Media Systems, LLC. All rights reserved.
|
|
2
|
+
####> This code is licensed pursuant to the BSD 3-Clause License.
|
|
3
|
+
|
|
4
|
+
require "wsc_sdk"
|
|
5
|
+
require_relative "../client" # Get our client
|
|
6
|
+
require_relative "../helpers" # Include some helpers to make the code more direct
|
|
7
|
+
|
|
8
|
+
# Ensure the args passed in are present
|
|
9
|
+
arguments = ask_for_arguments(__FILE__, transcoder_id: nil)
|
|
10
|
+
|
|
11
|
+
# Extract some data into convenience variables
|
|
12
|
+
transcoders = $client.transcoders
|
|
13
|
+
transcoder_id = arguments[0]
|
|
14
|
+
|
|
15
|
+
# Request the transcoder object
|
|
16
|
+
transcoder = transcoders.find(transcoder_id)
|
|
17
|
+
|
|
18
|
+
# Handle an API error (in the helpers.rb file)
|
|
19
|
+
handle_api_error(transcoder, "There was an error finding the transcoder") unless transcoder.success?
|
|
20
|
+
|
|
21
|
+
# Request the transcoder state
|
|
22
|
+
state = transcoder.state
|
|
23
|
+
|
|
24
|
+
# Handle an API error (in the helpers.rb file)
|
|
25
|
+
handle_api_error(state, "There was an error getting the transcoder state") unless state.success?
|
|
26
|
+
|
|
27
|
+
# Ensure the transcoder is started
|
|
28
|
+
if state.state != 'started'
|
|
29
|
+
# Start the transcoder and wait
|
|
30
|
+
state = transcoder.start do |wait_state, transcoder_state|
|
|
31
|
+
puts "Waiting for transcoder to start"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Handle an API error (in the helpers.rb file)
|
|
35
|
+
handle_api_error(state, "There was an error starting the transcoder") unless state.success?
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Request the thumbnail url
|
|
39
|
+
thumbnail = transcoder.thumbnail_url
|
|
40
|
+
|
|
41
|
+
# Handle an API error (in the helpers.rb file)
|
|
42
|
+
handle_api_error(thumbnail, "There was an error getting the transcoder thumbnail url") unless thumbnail.success?
|
|
43
|
+
|
|
44
|
+
# Output the thumbnail URL
|
|
45
|
+
# Defined in helpers.rb
|
|
46
|
+
output_model_attributes(thumbnail, "Transcoder Thumbnail:")
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
####> This code and all components © 2015 – 2019 Wowza Media Systems, LLC. All rights reserved.
|
|
2
|
+
####> This code is licensed pursuant to the BSD 3-Clause License.
|
|
3
|
+
|
|
4
|
+
require "wsc_sdk"
|
|
5
|
+
require_relative "../client" # Get our client
|
|
6
|
+
require_relative "../helpers" # Include some helpers to make the code more direct
|
|
7
|
+
|
|
8
|
+
# Ensure the args passed in are present
|
|
9
|
+
arguments = ask_for_arguments(__FILE__, transcoder_id: nil, new_transcoder_name: nil)
|
|
10
|
+
|
|
11
|
+
# Extract some data into convenience variables
|
|
12
|
+
transcoders = $client.transcoders
|
|
13
|
+
transcoder_id = arguments[0]
|
|
14
|
+
transcoder_name = arguments[1]
|
|
15
|
+
|
|
16
|
+
# Request the transcoder object
|
|
17
|
+
transcoder = transcoders.find(transcoder_id)
|
|
18
|
+
|
|
19
|
+
# Handle an API error (in the helpers.rb file)
|
|
20
|
+
handle_api_error(transcoder, "There was an error finding the transcoder") unless transcoder.success?
|
|
21
|
+
|
|
22
|
+
# Update the transcoder
|
|
23
|
+
transcoder.name = transcoder_name
|
|
24
|
+
|
|
25
|
+
# If the transcoder is invalid, output the messages and exit
|
|
26
|
+
unless (transcoder.valid?)
|
|
27
|
+
puts "Transcoder is invalid:"
|
|
28
|
+
|
|
29
|
+
transcoder.errors.each do |field, message|
|
|
30
|
+
puts " - #{field}: #{message}"
|
|
31
|
+
end
|
|
32
|
+
exit
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Get the result of saving the object to the API
|
|
36
|
+
saved = transcoder.save
|
|
37
|
+
|
|
38
|
+
# Handle an API error (in the helpers.rb file)
|
|
39
|
+
handle_api_error(saved, "There was an error saving the transcoder") unless saved.success?
|
|
40
|
+
|
|
41
|
+
# Output the transcoder details
|
|
42
|
+
# Defined in helpers.rb
|
|
43
|
+
output_model_attributes(transcoder, "Transcoder: #{transcoder.name}")
|
|
Binary file
|
data/lib/wsc_sdk.rb
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
####> This code and all components © 2015 – 2019 Wowza Media Systems, LLC. All rights reserved.
|
|
2
|
+
####> This code is licensed pursuant to the BSD 3-Clause License.
|
|
3
|
+
|
|
4
|
+
# The root path of the SDK code base.
|
|
5
|
+
WSC_SDK_ROOT_PATH = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
|
6
|
+
|
|
7
|
+
# The ./lib path of the SDK code base
|
|
8
|
+
WSC_SDK_LIB_PATH = File.join(WSC_SDK_ROOT_PATH, "lib")
|
|
9
|
+
|
|
10
|
+
# The ./lib/wsc_sdk path of the SDK code base
|
|
11
|
+
WSC_SDK_PATH = File.join(WSC_SDK_LIB_PATH, "wsc_sdk")
|
|
12
|
+
|
|
13
|
+
require 'logger'
|
|
14
|
+
require 'httparty'
|
|
15
|
+
require 'active_support/core_ext/hash'
|
|
16
|
+
require 'active_support/core_ext/string'
|
|
17
|
+
|
|
18
|
+
require "wsc_sdk/constants"
|
|
19
|
+
require "wsc_sdk/errors"
|
|
20
|
+
require "wsc_sdk/configuration"
|
|
21
|
+
require "wsc_sdk/client"
|
|
22
|
+
require "wsc_sdk/schema"
|
|
23
|
+
require "wsc_sdk/schema_attribute"
|
|
24
|
+
|
|
25
|
+
Dir[File.join(WSC_SDK_PATH, "modules", "**", "*.rb")].each{ |f| require f }
|
|
26
|
+
|
|
27
|
+
require "wsc_sdk/enums"
|
|
28
|
+
Dir[File.join(WSC_SDK_PATH, "attributes", "**", "*.rb")].each{ |f| require f }
|
|
29
|
+
Dir[File.join(WSC_SDK_PATH, "enums", "**", "*.rb")].each{ |f| require f }
|
|
30
|
+
|
|
31
|
+
require "wsc_sdk/model"
|
|
32
|
+
require "wsc_sdk/pagination"
|
|
33
|
+
require "wsc_sdk/model_list"
|
|
34
|
+
Dir[File.join(WSC_SDK_PATH, "models", "**", "*.rb")].each{ |f| require f }
|
|
35
|
+
|
|
36
|
+
require "wsc_sdk/model_template"
|
|
37
|
+
Dir[File.join(WSC_SDK_PATH, "templates", "**", "*.rb")].each{ |f| require f }
|
|
38
|
+
|
|
39
|
+
require "wsc_sdk/endpoint"
|
|
40
|
+
Dir[File.join(WSC_SDK_PATH, "endpoints", "**", "*.rb")].each{ |f| require f }
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
module WscSdk
|
|
44
|
+
|
|
45
|
+
# Generate class level attributes for the WscSdk module.
|
|
46
|
+
#
|
|
47
|
+
class << self
|
|
48
|
+
attr_writer :configuration
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Get the SDK configuration object.
|
|
52
|
+
#
|
|
53
|
+
# @return [WscSdk::Configuration]
|
|
54
|
+
# The SDK configuration object.
|
|
55
|
+
#
|
|
56
|
+
def self.configuration
|
|
57
|
+
@configuration ||= WscSdk::Configuration.new
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Provides a mechanism to configure the SDK given a block.
|
|
61
|
+
#
|
|
62
|
+
# @yield [configuration]
|
|
63
|
+
# Gives a configuration object to the block so it can be setup properly.
|
|
64
|
+
#
|
|
65
|
+
# @yieldparam configuration [WscSdk::Configuration]
|
|
66
|
+
# The SDK configuration object.
|
|
67
|
+
#
|
|
68
|
+
def self.configure
|
|
69
|
+
yield(configuration)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Returns an instance of the client configured using the SDK configuration
|
|
73
|
+
#
|
|
74
|
+
# @return [WscSdk::Client]
|
|
75
|
+
# An instance of the client object configured using the SDK configuration.
|
|
76
|
+
#
|
|
77
|
+
def self.client
|
|
78
|
+
@client ||= WscSdk::Client.configured_instance
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
end
|
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
####> This code and all components © 2015 – 2019 Wowza Media Systems, LLC. All rights reserved.
|
|
2
|
+
####> This code is licensed pursuant to the BSD 3-Clause License.
|
|
3
|
+
|
|
4
|
+
module WscSdk
|
|
5
|
+
|
|
6
|
+
# A client to manage credentials and act as an entrypoint for the SDK and all
|
|
7
|
+
# API interactions.
|
|
8
|
+
#
|
|
9
|
+
# @example Usage
|
|
10
|
+
#
|
|
11
|
+
# !!!ruby
|
|
12
|
+
# api_key = "[your-api-key]"
|
|
13
|
+
# access_key = "[your-api-access-key]"
|
|
14
|
+
# client = WscSdk::Client.new(api_key, access_key)
|
|
15
|
+
#
|
|
16
|
+
# @example Usage with Environment Variables: Shell Config
|
|
17
|
+
#
|
|
18
|
+
# !!!bash
|
|
19
|
+
# export WSC_API_KEY=[your-api-key]
|
|
20
|
+
# export WSC_API_ACCESS_KEY=[your-api-access-key]
|
|
21
|
+
#
|
|
22
|
+
# @example Usage with Environment Variables: Client Config
|
|
23
|
+
#
|
|
24
|
+
# !!!ruby
|
|
25
|
+
# client = WscSdk::Client.new()
|
|
26
|
+
#
|
|
27
|
+
class Client
|
|
28
|
+
include HTTParty
|
|
29
|
+
|
|
30
|
+
# Maximum number of requests to execute per second.
|
|
31
|
+
MAX_REQUESTS_PER_SECOND = 5
|
|
32
|
+
|
|
33
|
+
base_uri WscSdk::HOSTNAME
|
|
34
|
+
|
|
35
|
+
attr_accessor :api_key, :access_key, :path_version, :hostname, :base_path, :logger
|
|
36
|
+
|
|
37
|
+
attr_reader :last_request_time
|
|
38
|
+
|
|
39
|
+
# Create a new instance of the client.
|
|
40
|
+
#
|
|
41
|
+
# @param options [Hash]
|
|
42
|
+
# A hash of options.
|
|
43
|
+
#
|
|
44
|
+
# @option options [String] :api_key
|
|
45
|
+
# The account's API key. Used to generated signatures for the API request
|
|
46
|
+
# headers.
|
|
47
|
+
#
|
|
48
|
+
# @option options [String] :access_key
|
|
49
|
+
# The account's access key. Used to identify the profile making the
|
|
50
|
+
# API requests.
|
|
51
|
+
#
|
|
52
|
+
# @option options [String] :hostname
|
|
53
|
+
# The hostname to use when generating requests to the API.
|
|
54
|
+
#
|
|
55
|
+
# @option options [Logger] :logger
|
|
56
|
+
# The logger to use when generating log output in the SDK.
|
|
57
|
+
#
|
|
58
|
+
# @option options [String] :version
|
|
59
|
+
# The version of the API to use when generating requests to the API.
|
|
60
|
+
#
|
|
61
|
+
def initialize(options={})
|
|
62
|
+
@api_key = options.fetch(:api_key, WscSdk.configuration.api_key)
|
|
63
|
+
@access_key = options.fetch(:access_key, WscSdk.configuration.access_key)
|
|
64
|
+
@hostname = options.fetch(:hostname, WscSdk.configuration.hostname)
|
|
65
|
+
@path_version = options.fetch(:version, WscSdk.configuration.version)
|
|
66
|
+
@base_path = ["", "api", @path_version].join("/")
|
|
67
|
+
@logger = options.fetch(:logger, WscSdk.configuration.logger)
|
|
68
|
+
self.class.base_uri(@hostname)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# Get the fully qualified request path for an API request.
|
|
73
|
+
#
|
|
74
|
+
# @param path [String]
|
|
75
|
+
# The path of the API request.
|
|
76
|
+
#
|
|
77
|
+
# @return [String]
|
|
78
|
+
# The fully qualified request path.
|
|
79
|
+
#
|
|
80
|
+
def full_request_path(path)
|
|
81
|
+
[ base_path, path ].join("/")
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
# Outputs the details of the client as a string.
|
|
86
|
+
#
|
|
87
|
+
# @return [String] The details of the client.
|
|
88
|
+
#
|
|
89
|
+
def to_s
|
|
90
|
+
"WSC SDK Client > hostname: #{hostname} | version: #{path_version} | base_path: #{base_path}"
|
|
91
|
+
end
|
|
92
|
+
#---------------------------------------------------------------------------
|
|
93
|
+
# ___ _ _ _
|
|
94
|
+
# | __|_ _ __| |_ __ ___(_)_ _| |_ ___
|
|
95
|
+
# | _|| ' \/ _` | '_ \/ _ \ | ' \ _(_-<
|
|
96
|
+
# |___|_||_\__,_| .__/\___/_|_||_\__/__/
|
|
97
|
+
# |_|
|
|
98
|
+
#---------------------------------------------------------------------------
|
|
99
|
+
|
|
100
|
+
# Access the /transcoders endpoints
|
|
101
|
+
#
|
|
102
|
+
# @return [Wsc::Endpoints::Transcoders]
|
|
103
|
+
# An instance of the Transcoders endpoint class.
|
|
104
|
+
#
|
|
105
|
+
def live_streams
|
|
106
|
+
WscSdk::Endpoints::LiveStreams.new(self)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Access the /stream_targets endpoints
|
|
110
|
+
#
|
|
111
|
+
# @return [Wsc::Endpoints::StreamTargets]
|
|
112
|
+
# An instance of the StreamTargets endpoint class.
|
|
113
|
+
#
|
|
114
|
+
def stream_targets
|
|
115
|
+
WscSdk::Endpoints::StreamTargets.new(self)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Access the /transcoders endpoints
|
|
119
|
+
#
|
|
120
|
+
# @return [Wsc::Endpoints::Transcoders]
|
|
121
|
+
# An instance of the Transcoders endpoint class.
|
|
122
|
+
#
|
|
123
|
+
def transcoders
|
|
124
|
+
WscSdk::Endpoints::Transcoders.new(self)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
#---------------------------------------------------------------------------
|
|
128
|
+
# ___ _ _ _ _ _ _
|
|
129
|
+
# | _ \___ __ _ _ _ ___ __| |_ | || |__ _ _ _ __| | (_)_ _ __ _
|
|
130
|
+
# | / -_) _` | || / -_|_-< _| | __ / _` | ' \/ _` | | | ' \/ _` |
|
|
131
|
+
# |_|_\___\__, |\_,_\___/__/\__| |_||_\__,_|_||_\__,_|_|_|_||_\__, |
|
|
132
|
+
# |_| |___/
|
|
133
|
+
#---------------------------------------------------------------------------
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
# Make a GET request against the API.
|
|
137
|
+
#
|
|
138
|
+
# @param path [String]
|
|
139
|
+
# The path to request.
|
|
140
|
+
#
|
|
141
|
+
# @param options [Hash]
|
|
142
|
+
# A hash of options.
|
|
143
|
+
#
|
|
144
|
+
def get(path, options={})
|
|
145
|
+
send_request(:get, path, options)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# Make a POST request against the API.
|
|
149
|
+
#
|
|
150
|
+
# @param path [String]
|
|
151
|
+
# The path to request.
|
|
152
|
+
#
|
|
153
|
+
# @param options [Hash]
|
|
154
|
+
# A hash of options.
|
|
155
|
+
#
|
|
156
|
+
def post(path, options={})
|
|
157
|
+
send_request(:post, path, options)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# Make a GET request against the API.
|
|
161
|
+
#
|
|
162
|
+
# @param path [String]
|
|
163
|
+
# The path to request.
|
|
164
|
+
#
|
|
165
|
+
# @param options [Hash]
|
|
166
|
+
# A hash of options.
|
|
167
|
+
#
|
|
168
|
+
def put(path, options={})
|
|
169
|
+
send_request(:put, path, options)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
# Make a GET request against the API.
|
|
173
|
+
#
|
|
174
|
+
# @param path [String]
|
|
175
|
+
# The path to request.
|
|
176
|
+
#
|
|
177
|
+
# @param options [Hash]
|
|
178
|
+
# A hash of options.
|
|
179
|
+
#
|
|
180
|
+
def patch(path, options={})
|
|
181
|
+
send_request(:patch, path, options)
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
# Make a GET request against the API.
|
|
185
|
+
#
|
|
186
|
+
# @param path [String]
|
|
187
|
+
# The path to request.
|
|
188
|
+
#
|
|
189
|
+
# @param options [Hash]
|
|
190
|
+
# A hash of options.
|
|
191
|
+
#
|
|
192
|
+
def delete(path, options={})
|
|
193
|
+
send_request(:delete, path, options)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# A generic way to request against an endpoint in the API
|
|
197
|
+
#
|
|
198
|
+
# @param method [Symbol]
|
|
199
|
+
# The method to use to formulate the request.
|
|
200
|
+
#
|
|
201
|
+
# @param path [String]
|
|
202
|
+
# The path to the endpoint. This shoudl not include the protocol, domain
|
|
203
|
+
# or base path information. Only the endpoint path itself.
|
|
204
|
+
#
|
|
205
|
+
# @param body [Hash]
|
|
206
|
+
# A Hash of payload data to send in the request. This data will not be
|
|
207
|
+
# presented in the request if it's a GET or DELETE method.
|
|
208
|
+
#
|
|
209
|
+
def request_endpoint(method, path, body={})
|
|
210
|
+
begin
|
|
211
|
+
options = {}
|
|
212
|
+
options = { body: body } unless [:get, :delete].include?(method)
|
|
213
|
+
response = send_request(method, path, options)
|
|
214
|
+
return nil if response.body.to_s.empty?
|
|
215
|
+
|
|
216
|
+
begin
|
|
217
|
+
data = JSON.parse(response.body)
|
|
218
|
+
return data
|
|
219
|
+
rescue JSON::ParserError => jpe
|
|
220
|
+
return build_exception_response(500, "Bad JSON returned by request: [#{method.to_s.upcase}] #{path}", jpe)
|
|
221
|
+
end
|
|
222
|
+
rescue Exception => e
|
|
223
|
+
# return build_exception_response(500, "Exception while requesting endpoint: [#{method.to_s.upcase}] #{path}", e)
|
|
224
|
+
raise e
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
# Builds a structured hash to respond to an exception in the request_endpoint
|
|
229
|
+
# method
|
|
230
|
+
#
|
|
231
|
+
# @param status [Integer]
|
|
232
|
+
# The status code of the response
|
|
233
|
+
#
|
|
234
|
+
# @param title [String]
|
|
235
|
+
# The title of the exception
|
|
236
|
+
#
|
|
237
|
+
# @param exception [Exception]
|
|
238
|
+
# The exception to relay in the message.
|
|
239
|
+
#
|
|
240
|
+
private def build_exception_response(status, title, exception)
|
|
241
|
+
{
|
|
242
|
+
"meta" => {
|
|
243
|
+
"status" => status,
|
|
244
|
+
"code" => "ERR-#{status}-#{exception.class.name.gsub("::", "-")}",
|
|
245
|
+
"title" => title,
|
|
246
|
+
"message" => exception.message,
|
|
247
|
+
"description" => exception.backtrace[0..5].join(" | ")
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
# Get the correct headers for an API request, including the properly formed
|
|
253
|
+
# signed authentication headers.
|
|
254
|
+
#
|
|
255
|
+
# @param request_path [String]
|
|
256
|
+
# The request path to generate the headers for.
|
|
257
|
+
#
|
|
258
|
+
# @param options [Hash]
|
|
259
|
+
# A hash of options
|
|
260
|
+
#
|
|
261
|
+
# @option options [Time] :timestamp
|
|
262
|
+
# The timestamp of the request.
|
|
263
|
+
#
|
|
264
|
+
# @option options [String] :content_type
|
|
265
|
+
# ("multipart/form-data") The content type to return in the headers.
|
|
266
|
+
#
|
|
267
|
+
# @return [Hash]
|
|
268
|
+
# A hash of request headers.
|
|
269
|
+
#
|
|
270
|
+
def generate_headers(request_path, options={})
|
|
271
|
+
timestamp = options.fetch(:timestamp, Time.now.to_i)
|
|
272
|
+
request_path = request_path.split("?").first.chomp("/")
|
|
273
|
+
data = "#{timestamp}:#{request_path}:#{api_key}"
|
|
274
|
+
signature = OpenSSL::HMAC.hexdigest("SHA256", api_key, data)
|
|
275
|
+
content_type = options.fetch(:content_type, "multipart/form-data")
|
|
276
|
+
|
|
277
|
+
{
|
|
278
|
+
'User-Agent' => WscSdk::USER_AGENT,
|
|
279
|
+
'Wsc-Access-Key' => access_key,
|
|
280
|
+
'Wsc-Timestamp' => timestamp.to_s,
|
|
281
|
+
'Wsc-Signature' => signature,
|
|
282
|
+
'Content-Type' => content_type
|
|
283
|
+
}
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
# Generate a set of request params for an API request
|
|
287
|
+
#
|
|
288
|
+
# @param options [Hash]
|
|
289
|
+
# A hash of options.
|
|
290
|
+
#
|
|
291
|
+
# @option options [Hash] :params
|
|
292
|
+
# A hash of query params or body content to be sent in the request.
|
|
293
|
+
#
|
|
294
|
+
# @option options [Hash] :pagination
|
|
295
|
+
# Pagination configuration options.
|
|
296
|
+
#
|
|
297
|
+
# @option options [Hash] :filters
|
|
298
|
+
# Filter configuration options.
|
|
299
|
+
#
|
|
300
|
+
def request_params(options={})
|
|
301
|
+
pagination = options.fetch(:pagination, nil)
|
|
302
|
+
filters = options.fetch(:filters, nil)
|
|
303
|
+
params = options.fetch(:params, {})
|
|
304
|
+
|
|
305
|
+
if pagination
|
|
306
|
+
params[:page] = pagination.fetch(:page, 1)
|
|
307
|
+
params[:per_page] = pagination.fetch(:per_page, 25)
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
if filters
|
|
311
|
+
if filters.is_a?(Hash)
|
|
312
|
+
filter_index = 0
|
|
313
|
+
filters.each do |key, value|
|
|
314
|
+
params["filter[#{filter_index}][field]"] = key
|
|
315
|
+
params["filter[#{filter_index}][eq]"] = value
|
|
316
|
+
filter_index += 1
|
|
317
|
+
end
|
|
318
|
+
end
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
params
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
# Get debug information about the client configuration
|
|
325
|
+
#
|
|
326
|
+
def info
|
|
327
|
+
{
|
|
328
|
+
access_key: ("#{access_key[0..5]}****#{access_key[-6..-1]}" rescue "invalid"),
|
|
329
|
+
api_key: ("#{api_key[0..5]}****#{api_key[-6..-1]}" rescue "invalid"),
|
|
330
|
+
base_path: base_path,
|
|
331
|
+
hostname: hostname,
|
|
332
|
+
path_version: path_version,
|
|
333
|
+
logger: (logger.class.name rescue "nil"),
|
|
334
|
+
logger_level: (logger.level rescue "nil"),
|
|
335
|
+
throttle: MAX_REQUESTS_PER_SECOND,
|
|
336
|
+
user_agent: WscSdk::USER_AGENT
|
|
337
|
+
}
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
# Send a request to the API.
|
|
341
|
+
#
|
|
342
|
+
# @param method [Symbol]
|
|
343
|
+
# The method verb for the request (:get, :post, :put, :patch, :delete)
|
|
344
|
+
#
|
|
345
|
+
# @param path [String]
|
|
346
|
+
# The API path to request.
|
|
347
|
+
#
|
|
348
|
+
# @param options [Hash]
|
|
349
|
+
# A hash of options.
|
|
350
|
+
#
|
|
351
|
+
# @option options [Hash] :params
|
|
352
|
+
# A hash of query params or body content to be sent in the request.
|
|
353
|
+
#
|
|
354
|
+
# @option options [Hash] :pagination
|
|
355
|
+
# Pagination configuration options.
|
|
356
|
+
#
|
|
357
|
+
# @option options [Hash] :filters
|
|
358
|
+
# Filter configuration options.
|
|
359
|
+
#
|
|
360
|
+
private def send_request(method, path, options={})
|
|
361
|
+
wait_time = 0
|
|
362
|
+
unless @last_request_time.nil?
|
|
363
|
+
delay_time = 1.0/MAX_REQUESTS_PER_SECOND
|
|
364
|
+
elapsed = Time.now.to_f - @last_request_time.to_f
|
|
365
|
+
wait_time = delay_time - elapsed
|
|
366
|
+
wait_time = 0 if wait_time < 0
|
|
367
|
+
sleep(wait_time) if wait_time > 0
|
|
368
|
+
end
|
|
369
|
+
@last_request_time = Time.now.to_f
|
|
370
|
+
|
|
371
|
+
data = {}
|
|
372
|
+
full_path = full_request_path(path)
|
|
373
|
+
headers = options.fetch(:headers, {})
|
|
374
|
+
content_type = headers.fetch(:content_type, "application/json")
|
|
375
|
+
|
|
376
|
+
case method.to_sym
|
|
377
|
+
when :get
|
|
378
|
+
data[:query] = request_params(options)
|
|
379
|
+
data.delete(:query) if data[:query].empty?
|
|
380
|
+
else
|
|
381
|
+
data[:body] = options[:body].to_json
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
data[:headers] = generate_headers(full_path, content_type: content_type)
|
|
385
|
+
|
|
386
|
+
logger.debug("[WSC SDK] Endpoint Request : [#{method.to_s.upcase}] #{hostname}#{full_path} #{data}")
|
|
387
|
+
|
|
388
|
+
# Send the HTTParty call for the provided method.
|
|
389
|
+
response = self.class.send(method.to_sym, full_path, data)
|
|
390
|
+
logger.debug("[WSC SDK] Endpoint Response : [#{response.code}] #{response.body} | Throttle: #{wait_time}s")
|
|
391
|
+
response
|
|
392
|
+
end
|
|
393
|
+
|
|
394
|
+
# Get an instance of the Client built using the SDK configuration object.
|
|
395
|
+
#
|
|
396
|
+
# @return [WscSdk::Client]
|
|
397
|
+
# The configured instance of the client.
|
|
398
|
+
#
|
|
399
|
+
def self.configured_instance
|
|
400
|
+
@@client_instance ||= WscSdk::Client.new
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
# Convert a file to a base64 encoded string.
|
|
404
|
+
#
|
|
405
|
+
# @param file_path [String]
|
|
406
|
+
# A valid path to a file that should be converted to base64 encoding
|
|
407
|
+
#
|
|
408
|
+
# @return [String]
|
|
409
|
+
# The base64 encoded string that represents the file.
|
|
410
|
+
#
|
|
411
|
+
# @raise []
|
|
412
|
+
def self.file_to_base64(file_path)
|
|
413
|
+
raise ArgumentError.new("Could not convert the specified file to Base64, the file couldn't be found: #{file_path}") unless File.exists?(file_path)
|
|
414
|
+
Base64.encode64(File.open(file_path, "rb").read)
|
|
415
|
+
end
|
|
416
|
+
end
|
|
417
|
+
end
|