# Generated by API Builder - https://www.apibuilder.io # Service version: 0.0.1 # User agent: apibuilder app.apibuilder.io/edsancha/medallia-api/0.0.1/ruby_client require 'cgi' require 'net/http' require 'net/https' require 'uri' require 'base64' require 'date' require 'rubygems' require 'json' require 'bigdecimal' # API for Medallia Surveys system module Com module Edsancha module Medallia module Api module V0 class Client module Constants BASE_URL = 'https://api-us.kampyle.com/api/v1' unless defined?(Constants::BASE_URL) NAMESPACE = 'com.edsancha.medallia.api.v0' unless defined?(Constants::NAMESPACE) USER_AGENT = 'apibuilder app.apibuilder.io/edsancha/medallia-api/0.0.1/ruby_client' unless defined?(Constants::USER_AGENT) VERSION = '0.0.1' unless defined?(Constants::VERSION) VERSION_MAJOR = 0 unless defined?(VERSION_MAJOR) end attr_reader :url def initialize(url, opts={}) @url = HttpClient::Preconditions.assert_class('url', url, String) @base_url = URI(url) @authorization = HttpClient::Preconditions.assert_class_or_nil('authorization', opts.delete(:authorization), HttpClient::Authorization) @default_headers = HttpClient::Preconditions.assert_class('default_headers', opts.delete(:default_headers) || {}, Hash) @http_handler = opts.delete(:http_handler) || HttpClient::DefaultHttpHandler.new HttpClient::Preconditions.assert_empty_opts(opts) HttpClient::Preconditions.check_state(url.match(/http.+/i), "URL[%s] must start with http" % url) end # Creates an instance of the client using the base url specified in the API spec. def Client.at_base_url(opts={}) Client.new(Constants::BASE_URL, opts) end def request(path=nil) HttpClient::Preconditions.assert_class_or_nil('path', path, String) request = HttpClient::Request.new(@http_handler, @base_url, path.to_s).with_header('User-Agent', Constants::USER_AGENT).with_header('X-Apidoc-Version', Constants::VERSION).with_header('X-Apidoc-Version-Major', Constants::VERSION_MAJOR) @default_headers.each do |key, value| request = request.with_header(key, value) end if @authorization request = request.with_auth(@authorization) end request end def access_token_wrappers @access_token_wrappers ||= ::Com::Edsancha::Medallia::Api::V0::Clients::AccessTokenWrappers.new(self) end def configurations @configurations ||= ::Com::Edsancha::Medallia::Api::V0::Clients::Configurations.new(self) end def feedbacks @feedbacks ||= ::Com::Edsancha::Medallia::Api::V0::Clients::Feedbacks.new(self) end end module Clients class AccessTokenWrappers def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Com::Edsancha::Medallia::Api::V0::Client) end # This API is used to retrieve the temporary access token that allows your app # to access all other APIs def post_access_token r = @client.request("/accessToken").post ::Com::Edsancha::Medallia::Api::V0::Models::AccessTokenWrapper.new(r) end end class Configurations def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Com::Edsancha::Medallia::Api::V0::Client) end # This API returns the full configuration as defined in the Medallia Digital # command center. It returns the list of surveys, their content and business # logic as well as targeting and segmentation rules. def get_configuration r = @client.request("/configuration").get ::Com::Edsancha::Medallia::Api::V0::Models::Configuration.new(r) end end class Feedbacks def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Com::Edsancha::Medallia::Api::V0::Client) end # This API allows the application to submit feedback collected in the app to # the Medallia Digital def post_feedback(feedback) (x = feedback; x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::Feedback) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::Feedback.new(x)) r = @client.request("/feedback").with_json(feedback.to_json).post nil end end end module Models # Represents the question or fields to be filled by the user class ComponentUnion module Types COMPONENT_LABEL = 'label' unless defined?(COMPONENT_LABEL) COMPONENT_IMAGE = 'image' unless defined?(COMPONENT_IMAGE) COMPONENT_NPS = 'nps' unless defined?(COMPONENT_NPS) COMPONENT_TEXT_AREA = 'textArea' unless defined?(COMPONENT_TEXT_AREA) COMPONENT_TEXT_INPUT = 'textInput' unless defined?(COMPONENT_TEXT_INPUT) COMPONENT_RADIO_SELECTOR = 'radio' unless defined?(COMPONENT_RADIO_SELECTOR) COMPONENT_CHECKBOX = 'checkbox' unless defined?(COMPONENT_CHECKBOX) COMPONENT_DROPDOWN = 'select' unless defined?(COMPONENT_DROPDOWN) COMPONENT_GRADING = 'grading' unless defined?(COMPONENT_GRADING) COMPONENT_GRADING0TO10 = 'grading0to10' unless defined?(COMPONENT_GRADING0TO10) COMPONENT_GRADING1TO10 = 'grading1to10' unless defined?(COMPONENT_GRADING1TO10) end attr_reader :component def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:component], 'ComponentUnion') @component = HttpClient::Preconditions.assert_class('component', opts.delete(:component), String) end def subtype_to_hash raise 'Cannot serialize an instance of component_union directly - must use one of the specific types: component_label, component_image, component_nps, component_textArea, component_textInput, component_radioSelector, component_checkbox, component_dropdown, component_grading, component_grading0to10, component_grading1to10' end def to_hash subtype_to_hash.merge(:component => @component) end def ComponentUnion.from_json(hash) HttpClient::Preconditions.assert_class('hash', hash, Hash) discriminator = HttpClient::Helper.symbolize_keys(hash)[:component].to_s.strip if discriminator.empty? raise "Union type[component_union] requires a field named 'component'" end case discriminator when Types::COMPONENT_LABEL; ComponentLabel.new(hash) when Types::COMPONENT_IMAGE; ComponentImage.new(hash) when Types::COMPONENT_NPS; ComponentNps.new(hash) when Types::COMPONENT_TEXT_AREA; ComponentTextArea.new(hash) when Types::COMPONENT_TEXT_INPUT; ComponentTextInput.new(hash) when Types::COMPONENT_RADIO_SELECTOR; ComponentRadioSelector.new(hash) when Types::COMPONENT_CHECKBOX; ComponentCheckbox.new(hash) when Types::COMPONENT_DROPDOWN; ComponentDropdown.new(hash) when Types::COMPONENT_GRADING; ComponentGrading.new(hash) when Types::COMPONENT_GRADING0TO10; ComponentGrading0to10.new(hash) when Types::COMPONENT_GRADING1TO10; ComponentGrading1to10.new(hash) else ComponentUnionUndefinedType.new(:component => discriminator) end end end class ComponentUnionUndefinedType < ComponentUnion attr_reader :name def initialize(incoming={}) super(:component => 'undefined_type') opts = HttpClient::Helper.symbolize_keys(incoming) @name = HttpClient::Preconditions.assert_class('name', opts.delete(:component), String) end def subtype_to_hash raise 'Unable to serialize undefined type to json' end def copy(incoming={}) raise 'Operation not supported for undefined type' end def to_hash raise 'Operation not supported for undefined type' end end # Represents the component or fields to be filled by the user class FeedbackUnion module Types FEEDBACK_NPS = 'nps' unless defined?(FEEDBACK_NPS) FEEDBACK_TEXT_AREA = 'textArea' unless defined?(FEEDBACK_TEXT_AREA) FEEDBACK_TEXT_INPUT = 'textInput' unless defined?(FEEDBACK_TEXT_INPUT) FEEDBACK_RADIO_SELECTOR = 'radio' unless defined?(FEEDBACK_RADIO_SELECTOR) FEEDBACK_CHECKBOX = 'checkbox' unless defined?(FEEDBACK_CHECKBOX) FEEDBACK_DROPDOWN = 'select' unless defined?(FEEDBACK_DROPDOWN) FEEDBACK_GRADING = 'grading' unless defined?(FEEDBACK_GRADING) FEEDBACK_GRADING0TO10 = 'grading0to10' unless defined?(FEEDBACK_GRADING0TO10) FEEDBACK_GRADING1TO10 = 'grading1to10' unless defined?(FEEDBACK_GRADING1TO10) end attr_reader :component def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:component], 'FeedbackUnion') @component = HttpClient::Preconditions.assert_class('component', opts.delete(:component), String) end def subtype_to_hash raise 'Cannot serialize an instance of feedback_union directly - must use one of the specific types: feedback_nps, feedback_textArea, feedback_textInput, feedback_radioSelector, feedback_checkbox, feedback_dropdown, feedback_grading, feedback_grading0to10, feedback_grading1to10' end def to_hash subtype_to_hash.merge(:component => @component) end def FeedbackUnion.from_json(hash) HttpClient::Preconditions.assert_class('hash', hash, Hash) discriminator = HttpClient::Helper.symbolize_keys(hash)[:component].to_s.strip if discriminator.empty? raise "Union type[feedback_union] requires a field named 'component'" end case discriminator when Types::FEEDBACK_NPS; FeedbackNps.new(hash) when Types::FEEDBACK_TEXT_AREA; FeedbackTextArea.new(hash) when Types::FEEDBACK_TEXT_INPUT; FeedbackTextInput.new(hash) when Types::FEEDBACK_RADIO_SELECTOR; FeedbackRadioSelector.new(hash) when Types::FEEDBACK_CHECKBOX; FeedbackCheckbox.new(hash) when Types::FEEDBACK_DROPDOWN; FeedbackDropdown.new(hash) when Types::FEEDBACK_GRADING; FeedbackGrading.new(hash) when Types::FEEDBACK_GRADING0TO10; FeedbackGrading0to10.new(hash) when Types::FEEDBACK_GRADING1TO10; FeedbackGrading1to10.new(hash) else FeedbackUnionUndefinedType.new(:component => discriminator) end end end class FeedbackUnionUndefinedType < FeedbackUnion attr_reader :name def initialize(incoming={}) super(:component => 'undefined_type') opts = HttpClient::Helper.symbolize_keys(incoming) @name = HttpClient::Preconditions.assert_class('name', opts.delete(:component), String) end def subtype_to_hash raise 'Unable to serialize undefined type to json' end def copy(incoming={}) raise 'Operation not supported for undefined type' end def to_hash raise 'Operation not supported for undefined type' end end class CompareString attr_reader :value def initialize(value) @value = HttpClient::Preconditions.assert_class('value', value, String) end # Returns the instance of CompareString for this value, creating a new instance for an unknown value def CompareString.apply(value) if value.instance_of?(CompareString) value else HttpClient::Preconditions.assert_class_or_nil('value', value, String) value.nil? ? nil : (from_string(value) || CompareString.new(value)) end end # Returns the instance of CompareString for this value, or nil if not found def CompareString.from_string(value) HttpClient::Preconditions.assert_class('value', value, String) CompareString.ALL.find { |v| v.value == value } end def CompareString.ALL @@all ||= [CompareString.greater_than, CompareString.equals, CompareString.smaller_than] end def CompareString.greater_than @@_greater_than ||= CompareString.new('greaterThan') end def CompareString.equals @@_equals ||= CompareString.new('equals') end def CompareString.smaller_than @@_smaller_than ||= CompareString.new('smallerThan') end def to_hash value end end class FormType attr_reader :value def initialize(value) @value = HttpClient::Preconditions.assert_class('value', value, String) end # Returns the instance of FormType for this value, creating a new instance for an unknown value def FormType.apply(value) if value.instance_of?(FormType) value else HttpClient::Preconditions.assert_class_or_nil('value', value, String) value.nil? ? nil : (from_string(value) || FormType.new(value)) end end # Returns the instance of FormType for this value, or nil if not found def FormType.from_string(value) HttpClient::Preconditions.assert_class('value', value, String) FormType.ALL.find { |v| v.value == value } end def FormType.ALL @@all ||= [FormType.mobile_invitation, FormType.code] end def FormType.mobile_invitation @@_mobile_invitation ||= FormType.new('mobileInvitation') end def FormType.code @@_code ||= FormType.new('code') end def to_hash value end end class RatingViewType attr_reader :value def initialize(value) @value = HttpClient::Preconditions.assert_class('value', value, String) end # Returns the instance of RatingViewType for this value, creating a new instance for an unknown value def RatingViewType.apply(value) if value.instance_of?(RatingViewType) value else HttpClient::Preconditions.assert_class_or_nil('value', value, String) value.nil? ? nil : (from_string(value) || RatingViewType.new(value)) end end # Returns the instance of RatingViewType for this value, or nil if not found def RatingViewType.from_string(value) HttpClient::Preconditions.assert_class('value', value, String) RatingViewType.ALL.find { |v| v.value == value } end def RatingViewType.ALL @@all ||= [RatingViewType.slide, RatingViewType.numbers_square, RatingViewType.grading_slider, RatingViewType.grading_dropdown, RatingViewType.stars, RatingViewType.emoticons, RatingViewType.numbers, RatingViewType.smilies, RatingViewType.bars] end def RatingViewType.slide @@_slide ||= RatingViewType.new('slide') end def RatingViewType.numbers_square @@_numbers_square ||= RatingViewType.new('numbersSquare') end def RatingViewType.grading_slider @@_grading_slider ||= RatingViewType.new('gradingSlider') end def RatingViewType.grading_dropdown @@_grading_dropdown ||= RatingViewType.new('gradingDropdown') end def RatingViewType.stars @@_stars ||= RatingViewType.new('stars') end def RatingViewType.emoticons @@_emoticons ||= RatingViewType.new('emoticons') end def RatingViewType.numbers @@_numbers ||= RatingViewType.new('numbers') end def RatingViewType.smilies @@_smilies ||= RatingViewType.new('smilies') end def RatingViewType.bars @@_bars ||= RatingViewType.new('bars') end def to_hash value end end # JWT Access Token to be used to access the APIe class AccessTokenWrapper attr_reader :accessToken def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:accessToken], 'AccessTokenWrapper') @accessToken = HttpClient::Preconditions.assert_class('accessToken', opts.delete(:accessToken), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) AccessTokenWrapper.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :accessToken => accessToken } end end class ComponentCheckbox < ComponentUnion attr_reader :index, :id, :unique_name, :required, :label, :options, :description def initialize(incoming={}) super(:component => ComponentUnion::Types::COMPONENT_CHECKBOX) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:index, :id, :unique_name, :required, :label, :options], 'ComponentCheckbox') @index = HttpClient::Preconditions.assert_class('index', opts.delete(:index), Integer) @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @unique_name = HttpClient::Preconditions.assert_class('unique_name', opts.delete(:unique_name), String) @required = HttpClient::Preconditions.assert_boolean('required', opts.delete(:required)) @label = HttpClient::Preconditions.assert_class('label', opts.delete(:label), String) @options = HttpClient::Preconditions.assert_class('options', opts.delete(:options), Array).map { |v| HttpClient::Preconditions.assert_class('options', v, String) } @description = (x = opts.delete(:description); x.nil? ? nil : HttpClient::Preconditions.assert_class('description', x, String)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) ComponentCheckbox.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def subtype_to_hash { :index => index, :id => id, :unique_name => unique_name, :required => required, :label => label, :options => options, :description => description } end end class ComponentDropdown < ComponentUnion attr_reader :index, :id, :unique_name, :required, :placeholder, :label, :options, :description def initialize(incoming={}) super(:component => ComponentUnion::Types::COMPONENT_DROPDOWN) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:index, :id, :unique_name, :required, :placeholder, :label, :options], 'ComponentDropdown') @index = HttpClient::Preconditions.assert_class('index', opts.delete(:index), Integer) @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @unique_name = HttpClient::Preconditions.assert_class('unique_name', opts.delete(:unique_name), String) @required = HttpClient::Preconditions.assert_boolean('required', opts.delete(:required)) @placeholder = HttpClient::Preconditions.assert_class('placeholder', opts.delete(:placeholder), String) @label = HttpClient::Preconditions.assert_class('label', opts.delete(:label), String) @options = HttpClient::Preconditions.assert_class('options', opts.delete(:options), Array).map { |v| HttpClient::Preconditions.assert_class('options', v, String) } @description = (x = opts.delete(:description); x.nil? ? nil : HttpClient::Preconditions.assert_class('description', x, String)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) ComponentDropdown.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def subtype_to_hash { :index => index, :id => id, :unique_name => unique_name, :required => required, :placeholder => placeholder, :label => label, :options => options, :description => description } end end class ComponentGrading < ComponentUnion attr_reader :index, :id, :unique_name, :required, :label, :ratingViewType, :description def initialize(incoming={}) super(:component => ComponentUnion::Types::COMPONENT_GRADING) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:index, :id, :unique_name, :required, :label], 'ComponentGrading') @index = HttpClient::Preconditions.assert_class('index', opts.delete(:index), Integer) @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @unique_name = HttpClient::Preconditions.assert_class('unique_name', opts.delete(:unique_name), String) @required = HttpClient::Preconditions.assert_boolean('required', opts.delete(:required)) @label = HttpClient::Preconditions.assert_class('label', opts.delete(:label), String) @ratingViewType = (x = (x = opts.delete(:ratingViewType); x.nil? ? "gradingSlider" : x); x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::RatingViewType) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::RatingViewType.apply(x)) @description = (x = opts.delete(:description); x.nil? ? nil : HttpClient::Preconditions.assert_class('description', x, String)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) ComponentGrading.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def subtype_to_hash { :index => index, :id => id, :unique_name => unique_name, :required => required, :label => label, :ratingViewType => ratingViewType.value, :description => description } end end class ComponentGrading0to10 < ComponentUnion attr_reader :index, :id, :unique_name, :required, :label, :ratingViewType, :description def initialize(incoming={}) super(:component => ComponentUnion::Types::COMPONENT_GRADING0TO10) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:index, :id, :unique_name, :required, :label], 'ComponentGrading0to10') @index = HttpClient::Preconditions.assert_class('index', opts.delete(:index), Integer) @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @unique_name = HttpClient::Preconditions.assert_class('unique_name', opts.delete(:unique_name), String) @required = HttpClient::Preconditions.assert_boolean('required', opts.delete(:required)) @label = HttpClient::Preconditions.assert_class('label', opts.delete(:label), String) @ratingViewType = (x = (x = opts.delete(:ratingViewType); x.nil? ? "gradingSlider" : x); x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::RatingViewType) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::RatingViewType.apply(x)) @description = (x = opts.delete(:description); x.nil? ? nil : HttpClient::Preconditions.assert_class('description', x, String)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) ComponentGrading0to10.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def subtype_to_hash { :index => index, :id => id, :unique_name => unique_name, :required => required, :label => label, :ratingViewType => ratingViewType.value, :description => description } end end class ComponentGrading1to10 < ComponentUnion attr_reader :index, :id, :unique_name, :required, :label, :ratingViewType, :description def initialize(incoming={}) super(:component => ComponentUnion::Types::COMPONENT_GRADING1TO10) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:index, :id, :unique_name, :required, :label], 'ComponentGrading1to10') @index = HttpClient::Preconditions.assert_class('index', opts.delete(:index), Integer) @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @unique_name = HttpClient::Preconditions.assert_class('unique_name', opts.delete(:unique_name), String) @required = HttpClient::Preconditions.assert_boolean('required', opts.delete(:required)) @label = HttpClient::Preconditions.assert_class('label', opts.delete(:label), String) @ratingViewType = (x = (x = opts.delete(:ratingViewType); x.nil? ? "gradingSlider" : x); x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::RatingViewType) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::RatingViewType.apply(x)) @description = (x = opts.delete(:description); x.nil? ? nil : HttpClient::Preconditions.assert_class('description', x, String)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) ComponentGrading1to10.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def subtype_to_hash { :index => index, :id => id, :unique_name => unique_name, :required => required, :label => label, :ratingViewType => ratingViewType.value, :description => description } end end class ComponentImage < ComponentUnion attr_reader :index, :id, :unique_name, :imageObject, :uploadedResource def initialize(incoming={}) super(:component => ComponentUnion::Types::COMPONENT_IMAGE) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:index, :id, :unique_name], 'ComponentImage') @index = HttpClient::Preconditions.assert_class('index', opts.delete(:index), Integer) @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @unique_name = HttpClient::Preconditions.assert_class('unique_name', opts.delete(:unique_name), String) @imageObject = (x = opts.delete(:imageObject); x.nil? ? nil : (x = x; x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::Image) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::Image.new(x))) @uploadedResource = (x = opts.delete(:uploadedResource); x.nil? ? nil : (x = x; x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::Image) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::Image.new(x))) end def to_json JSON.dump(to_hash) end def copy(incoming={}) ComponentImage.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def subtype_to_hash { :index => index, :id => id, :unique_name => unique_name, :imageObject => imageObject.nil? ? nil : imageObject.to_hash, :uploadedResource => uploadedResource.nil? ? nil : uploadedResource.to_hash } end end class ComponentLabel < ComponentUnion attr_reader :index, :id, :unique_name, :labelContent, :num_of_lines def initialize(incoming={}) super(:component => ComponentUnion::Types::COMPONENT_LABEL) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:index, :id, :unique_name], 'ComponentLabel') @index = HttpClient::Preconditions.assert_class('index', opts.delete(:index), Integer) @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @unique_name = HttpClient::Preconditions.assert_class('unique_name', opts.delete(:unique_name), String) @labelContent = (x = opts.delete(:labelContent); x.nil? ? nil : HttpClient::Preconditions.assert_class('labelContent', x, String)) @num_of_lines = HttpClient::Preconditions.assert_class('num_of_lines', (x = opts.delete(:num_of_lines); x.nil? ? 2 : x), Integer) end def to_json JSON.dump(to_hash) end def copy(incoming={}) ComponentLabel.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def subtype_to_hash { :index => index, :id => id, :unique_name => unique_name, :labelContent => labelContent, :num_of_lines => num_of_lines } end end class ComponentNps < ComponentUnion attr_reader :index, :id, :unique_name, :required, :label, :description, :ratingViewType def initialize(incoming={}) super(:component => ComponentUnion::Types::COMPONENT_NPS) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:index, :id, :unique_name, :required, :label], 'ComponentNps') @index = HttpClient::Preconditions.assert_class('index', opts.delete(:index), Integer) @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @unique_name = HttpClient::Preconditions.assert_class('unique_name', opts.delete(:unique_name), String) @required = HttpClient::Preconditions.assert_boolean('required', opts.delete(:required)) @label = HttpClient::Preconditions.assert_class('label', opts.delete(:label), String) @description = (x = opts.delete(:description); x.nil? ? nil : HttpClient::Preconditions.assert_class('description', x, String)) @ratingViewType = (x = (x = opts.delete(:ratingViewType); x.nil? ? "slide" : x); x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::RatingViewType) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::RatingViewType.apply(x)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) ComponentNps.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def subtype_to_hash { :index => index, :id => id, :unique_name => unique_name, :required => required, :label => label, :description => description, :ratingViewType => ratingViewType.value } end end class ComponentRadioSelector < ComponentUnion attr_reader :index, :id, :unique_name, :required, :label, :options, :description def initialize(incoming={}) super(:component => ComponentUnion::Types::COMPONENT_RADIO_SELECTOR) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:index, :id, :unique_name, :required, :label, :options], 'ComponentRadioSelector') @index = HttpClient::Preconditions.assert_class('index', opts.delete(:index), Integer) @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @unique_name = HttpClient::Preconditions.assert_class('unique_name', opts.delete(:unique_name), String) @required = HttpClient::Preconditions.assert_boolean('required', opts.delete(:required)) @label = HttpClient::Preconditions.assert_class('label', opts.delete(:label), String) @options = HttpClient::Preconditions.assert_class('options', opts.delete(:options), Array).map { |v| HttpClient::Preconditions.assert_class('options', v, String) } @description = (x = opts.delete(:description); x.nil? ? nil : HttpClient::Preconditions.assert_class('description', x, String)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) ComponentRadioSelector.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def subtype_to_hash { :index => index, :id => id, :unique_name => unique_name, :required => required, :label => label, :options => options, :description => description } end end class ComponentTextArea < ComponentUnion attr_reader :index, :id, :unique_name, :required, :placeholder, :label, :num_of_lines, :description def initialize(incoming={}) super(:component => ComponentUnion::Types::COMPONENT_TEXT_AREA) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:index, :id, :unique_name, :required, :placeholder, :label], 'ComponentTextArea') @index = HttpClient::Preconditions.assert_class('index', opts.delete(:index), Integer) @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @unique_name = HttpClient::Preconditions.assert_class('unique_name', opts.delete(:unique_name), String) @required = HttpClient::Preconditions.assert_boolean('required', opts.delete(:required)) @placeholder = HttpClient::Preconditions.assert_class('placeholder', opts.delete(:placeholder), String) @label = HttpClient::Preconditions.assert_class('label', opts.delete(:label), String) @num_of_lines = HttpClient::Preconditions.assert_class('num_of_lines', (x = opts.delete(:num_of_lines); x.nil? ? 2 : x), Integer) @description = (x = opts.delete(:description); x.nil? ? nil : HttpClient::Preconditions.assert_class('description', x, String)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) ComponentTextArea.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def subtype_to_hash { :index => index, :id => id, :unique_name => unique_name, :required => required, :placeholder => placeholder, :label => label, :num_of_lines => num_of_lines, :description => description } end end class ComponentTextInput < ComponentUnion attr_reader :index, :id, :unique_name, :required, :placeholder, :label, :max_chars, :description def initialize(incoming={}) super(:component => ComponentUnion::Types::COMPONENT_TEXT_INPUT) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:index, :id, :unique_name, :required, :placeholder, :label], 'ComponentTextInput') @index = HttpClient::Preconditions.assert_class('index', opts.delete(:index), Integer) @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @unique_name = HttpClient::Preconditions.assert_class('unique_name', opts.delete(:unique_name), String) @required = HttpClient::Preconditions.assert_boolean('required', opts.delete(:required)) @placeholder = HttpClient::Preconditions.assert_class('placeholder', opts.delete(:placeholder), String) @label = HttpClient::Preconditions.assert_class('label', opts.delete(:label), String) @max_chars = HttpClient::Preconditions.assert_class('max_chars', (x = opts.delete(:max_chars); x.nil? ? 200 : x), Integer) @description = (x = opts.delete(:description); x.nil? ? nil : HttpClient::Preconditions.assert_class('description', x, String)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) ComponentTextInput.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def subtype_to_hash { :index => index, :id => id, :unique_name => unique_name, :required => required, :placeholder => placeholder, :label => label, :max_chars => max_chars, :description => description } end end # Configuration main object, including forms class Configuration attr_reader :propertyId, :feedbackSubmitUrl, :forms def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:propertyId, :feedbackSubmitUrl, :forms], 'Configuration') @propertyId = HttpClient::Preconditions.assert_class('propertyId', opts.delete(:propertyId), Integer) @feedbackSubmitUrl = HttpClient::Preconditions.assert_class('feedbackSubmitUrl', opts.delete(:feedbackSubmitUrl), String) @forms = HttpClient::Preconditions.assert_class('forms', opts.delete(:forms), Array).map { |v| (x = v; x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::Form) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::Form.new(x)) } end def to_json JSON.dump(to_hash) end def copy(incoming={}) Configuration.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :propertyId => propertyId, :feedbackSubmitUrl => feedbackSubmitUrl, :forms => forms.map { |o| o.to_hash } } end end class DynamicData attr_reader :index, :id, :required, :component, :unique_name, :placeholder, :label, :description, :options, :imageObject def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:index, :id, :required, :component, :unique_name, :placeholder, :label], 'DynamicData') @index = HttpClient::Preconditions.assert_class('index', opts.delete(:index), Integer) @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @required = HttpClient::Preconditions.assert_boolean('required', opts.delete(:required)) @component = HttpClient::Preconditions.assert_class('component', opts.delete(:component), String) @unique_name = HttpClient::Preconditions.assert_class('unique_name', opts.delete(:unique_name), String) @placeholder = HttpClient::Preconditions.assert_class('placeholder', opts.delete(:placeholder), String) @label = HttpClient::Preconditions.assert_class('label', opts.delete(:label), String) @description = (x = opts.delete(:description); x.nil? ? nil : HttpClient::Preconditions.assert_class('description', x, String)) @options = (x = opts.delete(:options); x.nil? ? nil : HttpClient::Preconditions.assert_class('options', x, Array).map { |v| HttpClient::Preconditions.assert_class('options', v, String) }) @imageObject = (x = opts.delete(:imageObject); x.nil? ? nil : (x = x; x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::Image) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::Image.new(x))) end def to_json JSON.dump(to_hash) end def copy(incoming={}) DynamicData.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :index => index, :id => id, :required => required, :component => component, :unique_name => unique_name, :placeholder => placeholder, :label => label, :description => description, :options => options.nil? ? nil : options, :imageObject => imageObject.nil? ? nil : imageObject.to_hash } end end # Feedback main object with survey's results class Feedback attr_reader :formId, :dynamicData def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:formId, :dynamicData], 'Feedback') @formId = HttpClient::Preconditions.assert_class('formId', opts.delete(:formId), Integer) @dynamicData = (x = opts.delete(:dynamicData); x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::FeedbackData) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::FeedbackData.new(x)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) Feedback.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :formId => formId, :dynamicData => dynamicData.to_hash } end end class FeedbackCheckbox < FeedbackUnion attr_reader :index, :id, :unique_name, :value, :type def initialize(incoming={}) super(:component => FeedbackUnion::Types::FEEDBACK_CHECKBOX) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:index, :id, :unique_name, :value], 'FeedbackCheckbox') @index = HttpClient::Preconditions.assert_class('index', opts.delete(:index), Integer) @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @unique_name = HttpClient::Preconditions.assert_class('unique_name', opts.delete(:unique_name), String) @value = HttpClient::Preconditions.assert_class('value', opts.delete(:value), Array).map { |v| HttpClient::Preconditions.assert_class('value', v, Integer) } @type = HttpClient::Preconditions.assert_class('type', (x = opts.delete(:type); x.nil? ? "checkbox" : x), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) FeedbackCheckbox.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def subtype_to_hash { :index => index, :id => id, :unique_name => unique_name, :value => value, :type => type } end end # Object that will hold the form pages and custom parameters. class FeedbackData attr_reader :customParams, :pages def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:pages], 'FeedbackData') @customParams = (x = opts.delete(:customParams); x.nil? ? nil : HttpClient::Preconditions.assert_class('customParams', x, BasicObject)) @pages = HttpClient::Preconditions.assert_class('pages', opts.delete(:pages), Array).map { |v| (x = v; x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::FeedbackPage) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::FeedbackPage.new(x)) } end def to_json JSON.dump(to_hash) end def copy(incoming={}) FeedbackData.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :customParams => customParams, :pages => pages.map { |o| o.to_hash } } end end class FeedbackDropdown < FeedbackUnion attr_reader :index, :id, :unique_name, :value, :type def initialize(incoming={}) super(:component => FeedbackUnion::Types::FEEDBACK_DROPDOWN) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:index, :id, :unique_name, :value], 'FeedbackDropdown') @index = HttpClient::Preconditions.assert_class('index', opts.delete(:index), Integer) @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @unique_name = HttpClient::Preconditions.assert_class('unique_name', opts.delete(:unique_name), String) @value = HttpClient::Preconditions.assert_class('value', opts.delete(:value), Integer) @type = HttpClient::Preconditions.assert_class('type', (x = opts.delete(:type); x.nil? ? "select" : x), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) FeedbackDropdown.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def subtype_to_hash { :index => index, :id => id, :unique_name => unique_name, :value => value, :type => type } end end class FeedbackGrading < FeedbackUnion attr_reader :index, :id, :unique_name, :value, :type def initialize(incoming={}) super(:component => FeedbackUnion::Types::FEEDBACK_GRADING) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:index, :id, :unique_name, :value], 'FeedbackGrading') @index = HttpClient::Preconditions.assert_class('index', opts.delete(:index), Integer) @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @unique_name = HttpClient::Preconditions.assert_class('unique_name', opts.delete(:unique_name), String) @value = HttpClient::Preconditions.assert_class('value', opts.delete(:value), Integer) @type = HttpClient::Preconditions.assert_class('type', (x = opts.delete(:type); x.nil? ? "grading" : x), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) FeedbackGrading.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def subtype_to_hash { :index => index, :id => id, :unique_name => unique_name, :value => value, :type => type } end end class FeedbackGrading0to10 < FeedbackUnion attr_reader :index, :id, :unique_name, :value, :type def initialize(incoming={}) super(:component => FeedbackUnion::Types::FEEDBACK_GRADING0TO10) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:index, :id, :unique_name, :value], 'FeedbackGrading0to10') @index = HttpClient::Preconditions.assert_class('index', opts.delete(:index), Integer) @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @unique_name = HttpClient::Preconditions.assert_class('unique_name', opts.delete(:unique_name), String) @value = HttpClient::Preconditions.assert_class('value', opts.delete(:value), Integer) @type = HttpClient::Preconditions.assert_class('type', (x = opts.delete(:type); x.nil? ? "grading0to10" : x), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) FeedbackGrading0to10.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def subtype_to_hash { :index => index, :id => id, :unique_name => unique_name, :value => value, :type => type } end end class FeedbackGrading1to10 < FeedbackUnion attr_reader :index, :id, :unique_name, :value, :type def initialize(incoming={}) super(:component => FeedbackUnion::Types::FEEDBACK_GRADING1TO10) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:index, :id, :unique_name, :value], 'FeedbackGrading1to10') @index = HttpClient::Preconditions.assert_class('index', opts.delete(:index), Integer) @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @unique_name = HttpClient::Preconditions.assert_class('unique_name', opts.delete(:unique_name), String) @value = HttpClient::Preconditions.assert_class('value', opts.delete(:value), Integer) @type = HttpClient::Preconditions.assert_class('type', (x = opts.delete(:type); x.nil? ? "grading1to10" : x), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) FeedbackGrading1to10.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def subtype_to_hash { :index => index, :id => id, :unique_name => unique_name, :value => value, :type => type } end end class FeedbackNps < FeedbackUnion attr_reader :index, :id, :unique_name, :value, :type def initialize(incoming={}) super(:component => FeedbackUnion::Types::FEEDBACK_NPS) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:index, :id, :unique_name, :value], 'FeedbackNps') @index = HttpClient::Preconditions.assert_class('index', opts.delete(:index), Integer) @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @unique_name = HttpClient::Preconditions.assert_class('unique_name', opts.delete(:unique_name), String) @value = HttpClient::Preconditions.assert_class('value', opts.delete(:value), Integer) @type = HttpClient::Preconditions.assert_class('type', (x = opts.delete(:type); x.nil? ? "nps" : x), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) FeedbackNps.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def subtype_to_hash { :index => index, :id => id, :unique_name => unique_name, :value => value, :type => type } end end # Object that will hold the form page class FeedbackPage attr_reader :components def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:components], 'FeedbackPage') @components = HttpClient::Preconditions.assert_class('components', opts.delete(:components), Array).map { |v| (x = v; x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::FeedbackUnion) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::FeedbackUnion.from_json(x)) } end def to_json JSON.dump(to_hash) end def copy(incoming={}) FeedbackPage.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :components => components.map { |o| o.to_hash } } end end class FeedbackRadioSelector < FeedbackUnion attr_reader :index, :id, :unique_name, :value, :type def initialize(incoming={}) super(:component => FeedbackUnion::Types::FEEDBACK_RADIO_SELECTOR) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:index, :id, :unique_name, :value], 'FeedbackRadioSelector') @index = HttpClient::Preconditions.assert_class('index', opts.delete(:index), Integer) @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @unique_name = HttpClient::Preconditions.assert_class('unique_name', opts.delete(:unique_name), String) @value = HttpClient::Preconditions.assert_class('value', opts.delete(:value), Integer) @type = HttpClient::Preconditions.assert_class('type', (x = opts.delete(:type); x.nil? ? "radio" : x), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) FeedbackRadioSelector.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def subtype_to_hash { :index => index, :id => id, :unique_name => unique_name, :value => value, :type => type } end end class FeedbackTextArea < FeedbackUnion attr_reader :index, :id, :unique_name, :value, :type def initialize(incoming={}) super(:component => FeedbackUnion::Types::FEEDBACK_TEXT_AREA) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:index, :id, :unique_name, :value], 'FeedbackTextArea') @index = HttpClient::Preconditions.assert_class('index', opts.delete(:index), Integer) @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @unique_name = HttpClient::Preconditions.assert_class('unique_name', opts.delete(:unique_name), String) @value = HttpClient::Preconditions.assert_class('value', opts.delete(:value), String) @type = HttpClient::Preconditions.assert_class('type', (x = opts.delete(:type); x.nil? ? "textArea" : x), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) FeedbackTextArea.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def subtype_to_hash { :index => index, :id => id, :unique_name => unique_name, :value => value, :type => type } end end class FeedbackTextInput < FeedbackUnion attr_reader :index, :id, :unique_name, :value, :type def initialize(incoming={}) super(:component => FeedbackUnion::Types::FEEDBACK_TEXT_INPUT) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:index, :id, :unique_name, :value], 'FeedbackTextInput') @index = HttpClient::Preconditions.assert_class('index', opts.delete(:index), Integer) @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @unique_name = HttpClient::Preconditions.assert_class('unique_name', opts.delete(:unique_name), String) @value = HttpClient::Preconditions.assert_class('value', opts.delete(:value), String) @type = HttpClient::Preconditions.assert_class('type', (x = opts.delete(:type); x.nil? ? "textInput" : x), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) FeedbackTextInput.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def subtype_to_hash { :index => index, :id => id, :unique_name => unique_name, :value => value, :type => type } end end class Form attr_reader :formId, :name, :title, :formType, :inviteData, :triggerData, :formJson def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:formId, :name, :title, :formType, :formJson], 'Form') @formId = HttpClient::Preconditions.assert_class('formId', opts.delete(:formId), Integer) @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String) @title = HttpClient::Preconditions.assert_class('title', opts.delete(:title), String) @formType = (x = opts.delete(:formType); x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::FormType) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::FormType.apply(x)) @inviteData = (x = opts.delete(:inviteData); x.nil? ? nil : (x = x; x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::InviteData) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::InviteData.new(x))) @triggerData = (x = opts.delete(:triggerData); x.nil? ? nil : (x = x; x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::TriggerData) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::TriggerData.new(x))) @formJson = (x = opts.delete(:formJson); x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::FormJson) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::FormJson.new(x)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) Form.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :formId => formId, :name => name, :title => title, :formType => formType.value, :inviteData => inviteData.nil? ? nil : inviteData.to_hash, :triggerData => triggerData.nil? ? nil : triggerData.to_hash, :formJson => formJson.to_hash } end end class FormJson attr_reader :pages def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:pages], 'FormJson') @pages = HttpClient::Preconditions.assert_class('pages', opts.delete(:pages), Array).map { |v| (x = v; x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::Page) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::Page.new(x)) } end def to_json JSON.dump(to_hash) end def copy(incoming={}) FormJson.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :pages => pages.map { |o| o.to_hash } } end end class Image attr_reader :name, :url def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:name, :url], 'Image') @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String) @url = HttpClient::Preconditions.assert_class('url', opts.delete(:url), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) Image.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :name => name, :url => url } end end class InviteData attr_reader :invitationHeadline, :invitationText, :provideButtonText, :declineButtonText, :laterButtonText def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:invitationHeadline, :invitationText, :provideButtonText, :declineButtonText, :laterButtonText], 'InviteData') @invitationHeadline = HttpClient::Preconditions.assert_class('invitationHeadline', opts.delete(:invitationHeadline), String) @invitationText = HttpClient::Preconditions.assert_class('invitationText', opts.delete(:invitationText), String) @provideButtonText = HttpClient::Preconditions.assert_class('provideButtonText', opts.delete(:provideButtonText), String) @declineButtonText = HttpClient::Preconditions.assert_class('declineButtonText', opts.delete(:declineButtonText), String) @laterButtonText = HttpClient::Preconditions.assert_class('laterButtonText', opts.delete(:laterButtonText), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) InviteData.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :invitationHeadline => invitationHeadline, :invitationText => invitationText, :provideButtonText => provideButtonText, :declineButtonText => declineButtonText, :laterButtonText => laterButtonText } end end class NumberOfAppSession attr_reader :number, :compareString def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:number, :compareString], 'NumberOfAppSession') @number = HttpClient::Preconditions.assert_class('number', opts.delete(:number), String) @compareString = (x = opts.delete(:compareString); x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::CompareString) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::CompareString.apply(x)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) NumberOfAppSession.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :number => number, :compareString => compareString.value } end end class NumberOfDays attr_reader :days def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:days], 'NumberOfDays') @days = HttpClient::Preconditions.assert_class('days', opts.delete(:days), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) NumberOfDays.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :days => days } end end class Page attr_reader :name, :index, :dynamicData def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:name, :dynamicData], 'Page') @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String) @index = HttpClient::Preconditions.assert_class('index', (x = opts.delete(:index); x.nil? ? 0 : x), Integer) @dynamicData = HttpClient::Preconditions.assert_class('dynamicData', opts.delete(:dynamicData), Array).map { |v| (x = v; x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::ComponentUnion) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::ComponentUnion.from_json(x)) } end def to_json JSON.dump(to_hash) end def copy(incoming={}) Page.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :name => name, :index => index, :dynamicData => dynamicData.map { |o| o.to_hash } } end end class PercentageOfSessions attr_reader :prec def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:prec], 'PercentageOfSessions') @prec = HttpClient::Preconditions.assert_class('prec', opts.delete(:prec), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) PercentageOfSessions.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :prec => prec } end end class TimeInForeground attr_reader :time, :compareString def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:time, :compareString], 'TimeInForeground') @time = HttpClient::Preconditions.assert_class('time', opts.delete(:time), String) @compareString = (x = opts.delete(:compareString); x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::CompareString) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::CompareString.apply(x)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) TimeInForeground.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :time => time, :compareString => compareString.value } end end class TriggerData attr_reader :numberOfAppSession, :timeInForeground, :mobileappVersion, :submitted, :declined, :mobileosVersion, :percentageOfSessions, :genericRule def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) @numberOfAppSession = (x = opts.delete(:numberOfAppSession); x.nil? ? nil : (x = x; x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::NumberOfAppSession) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::NumberOfAppSession.new(x))) @timeInForeground = (x = opts.delete(:timeInForeground); x.nil? ? nil : (x = x; x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::TimeInForeground) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::TimeInForeground.new(x))) @mobileappVersion = (x = opts.delete(:mobileappVersion); x.nil? ? nil : HttpClient::Preconditions.assert_class('mobileappVersion', x, Array).map { |v| HttpClient::Preconditions.assert_class('mobileappVersion', v, String) }) @submitted = (x = opts.delete(:submitted); x.nil? ? nil : (x = x; x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::NumberOfDays) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::NumberOfDays.new(x))) @declined = (x = opts.delete(:declined); x.nil? ? nil : (x = x; x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::NumberOfDays) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::NumberOfDays.new(x))) @mobileosVersion = (x = opts.delete(:mobileosVersion); x.nil? ? nil : HttpClient::Preconditions.assert_class('mobileosVersion', x, Array).map { |v| HttpClient::Preconditions.assert_class('mobileosVersion', v, String) }) @percentageOfSessions = (x = opts.delete(:percentageOfSessions); x.nil? ? nil : (x = x; x.is_a?(::Com::Edsancha::Medallia::Api::V0::Models::PercentageOfSessions) ? x : ::Com::Edsancha::Medallia::Api::V0::Models::PercentageOfSessions.new(x))) @genericRule = (x = opts.delete(:genericRule); x.nil? ? nil : HttpClient::Preconditions.assert_class('genericRule', x, String)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) TriggerData.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :numberOfAppSession => numberOfAppSession.nil? ? nil : numberOfAppSession.to_hash, :timeInForeground => timeInForeground.nil? ? nil : timeInForeground.to_hash, :mobileappVersion => mobileappVersion.nil? ? nil : mobileappVersion, :submitted => submitted.nil? ? nil : submitted.to_hash, :declined => declined.nil? ? nil : declined.to_hash, :mobileosVersion => mobileosVersion.nil? ? nil : mobileosVersion, :percentageOfSessions => percentageOfSessions.nil? ? nil : percentageOfSessions.to_hash, :genericRule => genericRule } end end end # ===== END OF SERVICE DEFINITION ===== module HttpClient class HttpHandler # Returns a client instance to use # # @param base_uri The base URI for this API # @param path the Requested full http path (including any query strings) def instance(base_uri, path) raise "Override in subclass" end end class HttpHandlerInstance # Executes a request. The provided request object will be an # instance of Net::HTTP (e.g. Net::HTTP::Get) def execute(request) raise "Override in subclass" end end class DefaultHttpHandler < HttpHandler def instance(base_uri, path) DefaultHttpHandlerInstance.new(base_uri) end end class DefaultHttpHandlerInstance < HttpHandlerInstance attr_reader :client def initialize(base_uri) @base_uri = Preconditions.assert_class('base_uri', base_uri, URI) @client = Net::HTTP.new(@base_uri.host, @base_uri.port) if @base_uri.scheme == "https" configure_ssl end end def execute(request) response = begin @client.request(request) rescue SocketError => e raise StandardError.new("Error accessing uri[#{full_uri(request.path)}]: #{e}") end case response when Net::HTTPSuccess response.body else body = response.body rescue nil raise HttpClient::ServerError.new(response.code.to_i, response.message, :body => body, :uri => full_uri(request.path).to_s) end end def full_uri(path) path.start_with?(@base_uri.to_s) ? path : File.join(@base_uri.to_s, path) end # Called to configure SSL if the base uri requires it def configure_ssl @client.use_ssl = true @client.verify_mode = OpenSSL::SSL::VERIFY_PEER @client.cert_store = OpenSSL::X509::Store.new @client.cert_store.set_default_paths end end class Request attr_reader :base_uri, :path, :full_uri def initialize(http_handler, base_uri, path) @http_handler = http_handler @base_uri = Preconditions.assert_class('base_uri', base_uri, URI) @path = Preconditions.assert_class('path', path, String) @full_uri = @base_uri.to_s + @path @params = nil @body = nil @auth = nil @headers = {} @header_keys_lower_case = [] end def with_header(name, value) Preconditions.check_not_blank('name', name, "Header name is required") Preconditions.check_not_blank('value', value, "Header value is required") Preconditions.check_state(!@headers.has_key?(name), "Duplicate header named[%s]" % name) @headers[name] = value @header_keys_lower_case << name.downcase self end def with_auth(auth) Preconditions.assert_class('auth', auth, HttpClient::Authorization) Preconditions.check_state(@auth.nil?, "auth previously set") if auth.scheme.name == AuthScheme::BASIC.name @auth = auth else raise "Auth Scheme[#{auth.scheme.name}] not supported" end self end def with_query(params) Preconditions.assert_class('params', params, Hash) Preconditions.check_state(@params.nil?, "Already have query parameters") @params = params self end # Wrapper to set Content-Type header to application/json and set # the provided json document as the body def with_json(json) @headers['Content-Type'] ||= 'application/json; charset=UTF-8' with_body(json) end def with_body(body) Preconditions.check_not_blank('body', body) @body = body self end def get(&block) do_request(Net::HTTP::Get, &block) end def delete(&block) do_request(Net::HTTP::Delete, &block) end def options(&block) do_request(Net::HTTP::Options, &block) end def post(&block) do_request(Net::HTTP::Post, &block) end def put(&block) do_request(Net::HTTP::Put, &block) end class PATCH < Net::HTTP::Put METHOD = "PATCH" end def patch(&block) do_request(PATCH, &block) end def do_request(klass) Preconditions.assert_class('klass', klass, Class) uri = @full_uri.dup if q = to_query(@params) uri += "?%s" % q end request = klass.send(:new, uri) # DEBUG curl = ['curl'] # DEBUG if klass != Net::HTTP::Get # DEBUG curl << "-X%s" % klass.name.split("::").last.upcase # DEBUG end if @body # DEBUG tmpfile = "/tmp/rest_client.tmp" # DEBUG File.open(tmpfile, "w") { |os| os << @body.to_s } # DEBUG curl << "-d@%s" % tmpfile request.body = @body end if @auth # DEBUG curl << "-u \"%s:%s\"" % [@auth.username, @auth.password] Preconditions.check_state(!@header_keys_lower_case.include?("authorization"), "Cannot specify both an Authorization header and an auth instance") user_pass = "%s:%s" % [@auth.username, @auth.password] encoded = Base64.encode64(user_pass).to_s.split("\n").map(&:strip).join request.add_field("Authorization", "Basic %s" % encoded) end @headers.each { |key, value| # DEBUG curl << "-H \"%s: %s\"" % [key, value] request.add_field(key, value) } # DEBUG curl << "'%s%s'" % [@base_uri, path] # DEBUG puts curl.join(" ") raw_response = @http_handler.instance(@base_uri, request.path).execute(request) response = raw_response.to_s == "" ? nil : JSON.parse(raw_response) if block_given? yield response else response end end private def to_query(params={}) parts = (params || {}).map { |k,v| if v.is_a?(Enumerable) v.map { |el| "%s=%s" % [k, CGI.escape(el.to_s)] } else "%s=%s" % [k, CGI.escape(v.to_s)] end } parts.empty? ? nil : parts.join("&") end end class ServerError < StandardError attr_reader :code, :details, :body, :uri def initialize(code, details, incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) @code = HttpClient::Preconditions.assert_class('code', code, Integer) @details = HttpClient::Preconditions.assert_class('details', details, String) @body = HttpClient::Preconditions.assert_class_or_nil('body', opts.delete(:body), String) @uri = HttpClient::Preconditions.assert_class_or_nil('uri', opts.delete(:uri), String) HttpClient::Preconditions.assert_empty_opts(opts) super(self.message) end def message m = "%s %s" % [@code, @details] if @body m << ": %s" % @body end m end def body_json @body ? JSON.parse(@body) : nil end end class PreconditionException < StandardError attr_reader :message def initialize(message) super(message) @message = message end end module Preconditions def Preconditions.check_argument(expression, error_message=nil) if !expression raise PreconditionException.new(error_message || "check_argument failed") end nil end def Preconditions.check_state(expression, error_message=nil) if !expression raise PreconditionException.new(error_message || "check_state failed") end nil end def Preconditions.check_not_nil(field_name, reference, error_message=nil) if reference.nil? raise PreconditionException.new(error_message || "argument for %s cannot be nil" % field_name) end reference end def Preconditions.check_not_blank(field_name, reference, error_message=nil) if reference.to_s.strip == "" raise PreconditionException.new(error_message || "argument for %s cannot be blank" % field_name) end reference end # Throws an error if opts is not empty. Useful when parsing # arguments to a function def Preconditions.assert_empty_opts(opts) if !opts.empty? raise PreconditionException.new("Invalid opts: #{opts.keys.inspect}\n#{opts.inspect}") end end # Requires that the provided hash has the specified keys. # @param fields A list of symbols def Preconditions.require_keys(hash, fields, error_prefix=nil) missing = fields.select { |f| !hash.has_key?(f) } if !missing.empty? msg = "Missing required fields: " + missing.join(", ") raise PreconditionException.new(error_prefix.empty? ? msg : "#{error_prefix}: #{msg}") end end # Asserts that value is not nill and is_?(klass). Returns # value. Common use is # # amount = Preconditions.assert_class('amount', amount, BigDecimal) def Preconditions.assert_class(field_name, value, klass) Preconditions.check_not_nil('field_name', field_name) Preconditions.check_not_nil('klass', klass) Preconditions.check_not_nil('value', value, "Value for %s cannot be nil. Expected an instance of class %s" % [field_name, klass.name]) Preconditions.check_state(value.is_a?(klass), "Value for #{field_name} is of type[#{value.class}] - class[#{klass}] is required. value[#{value.inspect.to_s}]") value end def Preconditions.assert_class_or_nil(field_name, value, klass) if !value.nil? Preconditions.assert_class(field_name, value, klass) end end def Preconditions.assert_boolean(field_name, value) Preconditions.check_not_nil('field_name', field_name) Preconditions.check_not_nil('value', value, "Value for %s cannot be nil. Expected an instance of TrueClass or FalseClass" % field_name) Preconditions.check_state(value.is_a?(TrueClass) || value.is_a?(FalseClass), "Value for #{field_name} is of type[#{value.class}] - class[TrueClass or FalseClass] is required. value[#{value.inspect.to_s}]") value end def Preconditions.assert_boolean_or_nil(field_name, value) if !value.nil? Preconditions.assert_boolean(field_name, value) end end def Preconditions.assert_collection_of_class(field_name, values, klass) Preconditions.assert_class(field_name, values, Array) values.each { |v| Preconditions.assert_class(field_name, v, klass) } end def Preconditions.assert_hash_of_class(field_name, hash, klass) Preconditions.assert_class(field_name, hash, Hash) values.each { |k, v| Preconditions.assert_class(field_name, v, klass) } end end class AuthScheme attr_reader :name def initialize(name) @name = HttpClient::Preconditions.check_not_blank('name', name) end BASIC = AuthScheme.new("basic") unless defined?(BASIC) end class Authorization attr_reader :scheme, :username, :password def initialize(scheme, username, opts={}) @scheme = HttpClient::Preconditions.assert_class('schema', scheme, AuthScheme) @username = HttpClient::Preconditions.check_not_blank('username', username, "username is required") @password = HttpClient::Preconditions.assert_class_or_nil('password', opts.delete(:password), String) HttpClient::Preconditions.assert_empty_opts(opts) end def Authorization.basic(username, password=nil) Authorization.new(AuthScheme::BASIC, username, :password => password) end end module Helper def Helper.symbolize_keys(hash) Preconditions.assert_class('hash', hash, Hash) new_hash = {} hash.each { |k, v| new_hash[k.to_sym] = v } new_hash end def Helper.to_big_decimal(value) value ? BigDecimal(value.to_s) : nil end def Helper.to_object(value) value ? (value.is_a?(Hash) ? value : JSON.parse(value)) : nil end def Helper.to_uuid(value) Preconditions.check_state(value.nil? || value.match(/^\w\w\w\w\w\w\w\w\-\w\w\w\w\-\w\w\w\w\-\w\w\w\w\-\w\w\w\w\w\w\w\w\w\w\w\w$/), "Invalid guid[%s]" % value) value end def Helper.to_date_iso8601(value) if value.is_a?(Date) value elsif value Date.parse(value.to_s) else nil end end def Helper.to_date_time_iso8601(value) if value.is_a?(DateTime) value elsif value DateTime.parse(value.to_s) else nil end end def Helper.date_iso8601_to_string(value) value.nil? ? nil : value.strftime('%Y-%m-%d') end def Helper.date_time_iso8601_to_string(value) value.nil? ? nil : value.strftime('%Y-%m-%dT%H:%M:%S%z') end TRUE_STRINGS = ['t', 'true', 'y', 'yes', 'on', '1', 'trueclass'] unless defined?(TRUE_STRINGS) FALSE_STRINGS = ['f', 'false', 'n', 'no', 'off', '0', 'falseclass'] unless defined?(FALSE_STRINGS) def Helper.to_boolean(field_name, value) string = value.to_s.strip.downcase if TRUE_STRINGS.include?(string) true elsif FALSE_STRINGS.include?(string) false elsif string != "" raise PreconditionException.new("Unsupported boolean value[#{string}]. For true, must be one of: #{TRUE_STRINGS.inspect}. For false, must be one of: #{FALSE_STRINGS.inspect}") else nil end end end end end end end end end