Skip to content
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
15 changes: 8 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -258,17 +258,15 @@ GEM
rspec (>= 2.99.0, < 4.0)
hashdiff (1.0.1)
hashie (4.1.0)
http (4.4.1)
addressable (~> 2.3)
http (5.0.4)
addressable (~> 2.8)
http-cookie (~> 1.0)
http-form_data (~> 2.2)
http-parser (~> 1.2.0)
llhttp-ffi (~> 0.4.0)
http-accept (1.7.0)
http-cookie (1.0.3)
http-cookie (1.0.4)
domain_name (~> 0.5)
http-form_data (2.3.0)
http-parser (1.2.1)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more http-parser!

ffi-compiler (>= 1.0, < 2.0)
http_accept_language (2.1.1)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -301,6 +299,9 @@ GEM
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
llhttp-ffi (0.4.0)
ffi-compiler (~> 1.0)
rake (~> 13.0)
lodash-rails (4.17.15)
railties (>= 3.1)
lograge (0.11.2)
Expand Down Expand Up @@ -593,7 +594,7 @@ GEM
execjs (>= 0.3.0, < 3)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.7)
unf_ext (0.0.8)
unicode-display_width (2.0.0)
uuidtools (2.1.5)
view_component (2.24.0)
Expand Down
2 changes: 1 addition & 1 deletion app/services/exotel_api_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def execute_post(url, data)
def parse_response(response)
return unless response.status.ok?

JSON.parse(response, symbolize_names: true)
response.parse(:json).deep_symbolize_keys

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The http gem has a parse method built in, which works fine, we just need to tell it to parse as json.

end

def base_uri
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"Connection" => "close",
"Host" => "api.exotel.com",
"Content-Type" => "application/x-www-form-urlencoded",
"User-Agent" => "http.rb/4.4.1"
"User-Agent" => "http.rb/#{HTTP::VERSION}"
}
end
let!(:stub) do
Expand Down
2 changes: 1 addition & 1 deletion spec/jobs/update_phone_number_details_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"Authorization" => "Basic #{auth_token}",
"Connection" => "close",
"Host" => "api.exotel.com",
"User-Agent" => "http.rb/4.4.1"
"User-Agent" => "http.rb/#{HTTP::VERSION}"
}
end

Expand Down
17 changes: 12 additions & 5 deletions spec/services/exotel_api_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@
"Authorization" => "Basic #{auth_token}",
"Connection" => "close",
"Host" => "api.exotel.com",
"User-Agent" => "http.rb/4.4.1"
"User-Agent" => "http.rb/#{HTTP::VERSION}"
}
end

around do |example|
WebMock.disallow_net_connect!
example.run
WebMock.allow_net_connect!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This made tracking down spec failures easier, because our suite defaults to this being allowed for feature specs to work.

end

describe "#call_details" do
let!(:call_details_200) { File.read("spec/support/fixtures/call_details_200.json") }
let!(:call_details_400) { File.read("spec/support/fixtures/call_details_400.json") }
Expand All @@ -27,18 +33,19 @@
"Authorization" => "Basic #{auth_token}",
"Connection" => "close",
"Host" => "api.exotel.com",
"User-Agent" => "http.rb/4.4.1"
"User-Agent" => "http.rb/#{HTTP::VERSION}"
}
end

it "should return call details for a session id in json when status is 200" do
stub_request(:get, request_url).with(headers: request_headers).to_return(status: 200,
body: call_details_200,
headers: {})
response = described_class.new(sid, token).call_details(call_sid)

expected_call_details_response = described_class.new(sid, token).call_details(call_sid)

expect(expected_call_details_response[:Call].keys).to eq(%i[Sid
expect(response[:Call][:From]).to eq("09663127355")
expect(response[:Call][:To]).to eq("01930483621")
expect(response[:Call].keys).to eq(%i[Sid
ParentCallSid
DateCreated
DateUpdated
Expand Down