Skip to content

Commit

Permalink
TED-1074/Add create_item
Browse files Browse the repository at this point in the history
  • Loading branch information
instantfred committed Jan 25, 2024
1 parent 4286aa9 commit 558c9f1
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/zesty/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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`
Expand Down
48 changes: 48 additions & 0 deletions spec/zesty/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]) }

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 558c9f1

Please sign in to comment.