There are two possible ways to define a model. You can use the standard class-based initialization, where you create a new object for each nesting level.
campaign = campaigns_api_instance.create_campaign({
campaigns_create_request_body: VoucherifySdk::CampaignsCreateDiscountCouponsCampaign.new({
campaign_type: "DISCOUNT_COUPONS",
name: generate_random_string(),
type: "AUTO_UPDATE",
voucher: VoucherifySdk::DiscountCouponsCampaignVoucher.new({
discount: VoucherifySdk::DiscountAmount.new({
type: "AMOUNT",
amount_off: 1000
})
}),
validation_rules: [validation_rule_id]
})
})
Another, simpler approach is to create only necessary objects. In this scenario, the model is created using JSON-like syntax..
campaign = campaigns_api_instance.create_campaign({
campaigns_create_request_body: VoucherifySdk::CampaignsCreateDiscountCouponsCampaign.new({
campaign_type: "DISCOUNT_COUPONS",
name: generate_random_string(),
type: "AUTO_UPDATE",
voucher: {
discount: {
type: "AMOUNT",
amount_off: 1000
}
},
validation_rules: [validation_rule_id]
})
})
Some objects are necessary because they represent a union of a few similar types, and you need to determine which type you're using.
E.g. model CampaignsCreateRequestBody consists of types like:
- CampaignsCreateDiscountCouponsCampaign
- CampaignsCreateGiftCampaign
- CampaignsCreateGiveawayCampaign
- CampaignsCreateLoyaltyCampaign
- CampaignsCreatePromotionCampaign
- CampaignsCreateReferralCampaign
So, in our example, we're declaring an object for it, instead of passing it explicitly. For example:
campaigns_create_request_body: VoucherifySdk::CampaignsCreateDiscountCouponsCampaign.new(...)
💡 More useful examples could be found in our tests
To build the Ruby code into a gem:
gem build VoucherifySdk.gemspec
Then either install the gem locally:
gem install ./VoucherifySdk-8.0.0.gem
(for development, run gem install --dev ./VoucherifySdk-8.0.0.gem
to install the development dependencies)
Add this to the Gemfile:
gem 'VoucherifySdk', '~> 8.0.0'
Then install dependencies with bundler
bundle install
Finally, exec script with bundler:
bundle exec ruby example.rb
You could use the GitHub repository (https://github.com/voucherifyio/voucherify-js-sdk) for installing SDK gem by adding it to the Gemfile
gem 'VoucherifySdk', :git => 'https://github.com/voucherifyio/voucherify-js-sdk.git', branch: 'main'
Then install dependencies with bundler
bundle install
Finally, exec script with bundler:
bundle exec ruby example.rb