diff --git a/lib/xpm_ruby/connection.rb b/lib/xpm_ruby/connection.rb
index 9176617..ce3bbc5 100644
--- a/lib/xpm_ruby/connection.rb
+++ b/lib/xpm_ruby/connection.rb
@@ -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
diff --git a/spec/vcr_cassettes/xpm_ruby/connection/post.yml b/spec/vcr_cassettes/xpm_ruby/connection/post.yml
new file mode 100644
index 0000000..2d566fa
--- /dev/null
+++ b/spec/vcr_cassettes/xpm_ruby/connection/post.yml
@@ -0,0 +1,52 @@
+---
+http_interactions:
+- request:
+ method: post
+ uri: https://api.workflowmax.com/v3/job.api/add
+ body:
+ encoding: UTF-8
+ string: "\n \n Brochure Design\n Detailed
+ description of the job\n e349fc1b-d92d-4ba2-b9fc-69fdd516e2a2\n
+ \ 20291023\n 20291028\n
+ \ \n "
+ headers:
+ User-Agent:
+ - Faraday v1.0.1
+ Authorization:
+ - Basic TEST=
+ Content-Type:
+ - application/x-www-form-urlencoded
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ access-control-allow-origin:
+ - "*"
+ cache-control:
+ - private
+ content-type:
+ - text/xml; charset=utf-8
+ date:
+ - Tue, 28 Apr 2020 01:01:38 GMT
+ server:
+ - Microsoft-IIS/10.0
+ vary:
+ - Accept-Encoding
+ x-aspnet-version:
+ - 4.0.30319
+ x-aspnetmvc-version:
+ - '4.0'
+ content-length:
+ - '432'
+ connection:
+ - keep-alive
+ body:
+ encoding: ASCII-8BIT
+ string: OKJ00002709d0978b-23c2-4356-b180-a230e9cf95a7Brochure
+ DesignDetailed description of the jobe349fc1b-d92d-4ba2-b9fc-69fdd516e2a2ABC
+ CoPlanned2029-10-23T00:00:002029-10-28T00:00:00
+ http_version: null
+ recorded_at: Tue, 28 Apr 2020 01:01:38 GMT
+recorded_with: VCR 5.1.0
diff --git a/spec/xpm_ruby/connection_spec.rb b/spec/xpm_ruby/connection_spec.rb
index 6fc1707..2c506f8 100644
--- a/spec/xpm_ruby/connection_spec.rb
+++ b/spec/xpm_ruby/connection_spec.rb
@@ -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
+ "Brochure DesignDetailed description of the jobe349fc1b-d92d-4ba2-b9fc-69fdd516e2a22029102320291028"
+ 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