Last active
April 4, 2017 10:56
-
-
Save ismasan/f108a49a48d1811e7cf2f0198f0ea8c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm using the "bearer token" strategy for the client, but you can use any or no auth strategy depending on your API.