Skip to content

Commit

Permalink
Require specifying a host when instantiating a Client (#8)
Browse files Browse the repository at this point in the history
* update the default domain to ca.engagingnetworks.app

* require specifying a host

* single quotes
  • Loading branch information
lavaturtle authored Oct 17, 2023
1 parent 923f68a commit 864f1c9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lib/engaging_networks_rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module EngagingNetworksRest
class << self
def new(api_key:, host: EngagingNetworksRest::Client::ENS_DOMAIN)
def new(api_key:, host:)
EngagingNetworksRest::Client.new(api_key: api_key, host: host)
end
end
Expand Down
4 changes: 1 addition & 3 deletions lib/engaging_networks_rest/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ module EngagingNetworksRest
class Client
attr_reader :api_key, :connection, :ens_auth_key

ENS_DOMAIN = 'www.e-activist.com'

def initialize(api_key:, host: ENS_DOMAIN)
def initialize(api_key:, host:)
@api_key = api_key

@connection = Faraday.new(url: "https://#{host}") do |conn|
Expand Down
7 changes: 4 additions & 3 deletions spec/client/pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
require 'spec_helper'

describe EngagingNetworksRest::Client::Pages do
let(:host) { 'example.com' }
let(:api_key) { 'abc-123' }
let(:ens_auth_key) { 'tmp-auth-key-456' }
let(:standard_headers) { { 'Content-Type' => 'application/json', 'Ens-Auth-Token' => ens_auth_key } }

subject { EngagingNetworksRest::Client.new(api_key: api_key) }
subject { EngagingNetworksRest::Client.new(api_key: api_key, host: host) }

describe '#pages' do
let(:page_type) { 'dcf' }
let(:page_status) { 'live' }
let(:pages_url) { "https://#{EngagingNetworksRest::Client::ENS_DOMAIN}/ens/service/page" }
let(:pages_url) { 'https://example.com/ens/service/page' }

# The API docs don't actually say what this response looks like, so this is a guess.
# Fortunately, it doesn't actually matter for our purposes, since we just return whatever JSON we get.
Expand Down Expand Up @@ -61,7 +62,7 @@

describe '#process_page_request' do
let(:page_id) { 234 }
let(:page_req_url) { "https://#{EngagingNetworksRest::Client::ENS_DOMAIN}/ens/service/page/#{page_id}/process" }
let(:page_req_url) { "https://example.com/ens/service/page/#{page_id}/process" }
let(:email) { Faker::Internet.email }
let(:supporter_hash) do
{ 'firstName' => 'Joe', 'lastName' => 'Smith', 'emailAddress' => email, 'customField1' => 'foo' }
Expand Down
27 changes: 6 additions & 21 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
require 'spec_helper'

describe EngagingNetworksRest::Client do
let(:host) { 'example.com' }
let(:api_key) { 'abc123' }
let(:content_type_header) { { 'Content-Type' => 'application/json' } }

subject { EngagingNetworksRest::Client.new(api_key: api_key) }
subject { EngagingNetworksRest::Client.new(api_key: api_key, host: host) }

describe '#authenticate!' do
let(:auth_url) { "https://#{host}/ens/service/authenticate" }
let(:auth_key) { '75491e42-99dc-45ce-b637-a681bede875c' }
let(:auth_key_body) { "{\"ens-auth-token\":\"#{auth_key}\",\"expires\":3600000}" }

Expand All @@ -18,27 +20,10 @@
.to_return(body: auth_key_body, headers: content_type_header)
end

context 'with no host specified' do
let(:auth_url) { "https://#{EngagingNetworksRest::Client::ENS_DOMAIN}/ens/service/authenticate" }
it 'should set the ens_auth_key on the client' do
subject.authenticate!

it 'should set the ens_auth_key on the client' do
subject.authenticate!

expect(subject.ens_auth_key).to eq auth_key
end
end

context 'with a host specified' do
let(:host) { 'example.com' }
let(:auth_url) { "https://#{host}/ens/service/authenticate" }

subject { EngagingNetworksRest::Client.new(api_key: api_key, host: host) }

it 'should set the ens_auth_key on the client' do
subject.authenticate!

expect(subject.ens_auth_key).to eq auth_key
end
expect(subject.ens_auth_key).to eq auth_key
end
end
end

0 comments on commit 864f1c9

Please sign in to comment.