Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/xpm_ruby/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ def get(endpoint:)
Faraday.new(url(endpoint: endpoint), headers: headers).get
end

def post(endpoint:, data:)
faraday_connection = Faraday.new("https://#{@api_url}/v3/")
faraday_connection.post(endpoint, data, headers)
end

private

def headers
Expand Down
52 changes: 52 additions & 0 deletions spec/vcr_cassettes/xpm_ruby/connection/post.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions spec/xpm_ruby/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,30 @@ module XpmRuby
connection.get(endpoint: "staff.api/list")
end
end

describe "#post" do
let(:api_key) { "TEST" }
let(:account_key) { "TEST" }
let(:api_url) { "api.workflowmax.com" }

let(:xml_string) do
"<Job><Name>Brochure Design</Name><Description>Detailed description of the job</Description><ClientUUID>e349fc1b-d92d-4ba2-b9fc-69fdd516e2a2</ClientUUID><StartDate>20291023</StartDate><DueDate>20291028</DueDate></Job>"
end

around(:each) do |example|
VCR.use_cassette("xpm_ruby/connection/post") do
example.run
end
end

it "should post to Faraday with the right endpoint, data and headers" do
connection = service.new(api_key: api_key, api_url: api_url, account_key: account_key)
response = connection.post(endpoint: "job.api/add", data: xml_string)

hash = Ox.load(response.body, mode: :hash_no_attrs, symbolize_keys: false)

expect(hash["Response"]["Status"]).to eq("OK")
end
end
end
end