Skip to content

Commit

Permalink
Handle a string response from a WP REST API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsanford committed Nov 30, 2023
1 parent 96b6b81 commit 804bdfc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
16 changes: 10 additions & 6 deletions app/finders/users/wp_json_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ def aggressive(_opts = {})
def users_from_response(response)
found = []

JSON.parse(response.body)&.each do |user|
found << Model::User.new(user['slug'],
id: user['id'],
found_by: found_by,
confidence: 100,
interesting_entries: [response.effective_url])
json = JSON.parse(response.body)

if json.is_a? Enumerable
json.each do |user|
found << Model::User.new(user['slug'],
id: user['id'],
found_by: found_by,
confidence: 100,
interesting_entries: [response.effective_url])
end
end

found
Expand Down
6 changes: 6 additions & 0 deletions spec/app/finders/users/wp_json_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
its(:aggressive) { should eql([]) }
end

context 'when a string response' do
let(:body) { '404' }

its(:aggressive) { should eql([]) }
end

context 'when a JSON response' do
context 'when unauthorised' do
let(:body) { File.read(fixtures.join('401.json')) }
Expand Down

0 comments on commit 804bdfc

Please sign in to comment.