From 28c934afbf1c7f8aa9b28d7bd9f75c5d25745758 Mon Sep 17 00:00:00 2001 From: abreckner Date: Tue, 28 Apr 2020 11:05:30 +1000 Subject: [PATCH 1/2] Add Faraday post to connection and post test with VCR --- lib/xpm_ruby/connection.rb | 5 ++ .../xpm_ruby/connection/post.yml | 52 +++++++++++++++++++ spec/xpm_ruby/connection_spec.rb | 33 ++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 spec/vcr_cassettes/xpm_ruby/connection/post.yml 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..41f9970 100644 --- a/spec/xpm_ruby/connection_spec.rb +++ b/spec/xpm_ruby/connection_spec.rb @@ -26,5 +26,38 @@ 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) { + """ + + Brochure Design + Detailed description of the job + e349fc1b-d92d-4ba2-b9fc-69fdd516e2a2 + 20291023 + 20291028 + + """ + } + + 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 From dc4ff587f326e317f1dae39d1bfca9b6bfb714f7 Mon Sep 17 00:00:00 2001 From: abreckner Date: Tue, 28 Apr 2020 11:17:26 +1000 Subject: [PATCH 2/2] Rubocop fixes --- spec/xpm_ruby/connection_spec.rb | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/spec/xpm_ruby/connection_spec.rb b/spec/xpm_ruby/connection_spec.rb index 41f9970..2c506f8 100644 --- a/spec/xpm_ruby/connection_spec.rb +++ b/spec/xpm_ruby/connection_spec.rb @@ -32,17 +32,9 @@ module XpmRuby let(:account_key) { "TEST" } let(:api_url) { "api.workflowmax.com" } - let(:xml_string) { - """ - - Brochure Design - Detailed description of the job - e349fc1b-d92d-4ba2-b9fc-69fdd516e2a2 - 20291023 - 20291028 - - """ - } + 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