Skip to content

Instantly share code, notes, and snippets.

@ismasan
Last active April 4, 2017 10:56
Show Gist options
  • Select an option

  • Save ismasan/f108a49a48d1811e7cf2f0198f0ea8c8 to your computer and use it in GitHub Desktop.

Select an option

Save ismasan/f108a49a48d1811e7cf2f0198f0ea8c8 to your computer and use it in GitHub Desktop.
# Gemfile
# gem "bootic_client"
# group :test do
# gem "rack-test"
# end
# spec/support/api_request_helper.rb
# Usage in your API tests
# it "loads the root resource" do
# authorize!(user_id: 1)
#
# expect(root.title).to eq "Hi!"
# end
#
# it "follows links" do
# users = root.users
#
# expect(users.total_items).to eq 2
# expect(users.map(&:name)).to eq ["jane", "joe"]
# end
module ApiRequestHelper
# this is your Rack app
def app
MyApplication
end
def authorize!(claims)
@access_token = generate_a_token_somehow(claims)
end
require "bootic_client"
BooticClient.configure do |c|
c.api_root = "http://example.org"
end
def client
@client ||= BooticClient.client(
:bearer,
access_token: @access_token,
faraday_adapter: [:rack, app]
)
end
def root
@root ||= client.root
end
end
@ismasan
Copy link
Author

ismasan commented Apr 4, 2017

I'm using the "bearer token" strategy for the client, but you can use any or no auth strategy depending on your API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment