This gem is a Ruby SDK for Hubrise API. It is maintained by the HubRise development team.
Installation
Add hubrise_client
to your Gemfile
:
gem 'hubrise_client'
Or install via gem
gem install hubrise_client
Prerequisites
-
Read the docs
-
Create a Hubrise Client to get your
CLIENT_ID
andCLIENT_SECRET
.
Get an access token
-
Initialize anonymous
HubriseClient
client = HubriseClient::V1.new(CLIENT_ID, CLIENT_SECRET)
-
Prepare a route to handle
REDIRECT_URI
callback# routes.rb namespace :hubrise_oauth do get :authorize_callback # => creates hubrise_oauth_authorize_callback_url helper end
-
Initiate an OAuth flow by redirecting a user to OAuth Authorization URL
oauth_scope = "location[orders.read]" # adjust to your needs authorization_url = client.build_authorization_url(hubrise_oauth_authorize_callback_url, oauth_scope) ... redirect_to(authorization_url)
-
Complete the OAuth flow
Once the user accepts your request he or she will be redirected to the REDIRECT_URI At this step you need to exchange the
authorization_code
(received as a query param) for a newaccess_token
# controllers/hubrise_oauth_controller.rb def authorize_callback client.authorize!(params[:code]) current_user.update!(hubrise_access_token: client.access_token) # account_id = client.account_id # location_id = client.location_id end
The
access_token
reffers to this specific user's permission so it should be securely persisted and not shared with other users.
Use the access token
client = HubriseClient::V1.new(CLIENT_ID, CLIENT_SECRET, access_token: current_user.hubrise_access_token)
Now you can call the helper methods on behalf of the user
client.get_account
Pagination
#next_page?
, #next_page
and #each_page
might be helpful when working with paginated endpoints
response = client.get_all_customers
response.next_page?
# => true
response.next_page.data
# => [{ first_name:... }]
response.each_page do |page_response|
page_response.data
# => [{ first_name:... }]
end
Publish changes to this gem
-
Make sure all local changes are committed.
-
Increase version in
lib/hubrise_client/version.rb
-
Tag the repository:
VERSION=2.0.9
git add lib/hubrise_client/version.rb
git commit -m "Version $VERSION"
git tag v$VERSION
git push --tags
git push
- Build & publish:
rm -f hubrise_client-*.gem
gem build hubrise_client
gem push hubrise_client-*.gem
rm -f hubrise_client-*.gem