The Moltin ruby-sdk is a simple to use interface for the API to help you get off the ground quickly and efficiently within the Ruby Language.
Add this line to your application's Gemfile:
And then execute:
$ bundle install
Moltin::Config.api_version = 'v1' Moltin::Config.api_host = 'api.molt.in'
We will automatically detect
ENV['MOLTIN_CLIENT_SECRET'] variables, or you can pass them through manually. There is no need to call the authenticate method if ENV variables are set.
Moltin::Client::Authenticate('client_credentials', client_id: 'XXXXX', client_secret: 'XXXXX')
The majority of our API calls can be mapped to Model-esque instance and don't need any low-level API calls.
// Create a product product = Moltin::Resource::Product.create title: 'Example Product' // Get a product product = Moltin::Resource::Product.find 1 // Update a product product.title = 'New Product Name' product.save // Delete a product product.delete
Manual API Request
For any API calls that aren't resources you can do the following
// Create a product product = Moltin::Api::Request.post('products', title: 'Example Product').result // Get a product product = Moltin::Api::Request.get('products/123') // Update a product product = Moltin::Api::Request.put('products/123', title: 'New Product Name') // Delete a product product = Moltin::Api::Request.delete('products/123')
Create an initializer with the following code to load in all rails helpers.
All resources work out of the box with rails
// app/controllers/customer_controller.rb def edit @customer = Customer.retreive params[:id] end // app/views/customers/edit.html.haml = form_for @customer do |f| = f.input :email // app/controllers/customers_controller.rb def update @customer = Customer.retreive params[:id] @customer.update params.require(:customer).permit(:email) end
After checking out the repo, run
bin/setup to install dependencies. Then, run
bin/console for an interactive prompt that will allow you to experiment.
$ bundle exec rspec
- Fork it ( https://github.com/moltin/ruby-sdk/fork )
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create a new Pull Request