Skip to content

HubRise/ruby-client

Repository files navigation

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

  1. Read the docs

  2. Create a Hubrise Client to get your CLIENT_ID and CLIENT_SECRET.

Get an access token

  1. Initialize anonymous HubriseClient

    client = HubriseClient::V1.new(CLIENT_ID, CLIENT_SECRET)
  2. 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
  3. 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)
  4. 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 new access_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

Development

Run tests

bundle install
bundle exec rspec

Release

  1. Make sure all local changes are committed.

  2. Increase version in lib/hubrise_client/version.rb

  3. Tag the repository:

VERSION=2.0.16
git add lib/hubrise_client/version.rb
git commit -m "Version $VERSION"
git tag v$VERSION
git push --tags
git push
  1. Build & publish:
rm -f hubrise_client-*.gem
gem build hubrise_client
gem push hubrise_client-*.gem
rm -f hubrise_client-*.gem

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages