Skip to content

Commit

Permalink
Merge pull request #24 from covermymeds/support-redirects
Browse files Browse the repository at this point in the history
Follow redirects to better support request-pages as before
  • Loading branch information
jonmartindell authored Oct 26, 2016
2 parents 83fe78f + a377787 commit 3ad8cd6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions cover_my_meds.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "railties"

spec.add_runtime_dependency "faraday", "~> 0.9"
spec.add_runtime_dependency "faraday_middleware"
spec.add_runtime_dependency "typhoeus"
spec.add_runtime_dependency "mime-types"
spec.add_runtime_dependency "hashie", ">= 3.4.0"
Expand Down
8 changes: 5 additions & 3 deletions lib/cover_my_meds/api_request.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'faraday'
require 'faraday_middleware'
require 'typhoeus'
require 'typhoeus/adapters/faraday'
require 'json'
Expand All @@ -18,9 +19,10 @@ def request(http_method, host, path, params={}, auth_type = :basic, &block)
headers = params.delete(:headers) || {}

conn = Faraday.new host do |faraday|
faraday.request :multipart
faraday.request :url_encoded
faraday.adapter :typhoeus
faraday.request :multipart
faraday.request :url_encoded
faraday.response :follow_redirects
faraday.adapter :typhoeus
end
case auth_type
when :basic
Expand Down
2 changes: 1 addition & 1 deletion lib/cover_my_meds/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module CoverMyMeds
VERSION = "3.0.0"
VERSION = "3.1.0"
end
14 changes: 14 additions & 0 deletions spec/request_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,19 @@
expect(request_page.keys).to match_array expected_keys
end
end

context 'a redirect is returned' do
before do
stub_request(:get, "https://www.example.com/").to_return(status: 200, body: { request_page: { data: "You redirected" } }.to_json)
stub_request(:get, "https://api.covermymeds.com/request-pages/#{request_id}?&v=#{version}")
.with( headers: { "Authorization" => "Bearer #{api_id}+#{token_id}" })
.to_return( status: 302, :headers => { "Location" => "https://www.example.com/" })
end

it 'follows redirects' do
request_page = client.get_request_page(request_id, token_id)
expect(request_page.data).to eq "You redirected"
end
end
end
end

0 comments on commit 3ad8cd6

Please sign in to comment.