From 558c9f19344f39a2ca8b0eed5c2089d271ebd079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Freddy=20Rami=CC=81rez?= Date: Thu, 25 Jan 2024 09:13:45 -0600 Subject: [PATCH] TED-1074/Add create_item --- lib/zesty/client.rb | 14 ++++++++++++ spec/zesty/client_spec.rb | 48 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/lib/zesty/client.rb b/lib/zesty/client.rb index b657ff6..5a83739 100644 --- a/lib/zesty/client.rb +++ b/lib/zesty/client.rb @@ -7,6 +7,7 @@ class Client get_model: "https://%{instance_zuid}.api.zesty.io/v1/content/models/%{model_zuid}", get_items: "https://%{instance_zuid}.api.zesty.io/v1/content/models/%{model_zuid}/items", get_item: "https://%{instance_zuid}.api.zesty.io/v1/content/models/%{model_zuid}/items/%{item_zuid}", + create_item: "https://%{instance_zuid}.api.zesty.io/v1/content/models/%{model_zuid}/items", update_item: "https://%{instance_zuid}.api.zesty.io/v1/content/models/%{model_zuid}/items/%{item_zuid}", get_head_tags: "https://%{instance_zuid}.api.zesty.io/v1/web/headtags", create_head_tag: "https://%{instance_zuid}.api.zesty.io/v1/web/headtags", @@ -43,6 +44,19 @@ def get_item(model_zuid, item_zuid) Request.get(url_for(:get_item, model_zuid: model_zuid, item_zuid: item_zuid), headers: { authorization: "Bearer #{@token}" }) end + def create_item(model_zuid, parent_zuid="0", data:, web: {}) + Request.post( + url_for(:create_item, model_zuid: model_zuid, parent_zuid: parent_zuid), + params: { + web: web.merge(parentZUID: parent_zuid).to_camel_case, + data: data + }, + headers: { + authorization: "Bearer #{@token}" + } + ) + end + def update_item(model_zuid, item_zuid, publish: false, data:, meta:, web: {}) # TODO: include `publish: publish` in `url_for` line once API is announced # TODO: add `?publish=%{publish}` to API_URLS `:update_item` diff --git a/spec/zesty/client_spec.rb b/spec/zesty/client_spec.rb index 46b2b05..340be2c 100644 --- a/spec/zesty/client_spec.rb +++ b/spec/zesty/client_spec.rb @@ -3,6 +3,7 @@ let(:instance_zuid) { ENV["INSTANCE_ZUID"] } let(:model_zuid) { ENV["MODEL_ZUID"] } let(:item_zuid) { "7-b29aa3e7ee-0swr1f" } + let(:parent_zuid) { "6-948fb2a6a4-hzsqk1" } let(:token) { Zesty::Auth.get_token(ENV["EMAIL"], ENV["PASSWORD"]) } @@ -174,6 +175,53 @@ end end + describe '#create_item' do + it "creates an item successfully" do + model = VCR.use_cassette("zesty/instances/create_item") do + result = client.create_item( + model_zuid, + parent_zuid, + web: { + metaTitle: "Example Only", + metaLinkText: "Example Link Text", + pathPart: "example-only" + }, + data: { + event_details_title: "postman test only", + charity_name: "postman test", + sweepstakes_datetime: "September 28 5PM", + event_entry_start_date: "August 15, 2023", + event_entry_start_time: "3:00:00 PM", + event_stream_start_date: "December 21, 2023", + event_stream_start_time: "2:59:59 PM", + event_drawing_date: "December 23, 2034", + event_drawing_time: "5:00:00 PM", + event_reveal_date: "December 24, 2034", + event_reveal_time: "6:00:00 PM", + donation_increment_title: "two", + donation_increment_amount: 2, + drawing_1_winning_pattern_name: "Line", + drawing_1_winning_pattern_description: "five (5) Clicked Numbers in any straight line on a Card", + drawing_1_prize_amount: 50, + drawing_1_prize_text: "fifty", + drawing_2_winning_pattern_name: "Stamp", + drawing_2_winning_pattern_description: "sixteen (16) Clicked Numbers around the edges of a Card", + drawing_2_prize_amount: 30, + drawing_2_prize_text: "thirty", + drawing_3_winning_pattern_name: "Corners", + drawing_3_winning_pattern_description: "twenty-five (25) Clicked Numbers on a Card", + drawing_3_prize_amount: 100, + drawing_3_prize_text: "one hundred", + drawings_total_prize_text: "five thousand five hundred fifty", + drawings_total_prize_amount: "5,550" + } + ) + end + + pp model + end + end + describe '#update_item' do it "updates an item successfully" do model = VCR.use_cassette("zesty/instances/update_item") do