diff --git a/Dockerfile b/Dockerfile index bf5d779b..5fc0f6d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ WORKDIR /app COPY . . RUN gem build VoucherifySdk.gemspec -RUN gem install voucherify-5.0.0.gem +RUN gem install voucherify-5.0.1.gem RUN gem install dotenv RUN gem install rspec diff --git a/EXAMPLES.md b/EXAMPLES.md index e5943882..662f9baf 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -67,15 +67,15 @@ gem build VoucherifySdk.gemspec Then either install the gem locally: ```shell -gem install ./VoucherifySdk-1.0.0.gem +gem install ./VoucherifySdk-5.0.1.gem ``` -(for development, run `gem install --dev ./VoucherifySdk-1.0.0.gem` to install the development dependencies) +(for development, run `gem install --dev ./VoucherifySdk-5.0.1.gem` to install the development dependencies) Add this to the Gemfile: ```shell -gem 'VoucherifySdk', '~> 1.0.0' +gem 'VoucherifySdk', '~> 5.0.1' ``` Then install dependencies with bundler diff --git a/README.md b/README.md index b9d09439..90227d80 100644 --- a/README.md +++ b/README.md @@ -111,11 +111,13 @@ Read more about how to Contribute to Voucherify Ruby SDK by visiting main repo [ Remember that this SDK is auto generated (except of the tests) so changes made here will be overwritten by generator. -## Changelog +## 📅 Changelog -- **2022-03-11** - `5.0.0` - The new version of the SKD includes coverage for all the most commonly used Voucherify endpoints and supports typed models. +- **2024-05-08** - `5.0.1` - Added support for [Create validation rule assignment](https://docs.voucherify.io/reference/create-validation-rule-assignment) -*Previous versions of the API are no longer supported, and we highly recommend upgrading to version 5.0.0, which is now designated as Long-Term Support (LTS).* +- **2024-03-11** - `5.0.0` - The new version of the SKD includes coverage for all the most commonly used Voucherify endpoints and supports typed models. + +*Previous versions of the API are no longer supported, and we highly recommend upgrading to version 5.0.0, which is now designated as Long-Term Support (LTS).* *Changelog for previous versions could be found in the [CHANGELOG.md file](./CHANGELOG.md)* @@ -262,6 +264,7 @@ Class | Method | HTTP request | Description *VoucherifySdk::RewardsApi* | [**list_reward_assignments**](docs/RewardsApi.md#list_reward_assignments) | **GET** /v1/rewards/{rewardId}/assignments | List Reward Assignments *VoucherifySdk::RewardsApi* | [**update_reward_assignment**](docs/RewardsApi.md#update_reward_assignment) | **PUT** /v1/rewards/{rewardId}/assignments/{assignmentId} | Update Reward Assignment *VoucherifySdk::SegmentsApi* | [**delete_segment**](docs/SegmentsApi.md#delete_segment) | **DELETE** /v1/segments/{segmentId} | Delete Segment +*VoucherifySdk::ValidationRulesApi* | [**create_validation_rule_assignment**](docs/ValidationRulesApi.md#create_validation_rule_assignment) | **POST** /v1/validation-rules/{validationRuleId}/assignments | Create Validation Rules Assignments *VoucherifySdk::ValidationRulesApi* | [**create_validation_rules**](docs/ValidationRulesApi.md#create_validation_rules) | **POST** /v1/validation-rules | Create Validation Rules *VoucherifySdk::ValidationRulesApi* | [**delete_validation_rule_assignment**](docs/ValidationRulesApi.md#delete_validation_rule_assignment) | **DELETE** /v1/validation-rules/{validationRuleId}/assignments/{assignmentId} | Delete Validation Rule Assignment *VoucherifySdk::ValidationRulesApi* | [**delete_validation_rules**](docs/ValidationRulesApi.md#delete_validation_rules) | **DELETE** /v1/validation-rules/{validationRuleId} | Delete Validation Rule @@ -885,6 +888,8 @@ Class | Method | HTTP request | Description - [VoucherifySdk::ValidationRuleBase](docs/ValidationRuleBase.md) - [VoucherifySdk::ValidationRuleBaseApplicableTo](docs/ValidationRuleBaseApplicableTo.md) - [VoucherifySdk::ValidationRuleBaseError](docs/ValidationRuleBaseError.md) + - [VoucherifySdk::ValidationRulesAssignmentsCreateRequestBody](docs/ValidationRulesAssignmentsCreateRequestBody.md) + - [VoucherifySdk::ValidationRulesAssignmentsCreateResponseBody](docs/ValidationRulesAssignmentsCreateResponseBody.md) - [VoucherifySdk::ValidationRulesAssignmentsList](docs/ValidationRulesAssignmentsList.md) - [VoucherifySdk::ValidationRulesAssignmentsListResponseBody](docs/ValidationRulesAssignmentsListResponseBody.md) - [VoucherifySdk::ValidationRulesCreateRequestBody](docs/ValidationRulesCreateRequestBody.md) @@ -943,7 +948,3 @@ Class | Method | HTTP request | Description - [VoucherifySdk::VouchersTransactionsExportCreateResponseBody](docs/VouchersTransactionsExportCreateResponseBody.md) - [VoucherifySdk::VouchersTransactionsListResponseBody](docs/VouchersTransactionsListResponseBody.md) - -## License - -The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). diff --git a/__tests__/lib/voucherify_data.rb b/__tests__/lib/voucherify_data.rb index 90e640d8..fa4bcc69 100644 --- a/__tests__/lib/voucherify_data.rb +++ b/__tests__/lib/voucherify_data.rb @@ -15,6 +15,7 @@ def initialize @loyalty_card = nil @product_ids = [] @sku = nil + @validation_rule = nil end def set_discount_campaign(discount_campaign) @@ -37,6 +38,10 @@ def add_product_id(product_id) @product_ids.push(product_id) end + def set_validation_rule(validation_rule) + @validation_rule = validation_rule + end + def get_product_ids @product_ids end @@ -89,6 +94,10 @@ def get_loyalty_card @loyalty_card end + def get_validation_rule + @validation_rule + end + def set_loyalty_card(loyalty_card) @loyalty_card = loyalty_card end diff --git a/__tests__/spec/2_campaigns_spec.rb b/__tests__/spec/2_campaigns_spec.rb index 4cc5dd10..9658622d 100644 --- a/__tests__/spec/2_campaigns_spec.rb +++ b/__tests__/spec/2_campaigns_spec.rb @@ -14,7 +14,6 @@ $created_promotion_campaign = nil $created_loyalty_campaign = nil $created_validation_rule_applicable_to = nil - $created_campaign_with_validation_rule = nil it 'create a validation rule with applicable_to', :order => :first do validation_rule = create_validation_rule_applicable_to(@validation_rules_api_instance, @voucherify_data.get_product.id) @@ -22,6 +21,7 @@ expect(validation_rule).not_to be_nil $created_validation_rule_applicable_to = validation_rule + @voucherify_data.set_validation_rule(validation_rule) end it 'create a discount campaign with applicable_to validation rule', :order => :second do diff --git a/__tests__/spec/a1_validation_rules_spec.rb b/__tests__/spec/a1_validation_rules_spec.rb new file mode 100644 index 00000000..6f2f972c --- /dev/null +++ b/__tests__/spec/a1_validation_rules_spec.rb @@ -0,0 +1,33 @@ +require_relative '../lib/config.rb' +require_relative '../lib/voucherify_data.rb' +require 'VoucherifySdk' + +RSpec.describe 'Validation Rules API', :order => :defined do + before(:each) do + @validation_rules_api_instance = Config.validation_rules_api_instance() + @voucherify_data = VoucherifyData.instance() + end + + it 'create validation rule', :order => :first do + voucher = @voucherify_data.get_voucher() + validation_rule = @voucherify_data.get_validation_rule() + + validationRulesAssignmentsCreateRequestBody = VoucherifySdk::ValidationRulesAssignmentsCreateRequestBody.new({ + related_object_type: "voucher", + related_object_id: voucher.code + }) + + created_validation_rule_assignment = @validation_rules_api_instance.create_validation_rule_assignment(validation_rule.id, { + validation_rules_assignments_create_request_body: validationRulesAssignmentsCreateRequestBody + }) + + expect(created_validation_rule_assignment).not_to be_nil + expect(created_validation_rule_assignment.id).not_to be_nil + expect(created_validation_rule_assignment.created_at).not_to be_nil + expect(created_validation_rule_assignment.rule_id).to eq(validation_rule.id) + expect(created_validation_rule_assignment.related_object_id).to eq(voucher.id) + expect(created_validation_rule_assignment.related_object_type).to eq("voucher") + expect(created_validation_rule_assignment.object).to eq("validation_rules_assignment") + end + +end diff --git a/docs/ValidationRulesApi.md b/docs/ValidationRulesApi.md index a58c1624..0d75c314 100644 --- a/docs/ValidationRulesApi.md +++ b/docs/ValidationRulesApi.md @@ -4,6 +4,7 @@ All URIs are relative to *https://api.voucherify.io* | Method | HTTP request | Description | | ------ | ------------ | ----------- | +| [**create_validation_rule_assignment**](ValidationRulesApi.md#create_validation_rule_assignment) | **POST** /v1/validation-rules/{validationRuleId}/assignments | Create Validation Rules Assignments | | [**create_validation_rules**](ValidationRulesApi.md#create_validation_rules) | **POST** /v1/validation-rules | Create Validation Rules | | [**delete_validation_rule_assignment**](ValidationRulesApi.md#delete_validation_rule_assignment) | **DELETE** /v1/validation-rules/{validationRuleId}/assignments/{assignmentId} | Delete Validation Rule Assignment | | [**delete_validation_rules**](ValidationRulesApi.md#delete_validation_rules) | **DELETE** /v1/validation-rules/{validationRuleId} | Delete Validation Rule | @@ -14,6 +15,70 @@ All URIs are relative to *https://api.voucherify.io* | [**update_validation_rule**](ValidationRulesApi.md#update_validation_rule) | **PUT** /v1/validation-rules/{validationRuleId} | Update Validation Rule | +## create_validation_rule_assignment + +> create_validation_rule_assignment(validation_rule_id, opts) + +Create Validation Rules Assignments + +Assign validation rule to either one of the following objects: voucher, campaign, promotion tier, earning rule, reward, distribution. + +### Examples + +```ruby +require 'time' +require 'VoucherifySdk' +# setup authorization +VoucherifySdk.configure do |config| + # Configure API key authorization: X-App-Id + config.api_key['X-App-Id'] = 'YOUR API KEY' + # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil) + # config.api_key_prefix['X-App-Id'] = 'Bearer' + + # Configure API key authorization: X-App-Token + config.api_key['X-App-Token'] = 'YOUR API KEY' + # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil) + # config.api_key_prefix['X-App-Token'] = 'Bearer' +end + +api_instance = VoucherifySdk::ValidationRulesApi.new +validation_rule_id = 'validation_rule_id_example' # String | Unique validation rule ID. +opts = { + force: true, # Boolean | If this flag is set to true, the previous assignment with the same data will be deleted and a new one will be added. + validation_rules_assignments_create_request_body: VoucherifySdk::ValidationRulesAssignmentsCreateRequestBody.new # ValidationRulesAssignmentsCreateRequestBody | Specify the resource that you would like to assign the validation rule to. +} + +begin + # Create Validation Rules Assignments + result = api_instance.create_validation_rule_assignment(validation_rule_id, opts) + p result +rescue VoucherifySdk::ApiError => e + puts "Error when calling ValidationRulesApi->create_validation_rule_assignment: #{e}" +end +``` + +### Parameters + +| Name | Type | Description | Notes | +| ---- | ---- | ----------- | ----- | +| **validation_rule_id** | **String** | Unique validation rule ID. | | +| **force** | **Boolean** | If this flag is set to true, the previous assignment with the same data will be deleted and a new one will be added. | [optional] | +| **validation_rules_assignments_create_request_body** | [**ValidationRulesAssignmentsCreateRequestBody**](ValidationRulesAssignmentsCreateRequestBody.md) | Specify the resource that you would like to assign the validation rule to. | [optional] | + +### Return type + +[**ValidationRulesAssignmentsCreateResponseBody**](ValidationRulesAssignmentsCreateResponseBody.md) + +### Authorization + +[X-App-Id](../README.md#X-App-Id), [X-App-Token](../README.md#X-App-Token) + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: application/json + + ## create_validation_rules > create_validation_rules(opts) diff --git a/docs/ValidationRulesAssignmentsCreateRequestBody.md b/docs/ValidationRulesAssignmentsCreateRequestBody.md new file mode 100644 index 00000000..f6aa4ff8 --- /dev/null +++ b/docs/ValidationRulesAssignmentsCreateRequestBody.md @@ -0,0 +1,9 @@ +# VoucherifySdk::ValidationRulesAssignmentsCreateRequestBody + +## Properties + +| Name | Type | Description | Notes | +| ---- | ---- | ----------- | ----- | +| **related_object_type** | **String** | Defines the related object. i.e. `voucher`. | [optional][default to 'voucher'] | +| **related_object_id** | **String** | Unique related object ID assigned by Voucherify, i.e. v_lfZi4rcEGe0sN9gmnj40bzwK2FH6QUno for a voucher. | [optional] | + diff --git a/docs/ValidationRulesAssignmentsCreateResponseBody.md b/docs/ValidationRulesAssignmentsCreateResponseBody.md new file mode 100644 index 00000000..1a04495b --- /dev/null +++ b/docs/ValidationRulesAssignmentsCreateResponseBody.md @@ -0,0 +1,13 @@ +# VoucherifySdk::ValidationRulesAssignmentsCreateResponseBody + +## Properties + +| Name | Type | Description | Notes | +| ---- | ---- | ----------- | ----- | +| **id** | **String** | Validation rule assignment ID. | | +| **rule_id** | **String** | Validation rule ID. | | +| **related_object_id** | **String** | The resource ID to which the validation rule was assigned. | | +| **related_object_type** | **String** | The type of resource to which the validation rule was assigned. | | +| **created_at** | **Time** | Timestamp representing the date and time when the validation rule assignment was created in ISO 8601 format. | | +| **object** | **String** | The type of object represented by the ID. | [default to 'validation_rules_assignment'] | + diff --git a/lib/VoucherifySdk.rb b/lib/VoucherifySdk.rb index a5cba275..957e560c 100644 --- a/lib/VoucherifySdk.rb +++ b/lib/VoucherifySdk.rb @@ -618,6 +618,8 @@ require 'VoucherifySdk/models/validation_rule_base' require 'VoucherifySdk/models/validation_rule_base_applicable_to' require 'VoucherifySdk/models/validation_rule_base_error' +require 'VoucherifySdk/models/validation_rules_assignments_create_request_body' +require 'VoucherifySdk/models/validation_rules_assignments_create_response_body' require 'VoucherifySdk/models/validation_rules_assignments_list' require 'VoucherifySdk/models/validation_rules_assignments_list_response_body' require 'VoucherifySdk/models/validation_rules_create_request_body' diff --git a/lib/VoucherifySdk/api/validation_rules_api.rb b/lib/VoucherifySdk/api/validation_rules_api.rb index 97238643..60854ea1 100644 --- a/lib/VoucherifySdk/api/validation_rules_api.rb +++ b/lib/VoucherifySdk/api/validation_rules_api.rb @@ -19,6 +19,79 @@ class ValidationRulesApi def initialize(api_client = ApiClient.default) @api_client = api_client end + # Create Validation Rules Assignments + # Assign validation rule to either one of the following objects: voucher, campaign, promotion tier, earning rule, reward, distribution. + # @param validation_rule_id [String] Unique validation rule ID. + # @param [Hash] opts the optional parameters + # @option opts [Boolean] :force If this flag is set to true, the previous assignment with the same data will be deleted and a new one will be added. + # @option opts [ValidationRulesAssignmentsCreateRequestBody] :validation_rules_assignments_create_request_body Specify the resource that you would like to assign the validation rule to. + # @return [ValidationRulesAssignmentsCreateResponseBody] + def create_validation_rule_assignment(validation_rule_id, opts = {}) + data, _status_code, _headers = create_validation_rule_assignment_with_http_info(validation_rule_id, opts) + data + end + + # Create Validation Rules Assignments + # Assign validation rule to either one of the following objects: voucher, campaign, promotion tier, earning rule, reward, distribution. + # @param validation_rule_id [String] Unique validation rule ID. + # @param [Hash] opts the optional parameters + # @option opts [Boolean] :force If this flag is set to true, the previous assignment with the same data will be deleted and a new one will be added. + # @option opts [ValidationRulesAssignmentsCreateRequestBody] :validation_rules_assignments_create_request_body Specify the resource that you would like to assign the validation rule to. + # @return [Array<(ValidationRulesAssignmentsCreateResponseBody, Integer, Hash)>] ValidationRulesAssignmentsCreateResponseBody data, response status code and response headers + private def create_validation_rule_assignment_with_http_info(validation_rule_id, opts = {}) + if @api_client.config.debugging + @api_client.config.logger.debug 'Calling API: ValidationRulesApi.create_validation_rule_assignment ...' + end + # verify the required parameter 'validation_rule_id' is set + if @api_client.config.client_side_validation && validation_rule_id.nil? + fail ArgumentError, "Missing the required parameter 'validation_rule_id' when calling ValidationRulesApi.create_validation_rule_assignment" + end + # resource path + local_var_path = '/v1/validation-rules/{validationRuleId}/assignments'.sub('{' + 'validationRuleId' + '}', CGI.escape(validation_rule_id.to_s)) + + # query parameters + query_params = opts[:query_params] || {} + query_params[:'force'] = opts[:'force'] if !opts[:'force'].nil? + + # header parameters + header_params = opts[:header_params] || {} + # HTTP header 'Accept' (if needed) + header_params['Accept'] = @api_client.select_header_accept(['application/json']) + # HTTP header 'Content-Type' + content_type = @api_client.select_header_content_type(['application/json']) + if !content_type.nil? + header_params['Content-Type'] = content_type + end + + # form parameters + form_params = opts[:form_params] || {} + + # http body (model) + post_body = opts[:debug_body] || @api_client.object_to_http_body(opts[:'validation_rules_assignments_create_request_body']) + + # return_type + return_type = opts[:debug_return_type] || 'ValidationRulesAssignmentsCreateResponseBody' + + # auth_names + auth_names = opts[:debug_auth_names] || ['X-App-Id', 'X-App-Token'] + + new_options = opts.merge( + :operation => :"ValidationRulesApi.create_validation_rule_assignment", + :header_params => header_params, + :query_params => query_params, + :form_params => form_params, + :body => post_body, + :auth_names => auth_names, + :return_type => return_type + ) + + data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options) + if @api_client.config.debugging + @api_client.config.logger.debug "API called: ValidationRulesApi#create_validation_rule_assignment\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" + end + return data, status_code, headers + end + # Create Validation Rules # Create validation rules. # @param [Hash] opts the optional parameters diff --git a/lib/VoucherifySdk/models/validation_rules_assignments_create_request_body.rb b/lib/VoucherifySdk/models/validation_rules_assignments_create_request_body.rb new file mode 100644 index 00000000..3d11d8ab --- /dev/null +++ b/lib/VoucherifySdk/models/validation_rules_assignments_create_request_body.rb @@ -0,0 +1,262 @@ +=begin +#Voucherify API + +#Voucherify promotion engine REST API. Please see https://docs.voucherify.io/docs for more details. + +The version of the OpenAPI document: v2018-08-01 +Contact: support@voucherify.io +Generated by: https://openapi-generator.tech +OpenAPI Generator version: 7.0.1 + +=end + +require 'date' +require 'time' + +module VoucherifySdk + # Request body schema for **POST** `/validation-rules/{validationRuleId}/assignments`. + class ValidationRulesAssignmentsCreateRequestBody + # Defines the related object. i.e. `voucher`. + attr_accessor :related_object_type + + # Unique related object ID assigned by Voucherify, i.e. v_lfZi4rcEGe0sN9gmnj40bzwK2FH6QUno for a voucher. + attr_accessor :related_object_id + + class EnumAttributeValidator + attr_reader :datatype + attr_reader :allowable_values + + def initialize(datatype, allowable_values) + @allowable_values = allowable_values.map do |value| + case datatype.to_s + when /Integer/i + value.to_i + when /Float/i + value.to_f + else + value + end + end + end + + def valid?(value) + !value || allowable_values.include?(value) + end + end + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'related_object_type' => :'related_object_type', + :'related_object_id' => :'related_object_id' + } + end + + # Returns all the JSON keys this model knows about + def self.acceptable_attributes + attribute_map.values + end + + # Attribute type mapping. + def self.openapi_types + { + :'related_object_type' => :'String', + :'related_object_id' => :'String' + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + ]) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + fail ArgumentError, "The input argument (attributes) must be a hash in `VoucherifySdk::ValidationRulesAssignmentsCreateRequestBody` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + fail ArgumentError, "`#{k}` is not a valid attribute in `VoucherifySdk::ValidationRulesAssignmentsCreateRequestBody`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect + end + h[k.to_sym] = v + } + + if attributes.key?(:'related_object_type') + self.related_object_type = attributes[:'related_object_type'] + else + self.related_object_type = 'voucher' + end + + if attributes.key?(:'related_object_id') + self.related_object_id = attributes[:'related_object_id'] + end + end + + # Show invalid properties with the reasons. Usually used together with valid? + # @return Array for valid properties with the reasons + def list_invalid_properties + warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' + invalid_properties = Array.new + invalid_properties + end + + # Check to see if the all the properties in the model are valid + # @return true if the model is valid + def valid? + warn '[DEPRECATED] the `valid?` method is obsolete' + related_object_type_validator = EnumAttributeValidator.new('String', ["voucher", "promotion_tier", "campaign", "earning_rule", "distribution", "reward_assignment"]) + return false unless related_object_type_validator.valid?(@related_object_type) + true + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] related_object_type Object to be assigned + def related_object_type=(related_object_type) + validator = EnumAttributeValidator.new('String', ["voucher", "promotion_tier", "campaign", "earning_rule", "distribution", "reward_assignment"]) + unless validator.valid?(related_object_type) + fail ArgumentError, "invalid value for \"related_object_type\", must be one of #{validator.allowable_values}." + end + @related_object_type = related_object_type + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(o) + return true if self.equal?(o) + self.class == o.class && + related_object_type == o.related_object_type && + related_object_id == o.related_object_id + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(o) + self == o + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [related_object_type, related_object_id].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + openapi_types.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash["#{key}"] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + end + end + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + else # model + # models (e.g. Pet) or oneOf + klass = VoucherifySdk.const_get(type) + klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = self.send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to? :to_hash + value.to_hash + else + value + end + end + + end + +end diff --git a/lib/VoucherifySdk/models/validation_rules_assignments_create_response_body.rb b/lib/VoucherifySdk/models/validation_rules_assignments_create_response_body.rb new file mode 100644 index 00000000..91868598 --- /dev/null +++ b/lib/VoucherifySdk/models/validation_rules_assignments_create_response_body.rb @@ -0,0 +1,361 @@ +=begin +#Voucherify API + +#Voucherify promotion engine REST API. Please see https://docs.voucherify.io/docs for more details. + +The version of the OpenAPI document: v2018-08-01 +Contact: support@voucherify.io +Generated by: https://openapi-generator.tech +OpenAPI Generator version: 7.0.1 + +=end + +require 'date' +require 'time' + +module VoucherifySdk + # Response body for **POST** `/validation-rules/{validationRuleId}/assignments`. + class ValidationRulesAssignmentsCreateResponseBody + # Validation rule assignment ID. + attr_accessor :id + + # Validation rule ID. + attr_accessor :rule_id + + # The resource ID to which the validation rule was assigned. + attr_accessor :related_object_id + + # The type of resource to which the validation rule was assigned. + attr_accessor :related_object_type + + # Timestamp representing the date and time when the validation rule assignment was created in ISO 8601 format. + attr_accessor :created_at + + # The type of object represented by the ID. + attr_accessor :object + + class EnumAttributeValidator + attr_reader :datatype + attr_reader :allowable_values + + def initialize(datatype, allowable_values) + @allowable_values = allowable_values.map do |value| + case datatype.to_s + when /Integer/i + value.to_i + when /Float/i + value.to_f + else + value + end + end + end + + def valid?(value) + !value || allowable_values.include?(value) + end + end + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'id' => :'id', + :'rule_id' => :'rule_id', + :'related_object_id' => :'related_object_id', + :'related_object_type' => :'related_object_type', + :'created_at' => :'created_at', + :'object' => :'object' + } + end + + # Returns all the JSON keys this model knows about + def self.acceptable_attributes + attribute_map.values + end + + # Attribute type mapping. + def self.openapi_types + { + :'id' => :'String', + :'rule_id' => :'String', + :'related_object_id' => :'String', + :'related_object_type' => :'String', + :'created_at' => :'Time', + :'object' => :'String' + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + ]) + end + + # List of class defined in allOf (OpenAPI v3) + def self.openapi_all_of + [ + :'ValidationRuleAssignment' + ] + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + fail ArgumentError, "The input argument (attributes) must be a hash in `VoucherifySdk::ValidationRulesAssignmentsCreateResponseBody` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + fail ArgumentError, "`#{k}` is not a valid attribute in `VoucherifySdk::ValidationRulesAssignmentsCreateResponseBody`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect + end + h[k.to_sym] = v + } + + if attributes.key?(:'id') + self.id = attributes[:'id'] + else + self.id = nil + end + + if attributes.key?(:'rule_id') + self.rule_id = attributes[:'rule_id'] + else + self.rule_id = nil + end + + if attributes.key?(:'related_object_id') + self.related_object_id = attributes[:'related_object_id'] + else + self.related_object_id = nil + end + + if attributes.key?(:'related_object_type') + self.related_object_type = attributes[:'related_object_type'] + else + self.related_object_type = nil + end + + if attributes.key?(:'created_at') + self.created_at = attributes[:'created_at'] + else + self.created_at = nil + end + + if attributes.key?(:'object') + self.object = attributes[:'object'] + else + self.object = 'validation_rules_assignment' + end + end + + # Show invalid properties with the reasons. Usually used together with valid? + # @return Array for valid properties with the reasons + def list_invalid_properties + warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' + invalid_properties = Array.new + if @id.nil? + invalid_properties.push('invalid value for "id", id cannot be nil.') + end + + if @rule_id.nil? + invalid_properties.push('invalid value for "rule_id", rule_id cannot be nil.') + end + + if @related_object_id.nil? + invalid_properties.push('invalid value for "related_object_id", related_object_id cannot be nil.') + end + + if @related_object_type.nil? + invalid_properties.push('invalid value for "related_object_type", related_object_type cannot be nil.') + end + + if @created_at.nil? + invalid_properties.push('invalid value for "created_at", created_at cannot be nil.') + end + + if @object.nil? + invalid_properties.push('invalid value for "object", object cannot be nil.') + end + + invalid_properties + end + + # Check to see if the all the properties in the model are valid + # @return true if the model is valid + def valid? + warn '[DEPRECATED] the `valid?` method is obsolete' + return false if @id.nil? + return false if @rule_id.nil? + return false if @related_object_id.nil? + return false if @related_object_type.nil? + related_object_type_validator = EnumAttributeValidator.new('String', ["voucher", "campaign", "earning_rule", "reward_assignment", "promotion_tier", "distribution"]) + return false unless related_object_type_validator.valid?(@related_object_type) + return false if @created_at.nil? + return false if @object.nil? + object_validator = EnumAttributeValidator.new('String', ["validation_rules_assignment"]) + return false unless object_validator.valid?(@object) + true + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] related_object_type Object to be assigned + def related_object_type=(related_object_type) + validator = EnumAttributeValidator.new('String', ["voucher", "campaign", "earning_rule", "reward_assignment", "promotion_tier", "distribution"]) + unless validator.valid?(related_object_type) + fail ArgumentError, "invalid value for \"related_object_type\", must be one of #{validator.allowable_values}." + end + @related_object_type = related_object_type + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] object Object to be assigned + def object=(object) + validator = EnumAttributeValidator.new('String', ["validation_rules_assignment"]) + unless validator.valid?(object) + fail ArgumentError, "invalid value for \"object\", must be one of #{validator.allowable_values}." + end + @object = object + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(o) + return true if self.equal?(o) + self.class == o.class && + id == o.id && + rule_id == o.rule_id && + related_object_id == o.related_object_id && + related_object_type == o.related_object_type && + created_at == o.created_at && + object == o.object + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(o) + self == o + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [id, rule_id, related_object_id, related_object_type, created_at, object].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + openapi_types.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash["#{key}"] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + end + end + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + else # model + # models (e.g. Pet) or oneOf + klass = VoucherifySdk.const_get(type) + klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = self.send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to? :to_hash + value.to_hash + else + value + end + end + + end + +end diff --git a/lib/VoucherifySdk/version.rb b/lib/VoucherifySdk/version.rb index 2439bfe6..5d1e73d2 100644 --- a/lib/VoucherifySdk/version.rb +++ b/lib/VoucherifySdk/version.rb @@ -11,5 +11,5 @@ =end module VoucherifySdk - VERSION = '5.0.0' + VERSION = '5.0.1' end