Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add data marketplace connector #7

Merged
merged 1 commit into from
Nov 21, 2024
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
26 changes: 26 additions & 0 deletions app/services/data_marketplace_connector.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class DataMarketplaceConnector
def self.create(record)
new.create(record) # rubocop:disable Rails/SaveBang
end

def create(record)
Faraday.post(
"https://apitest.datamarketplace.gov.uk/v1/datasets",
record.metadata.to_json,
"Content-Type" => "application/json",
"Authorization" => "Bearer #{token}",
)
end

def token
@token ||= begin
response = Faraday.post(
"https://apitest.datamarketplace.gov.uk/v1/clientauth/get-token",
Rails.application.credentials.dm_api.to_json,
"Content-Type" => "application/json",
)
json = JSON.parse(response.body)
json["token"]
end
end
end
2 changes: 1 addition & 1 deletion app/views/records/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</pre>

<div>
<%= govuk_button_to "Destroy this record", @record, method: :delete, warning: true %>
<%#= govuk_button_to "Publish this record", @record, method: :delete, warning: true %>
</div>

<div class="govuk-!-padding-bottom-2">
Expand Down
2 changes: 1 addition & 1 deletion config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
POsrQfSdplij0H2sViAnX9/9xgscONWUPtkJH9Lu+QpO7RNYXOOKorXm59q0Uq9T5jN9aESjzmQTDsSwbN5lRLLvYOA5WxnW56ryI2bgtV8xKDBswjTFwmnKMLF8jWzy2vJKVs7IpPrwjM5HqV4tZmhfL2ubl55Q4dYl3+YkdkPE6BK1hWBX/PO+jR14Of18qPA/UOVH6HTa1dQFeUsbI5s9uszpy+61UiCchDxCIbaEfXsm6uV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p6DA==
28 changes: 28 additions & 0 deletions spec/services/data_marketplace_connector_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require "rails_helper"

RSpec.describe DataMarketplaceConnector, type: :service do
describe ".create" do
let(:token) { SecureRandom.uuid }
let(:record) { create :record }

before do
stub_request(:post, "https://apitest.datamarketplace.gov.uk/v1/clientauth/get-token")
.with(
body: Rails.application.credentials.dm_api.to_json,
headers: { "Content-Type" => "application/json" },
)
.to_return(status: 200, body: { token: }.to_json)

stub_request(:post, "https://apitest.datamarketplace.gov.uk/v1/datasets")
.with(
body: record.metadata.to_json,
headers: { "Content-Type" => "application/json" },
)
.to_return(status: 200, body: "", headers: {})
end

it "returns success" do
expect(described_class.create(record)).to be_success
end
end
end
Loading