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,21 @@
|
|
|
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 class to contain the configuration of the WscSdk::Client.
|
|
7
|
+
#
|
|
8
|
+
class Configuration
|
|
9
|
+
|
|
10
|
+
attr_accessor :api_key, :access_key, :version, :hostname, :logger
|
|
11
|
+
|
|
12
|
+
def initialize
|
|
13
|
+
@api_key = ENV["WSC_API_KEY"]
|
|
14
|
+
@access_key = ENV["WSC_API_ACCESS_KEY"]
|
|
15
|
+
@logger = ::Logger.new(STDOUT)
|
|
16
|
+
@hostname = WscSdk::HOSTNAME
|
|
17
|
+
@version = WscSdk::PATH_VERSION
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
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/version"
|
|
5
|
+
|
|
6
|
+
# Define the base SDK module.
|
|
7
|
+
#
|
|
8
|
+
module WscSdk
|
|
9
|
+
|
|
10
|
+
# The name of the SDK.
|
|
11
|
+
SDK_NAME = "Wowza Streaming Cloud SDK"
|
|
12
|
+
|
|
13
|
+
# The default version to use when generating API requests.
|
|
14
|
+
PATH_VERSION = "v" << VERSION.split(".")[0..1].join(".")
|
|
15
|
+
|
|
16
|
+
# The default hostname to use when generating API requests.
|
|
17
|
+
HOSTNAME = "https://api.cloud.wowza.com"
|
|
18
|
+
|
|
19
|
+
# The hostname of the Production server. This is an alias for
|
|
20
|
+
# WscSdk::HOSTNAME
|
|
21
|
+
PRODUCTION_HOSTNAME = HOSTNAME
|
|
22
|
+
|
|
23
|
+
# The hostname of the Sandbox server.
|
|
24
|
+
SANDBOX_HOSTNAME = "https://api-sandbox.cloud.wowza.com"
|
|
25
|
+
|
|
26
|
+
# The user agent to report when generating API requests.
|
|
27
|
+
USER_AGENT = "{\"name\": \"#{SDK_NAME}\", \"version\": \"#{WscSdk::VERSION}\", \"platform\": \"#{RUBY_PLATFORM}\", \"engine\": \"#{RUBY_ENGINE}\"}"
|
|
28
|
+
|
|
29
|
+
end
|
|
@@ -0,0 +1,492 @@
|
|
|
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
|
+
# Module for endpoint definitions.
|
|
7
|
+
#
|
|
8
|
+
module Endpoints
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# A base class for defining endpoint interactions and generating API requests.
|
|
12
|
+
#
|
|
13
|
+
class Endpoint
|
|
14
|
+
include Loggable
|
|
15
|
+
|
|
16
|
+
attr_reader :client, :parent_path
|
|
17
|
+
|
|
18
|
+
# Instantiate a new endpoint.
|
|
19
|
+
#
|
|
20
|
+
# @param [WscSdk::Client] client
|
|
21
|
+
# The client to associate with the endpoint.
|
|
22
|
+
#
|
|
23
|
+
# @param [Hash] options
|
|
24
|
+
# A hash of options
|
|
25
|
+
#
|
|
26
|
+
# @option options [String] :parent_path
|
|
27
|
+
# The parent object path to use when generating endpoint requests. This
|
|
28
|
+
# enables chaining models together in the REST pattern.
|
|
29
|
+
#
|
|
30
|
+
def initialize(client, options={})
|
|
31
|
+
@client = client
|
|
32
|
+
@parent_path = options.fetch(:parent_path, nil)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
#---------------------------------------------------------------------------
|
|
37
|
+
# _ _ _
|
|
38
|
+
# /_\ __| |_(_)___ _ _ ___
|
|
39
|
+
# / _ \/ _| _| / _ \ ' \(_-<
|
|
40
|
+
# /_/ \_\__|\__|_\___/_||_/__/
|
|
41
|
+
#
|
|
42
|
+
#---------------------------------------------------------------------------
|
|
43
|
+
|
|
44
|
+
# List all of the models for the endpoint.
|
|
45
|
+
#
|
|
46
|
+
# @param options [Hash]
|
|
47
|
+
# A hash of options
|
|
48
|
+
#
|
|
49
|
+
# @option options [Hash] :pagination
|
|
50
|
+
# Pagination configuration for the returned list.
|
|
51
|
+
#
|
|
52
|
+
# @option options [Hash] :filters
|
|
53
|
+
# Filters to be applied to the list.
|
|
54
|
+
#
|
|
55
|
+
# @return [Hash<Any,WscSdk::Model>]
|
|
56
|
+
# A hash of the models in the list, keyed by their primary key.
|
|
57
|
+
#
|
|
58
|
+
# @return [WscSdk::Models::Error]
|
|
59
|
+
# An error response if the request failed.
|
|
60
|
+
#
|
|
61
|
+
def list(options={})
|
|
62
|
+
url = list_path
|
|
63
|
+
response = client.get(url, options)
|
|
64
|
+
|
|
65
|
+
if (200..299).include?(response.code)
|
|
66
|
+
return transform_list(response.body)
|
|
67
|
+
else
|
|
68
|
+
return transform_model(response.body, model_class: WscSdk::Models::Error)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Find a specific model in the endpoint.
|
|
73
|
+
#
|
|
74
|
+
# @param id [Any]
|
|
75
|
+
# The id/primary key of the model to find.
|
|
76
|
+
#
|
|
77
|
+
def find(id)
|
|
78
|
+
response = client.get(find_path(id))
|
|
79
|
+
if (200..299).include?(response.code)
|
|
80
|
+
return transform_model(response.body)
|
|
81
|
+
else
|
|
82
|
+
return transform_model(response.body, model_class: WscSdk::Models::Error)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Refresh the data of a specific model.
|
|
87
|
+
#
|
|
88
|
+
# @param model [WscSdk::Model]
|
|
89
|
+
#
|
|
90
|
+
def refresh(model)
|
|
91
|
+
response = client.get(find_path(model.primary_key))
|
|
92
|
+
if (200..299).include?(response.code)
|
|
93
|
+
return transform_model(response.body, origin_model: model)
|
|
94
|
+
else
|
|
95
|
+
return transform_model(response.body, model_class: WscSdk::Models::Error)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Build a new instance of the model class, without committing it to the API.
|
|
100
|
+
#
|
|
101
|
+
# @param attributes [Hash]
|
|
102
|
+
# A hash of attributes to assign to the new instance.
|
|
103
|
+
#
|
|
104
|
+
# @return [WscSdk::Model]
|
|
105
|
+
# The new instance of the model.
|
|
106
|
+
#
|
|
107
|
+
def build(attributes={})
|
|
108
|
+
self.class.model.new(self, attributes)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Create a new model using the endpoint.
|
|
112
|
+
#
|
|
113
|
+
# If successful this method will directly modify the model_object that is
|
|
114
|
+
# provided, and also return a reference to that object.
|
|
115
|
+
#
|
|
116
|
+
# If the data in the model_object is not valid, then the validation messages
|
|
117
|
+
# will be updated in the errors property, and the method will return a Nil
|
|
118
|
+
# object.
|
|
119
|
+
#
|
|
120
|
+
# @param model_object [WscSdk::Model]
|
|
121
|
+
# The model object to create in the endpoint.
|
|
122
|
+
#
|
|
123
|
+
# @return [WscSdk::Model]
|
|
124
|
+
# If the newly created model is valid and returns properly from the
|
|
125
|
+
# endpoint.
|
|
126
|
+
#
|
|
127
|
+
# @return [Nil]
|
|
128
|
+
# If the newly created model is invalid.
|
|
129
|
+
#
|
|
130
|
+
def create(model_object)
|
|
131
|
+
return WscSdk::Errors.model_exists(self) unless model_object.new_model?
|
|
132
|
+
|
|
133
|
+
payload = model_object.build_payload
|
|
134
|
+
return WscSdk::Errors.invalid_attributes(self) unless model_object.valid?
|
|
135
|
+
|
|
136
|
+
response = client.post(create_path, body: payload)
|
|
137
|
+
|
|
138
|
+
if (200..299).include?(response.code)
|
|
139
|
+
return transform_model(response.body, origin_model: model_object)
|
|
140
|
+
else
|
|
141
|
+
return transform_model(response.body, model_class: WscSdk::Models::Error)
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Update an existing model in the endpoint.
|
|
146
|
+
#
|
|
147
|
+
# If the model_object's `WscSdk::Model#new_model?` call returns true, this
|
|
148
|
+
# method becomes an alias for `WscSdk::Model#create(model_object)`
|
|
149
|
+
#
|
|
150
|
+
# If successful this method will directly modify the model_object that is
|
|
151
|
+
# provided, and also return a reference to that object.
|
|
152
|
+
#
|
|
153
|
+
# If the data in the model_object is not valid, then the validation messages
|
|
154
|
+
# will be updated in the errors property, and the method will return a Nil
|
|
155
|
+
# object.
|
|
156
|
+
#
|
|
157
|
+
# @param model_object [WscSdk::Model]
|
|
158
|
+
# The model object to create in the endpoint.
|
|
159
|
+
#
|
|
160
|
+
# @return [WscSdk::Model]
|
|
161
|
+
# If the newly created model is valid and returns properly from the
|
|
162
|
+
# endpoint.
|
|
163
|
+
#
|
|
164
|
+
# @return [Nil]
|
|
165
|
+
# If the newly created model is invalid.
|
|
166
|
+
#
|
|
167
|
+
def update(model_object)
|
|
168
|
+
return WscSdk::Errors.model_does_not_exist(self) if model_object.new_model?
|
|
169
|
+
|
|
170
|
+
payload = model_object.build_payload
|
|
171
|
+
return WscSdk::Errors.invalid_attributes(self) unless model_object.valid?
|
|
172
|
+
|
|
173
|
+
response = client.put(update_path(model_object.primary_key), body: payload)
|
|
174
|
+
if (200..299).include?(response.code)
|
|
175
|
+
return transform_model(response.body, origin_model: model_object)
|
|
176
|
+
else
|
|
177
|
+
return transform_model(response.body, model_class: WscSdk::Models::Error)
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
# Delete an existing model in the endpoint.
|
|
182
|
+
#
|
|
183
|
+
# If the model_object's `WscSdk::Model#new_model?` call returns true, this
|
|
184
|
+
# method becomes an alias for `WscSdk::Model#create(model_object)`
|
|
185
|
+
#
|
|
186
|
+
# If successful this method will directly modify the model_object that is
|
|
187
|
+
# provided, and also return a reference to that object.
|
|
188
|
+
#
|
|
189
|
+
# If the data in the model_object is not valid, then the validation messages
|
|
190
|
+
# will be updated in the errors property, and the method will return a Nil
|
|
191
|
+
# object.
|
|
192
|
+
#
|
|
193
|
+
# @param model_object [WscSdk::Model]
|
|
194
|
+
# The model object to create in the endpoint.
|
|
195
|
+
#
|
|
196
|
+
# @return [WscSdk::Model]
|
|
197
|
+
# If the newly created model is valid and returns properly from the
|
|
198
|
+
# endpoint.
|
|
199
|
+
#
|
|
200
|
+
# @return [Nil]
|
|
201
|
+
# If the newly created model is invalid.
|
|
202
|
+
#
|
|
203
|
+
def delete(model_object)
|
|
204
|
+
return WscSdk::Errors.model_does_not_exist(self) if model_object.new_model?
|
|
205
|
+
|
|
206
|
+
response = client.delete(delete_path(model_object.primary_key))
|
|
207
|
+
if (200..299).include?(response.code)
|
|
208
|
+
model_object.clear_primary_key
|
|
209
|
+
return model_object
|
|
210
|
+
else
|
|
211
|
+
return transform_model(response.body, model_class: WscSdk::Models::Error)
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
#---------------------------------------------------------------------------
|
|
217
|
+
# ___ _ _
|
|
218
|
+
# | _ \__ _| |_| |_ ___
|
|
219
|
+
# | _/ _` | _| ' \(_-<
|
|
220
|
+
# |_| \__,_|\__|_||_/__/
|
|
221
|
+
#
|
|
222
|
+
#---------------------------------------------------------------------------
|
|
223
|
+
|
|
224
|
+
# Get the path for the list of models
|
|
225
|
+
#
|
|
226
|
+
# @return [String]
|
|
227
|
+
# The list path.
|
|
228
|
+
#
|
|
229
|
+
def list_path
|
|
230
|
+
[ parent_path, model_name_plural ].compact.join("/")
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
# Get the path for an individual model.
|
|
234
|
+
#
|
|
235
|
+
# @param id [Any]
|
|
236
|
+
# The unique id of the model.
|
|
237
|
+
#
|
|
238
|
+
# @return [String]
|
|
239
|
+
# The model path.
|
|
240
|
+
#
|
|
241
|
+
def model_path(id)
|
|
242
|
+
[ parent_path, model_name_plural, id ].compact.join("/")
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
# Get the path for finding an individual model
|
|
246
|
+
#
|
|
247
|
+
# @param id [Any]
|
|
248
|
+
# The unique id of the model.
|
|
249
|
+
#
|
|
250
|
+
# @return [String]
|
|
251
|
+
# The find path.
|
|
252
|
+
#
|
|
253
|
+
def find_path(id)
|
|
254
|
+
model_path(id)
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
# Get the path for creating an individual model
|
|
258
|
+
#
|
|
259
|
+
# @return [String]
|
|
260
|
+
# The create path.
|
|
261
|
+
#
|
|
262
|
+
def create_path
|
|
263
|
+
list_path
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
# Get the path for updating an individual model
|
|
267
|
+
#
|
|
268
|
+
# @param id [Any]
|
|
269
|
+
# The unique id of the model.
|
|
270
|
+
#
|
|
271
|
+
# @return [String]
|
|
272
|
+
# The update path.
|
|
273
|
+
#
|
|
274
|
+
def update_path(id)
|
|
275
|
+
model_path(id)
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
# Get the path for deleting an individual model
|
|
279
|
+
#
|
|
280
|
+
# @param id [Any]
|
|
281
|
+
# The unique id of the model.
|
|
282
|
+
#
|
|
283
|
+
# @return [String]
|
|
284
|
+
# The destroy path.
|
|
285
|
+
#
|
|
286
|
+
def delete_path(id)
|
|
287
|
+
model_path(id)
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
#---------------------------------------------------------------------------
|
|
292
|
+
# __ __ _ _ _ _ _ _ _
|
|
293
|
+
# | \/ |___ __| |___| | | || |__ _ _ _ __| | (_)_ _ __ _
|
|
294
|
+
# | |\/| / _ \/ _` / -_) | | __ / _` | ' \/ _` | | | ' \/ _` |
|
|
295
|
+
# |_| |_\___/\__,_\___|_| |_||_\__,_|_||_\__,_|_|_|_||_\__, |
|
|
296
|
+
# |___/
|
|
297
|
+
#---------------------------------------------------------------------------
|
|
298
|
+
|
|
299
|
+
# Get the plural form of the model name.
|
|
300
|
+
#
|
|
301
|
+
# @return [String]
|
|
302
|
+
# The plural form of the model name.
|
|
303
|
+
#
|
|
304
|
+
def model_name_plural
|
|
305
|
+
return nil if self.class.model.nil?
|
|
306
|
+
self.class.model.plural_name
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
# Get the singular form of the model name
|
|
310
|
+
#
|
|
311
|
+
# @return [String]
|
|
312
|
+
# The singular form of the model name
|
|
313
|
+
#
|
|
314
|
+
def model_name_singular
|
|
315
|
+
return nil if self.class.model.nil?
|
|
316
|
+
self.class.model.singular_name
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
# Transform a response payload into a list of models.
|
|
321
|
+
#
|
|
322
|
+
# @param payload [Hash]
|
|
323
|
+
# The response payload from an API request.
|
|
324
|
+
#
|
|
325
|
+
# @return [WscSdk::ModelList]
|
|
326
|
+
# The list of models
|
|
327
|
+
#
|
|
328
|
+
def transform_list(payload)
|
|
329
|
+
list = WscSdk::ModelList.new
|
|
330
|
+
begin
|
|
331
|
+
data = JSON.parse(payload).deep_symbolize_keys
|
|
332
|
+
|
|
333
|
+
data[model_name_plural.to_sym].each do |model_data|
|
|
334
|
+
model = self.class.model.new(self)
|
|
335
|
+
model.ingest_attributes(model_data, write_to_read_only: true, mark_clean: true, partial_data: true)
|
|
336
|
+
list.add(model)
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
list.pagination = data[:pagination] if data.has_key?(:pagination)
|
|
340
|
+
|
|
341
|
+
return list
|
|
342
|
+
rescue JSON::ParserError => e
|
|
343
|
+
return handle_json_error(e, payload)
|
|
344
|
+
end
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
# Transform a response payload into a model.
|
|
348
|
+
#
|
|
349
|
+
# @param payload [String]
|
|
350
|
+
# The response body from an API request.
|
|
351
|
+
#
|
|
352
|
+
# @param options [Hash]
|
|
353
|
+
# A hash of options
|
|
354
|
+
#
|
|
355
|
+
# @option options [WscSdk::Model] :model_class
|
|
356
|
+
# The class of the model to transform the payload into. This is set to
|
|
357
|
+
# then endpoints static `Endpoint#model` class that is assigned when the
|
|
358
|
+
# endpoint is built. This option is overridden if the `:origin_model`
|
|
359
|
+
# option is used.
|
|
360
|
+
#
|
|
361
|
+
# @option options [WscSdk::Model] :origin_model
|
|
362
|
+
# An existing model that is used instead of generating a new one. This
|
|
363
|
+
# model needs to be the same type of model that is represented by the
|
|
364
|
+
# payload otherwise errors may be generated. This options overrides the
|
|
365
|
+
# `:model_class` options if it's set.
|
|
366
|
+
#
|
|
367
|
+
# @return [WscSdk::Model]
|
|
368
|
+
# The model
|
|
369
|
+
#
|
|
370
|
+
def transform_model(payload, options={})
|
|
371
|
+
model_class = options.fetch(:model_class, self.class.model)
|
|
372
|
+
origin_model = options.fetch(:origin_model, nil)
|
|
373
|
+
model = nil
|
|
374
|
+
|
|
375
|
+
begin
|
|
376
|
+
data = JSON.parse(payload).deep_symbolize_keys
|
|
377
|
+
model = origin_model.nil? ? model_class.new(self) : origin_model
|
|
378
|
+
root_key = model.class.singular_name.to_sym
|
|
379
|
+
model_data = data.has_key?(root_key) ? data[root_key] : data
|
|
380
|
+
|
|
381
|
+
model.ingest_attributes(model_data, write_to_read_only: true, mark_clean: true)
|
|
382
|
+
|
|
383
|
+
return model
|
|
384
|
+
rescue JSON::ParserError => e
|
|
385
|
+
return handle_json_error(e, payload)
|
|
386
|
+
end
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
# If there is an error while attempting to parse inbound JSON, then make
|
|
390
|
+
# sure we have a uniform response mechanism.
|
|
391
|
+
#
|
|
392
|
+
# A logger error message is written with the error message.
|
|
393
|
+
# A logger debug message is written with the payload information.
|
|
394
|
+
# A WscSdk::Models::Error object is returned
|
|
395
|
+
#
|
|
396
|
+
# @param json_error (JSON::ParserError)
|
|
397
|
+
# The exception raised while parsing the JSON
|
|
398
|
+
#
|
|
399
|
+
# @param payload (String)
|
|
400
|
+
# (nil) If a payload is available, then we will log the details at a DEBUG
|
|
401
|
+
# level.
|
|
402
|
+
#
|
|
403
|
+
# @raise [WscSdk::Model::Error]
|
|
404
|
+
# Returns an error model so that the SDK can continue without interruption
|
|
405
|
+
# but details will be available, and the `.success?` test will fail.
|
|
406
|
+
#
|
|
407
|
+
def handle_json_error(json_error, payload=nil)
|
|
408
|
+
client.logger.error("Payload Invalid : #{json_error.message}")
|
|
409
|
+
client.logger.debug("Payload Data : #{payload}") if payload
|
|
410
|
+
return WscSdk::Errors.invalid_payload(self)
|
|
411
|
+
end
|
|
412
|
+
|
|
413
|
+
#---------------------------------------------------------------------------
|
|
414
|
+
# __ __
|
|
415
|
+
# | \/ |__ _ __ _ _ ___ ___
|
|
416
|
+
# | |\/| / _` / _| '_/ _ (_-<
|
|
417
|
+
# |_| |_\__,_\__|_| \___/__/
|
|
418
|
+
#---------------------------------------------------------------------------
|
|
419
|
+
|
|
420
|
+
# Define which built-in actions should be available in the endpoint.
|
|
421
|
+
#
|
|
422
|
+
# @param [Hash] config
|
|
423
|
+
# A hash of configuration options
|
|
424
|
+
#
|
|
425
|
+
# @option config [Array] :include
|
|
426
|
+
# An array of actions to keep enabled, anything not listed will be
|
|
427
|
+
# disabled.
|
|
428
|
+
#
|
|
429
|
+
# @option config [Array] :exclude
|
|
430
|
+
# An array of actions to disable. This option supercedes the :include
|
|
431
|
+
# option.
|
|
432
|
+
#
|
|
433
|
+
def self.actions config={}
|
|
434
|
+
available_actions = [:list, :find, :build, :create, :update, :delete]
|
|
435
|
+
disabled_actions = available_actions.clone
|
|
436
|
+
|
|
437
|
+
include_actions = config.fetch(:include, [])
|
|
438
|
+
include_actions = [include_actions] unless include_actions.is_a?(Array)
|
|
439
|
+
include_actions = include_actions.map{ |action| action.to_sym }
|
|
440
|
+
|
|
441
|
+
exclude_actions = config.fetch(:exclude, [])
|
|
442
|
+
exclude_actions = [exclude_actions] unless include_actions.is_a?(Array)
|
|
443
|
+
exclude_actions = exclude_actions.map{ |action| action.to_sym }
|
|
444
|
+
|
|
445
|
+
# Do the math to determine which actions should be disabled
|
|
446
|
+
disabled_actions = ((disabled_actions - include_actions) + exclude_actions).flatten.compact
|
|
447
|
+
|
|
448
|
+
# Get the intersectino of the available actions and the disabled actions
|
|
449
|
+
# to make sure that we aren't disabling unexpected actions.
|
|
450
|
+
disabled_actions = available_actions & disabled_actions
|
|
451
|
+
|
|
452
|
+
disabled_actions.each do |disabled_action|
|
|
453
|
+
define_method disabled_action.to_sym do |*args|
|
|
454
|
+
raise NoMethodError.new("the '#{disabled_action}' action is not enabled on this endpoint")
|
|
455
|
+
end
|
|
456
|
+
end
|
|
457
|
+
end
|
|
458
|
+
|
|
459
|
+
# Builds the `model` static method that returns the class of the expected
|
|
460
|
+
# model for the given endpoint.
|
|
461
|
+
#
|
|
462
|
+
# @param model_class [Class]
|
|
463
|
+
# The class of the expected model.
|
|
464
|
+
#
|
|
465
|
+
def self.model_class model_class
|
|
466
|
+
define_singleton_method :model do
|
|
467
|
+
model_class
|
|
468
|
+
end
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
# Builds additional action methods for the given model into the endpoint.
|
|
472
|
+
# this allows the endpoint functionality to be extended.
|
|
473
|
+
#
|
|
474
|
+
# @param action_name [Symbol]
|
|
475
|
+
# The name of the action to append to the endpoint path (e.g. /start)
|
|
476
|
+
#
|
|
477
|
+
# @param method [Symbol]
|
|
478
|
+
# The request action method (:get, :post, :put, :patch, :delete)
|
|
479
|
+
#
|
|
480
|
+
# @param model_class [Class]
|
|
481
|
+
# The expected model class that is retuned by the action.
|
|
482
|
+
#
|
|
483
|
+
def self.model_action(action_name, method, model_class)
|
|
484
|
+
define_method action_name.to_sym do |id|
|
|
485
|
+
response = self.client.send(method.to_sym, [find_path(id), action_name.to_s].join("/"))
|
|
486
|
+
(200..299).include?(response.code) ?
|
|
487
|
+
transform_model(response.body, model_class: model_class) :
|
|
488
|
+
transform_model(response.body, model_class: WscSdk::Models::Error)
|
|
489
|
+
end
|
|
490
|
+
end
|
|
491
|
+
end
|
|
492
|
+
end
|