Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

interage-request

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

interage-request

  • 0.2.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Interage::Request

Installation

Add this line to your application's Gemfile:

gem 'interage-request', '~> 0.2'

And then execute:

bundle install

Or install it yourself as:

gem install interage-request

Usage

You can use a Rails generator to install:

rails g interage:request:install

Or you can create the ApplicationRequest:

# app/requests/application_request.rb
class ApplicationRequest < ::Interage::ApplicationRequest
end

And ApplicationBuilder

# app/builders/application_builder.rb
class ApplicationBuilder < ::Interage::ApplicationBuilder
end

To create a request and builder classes you also can use a Rails generator:

rails g interage:request:create store/order client_name payment_form

This will create this classes:

# app/requests/store/base_request.rb
module Store
  class BaseRequest < ::ApplicationRequest
    private

    def api_base_url
      "#{ENV.fetch('STORE_BASE_URL')}/v1/"
    end

    def headers
      { 'Authorization-Token': ENV.fetch('STORE_AUTHORIZATION_TOKEN') }
    end
  end
end

# app/requests/store/orders_request.rb
module Store
  class OrdersRequest < ::Store::BaseRequest
    private

    def key_name
      :order
    end

    def klass
      ::Store::Order
    end
  end
end

# app/builders/store/order.rb
module Store
  class Order < ApplicationBuilder
    attr_accessor :client_name,
                  :payment_form

    def requester
      @requester ||= ::Store::OrdersRequest.new
    end

    private

    def changeable_attributes
      { client_name: client_name,
        payment_form: payment_form }
    end
  end
end

Controller usage

# frozen_string_literal: true

class OrdersController < ApplicationController
  before_action :set_new_order, only: [:new, :create]
  before_action :set_order, only: [:show, :edit, :update, :destroy]

  def index
    @orders = Order.paginate(params[:page])
  end

  def new
  end

  def create
    if @order.create(order_params)
      redirect_to orders_path
    else
      render :new
    end
  end

  def edit
  end

  def update
    if @order.update(order_params)
      redirect_to orders_path
    else
      render :edit
    end
  end

  def show
  end

  def destroy
    @order.destroy

    redirect_to orders_path
  end

  private

  def order_params
    params.require(:order).permit(:name, :age)
  end

  def set_new_order
    @order = Order.new
  end

  def set_order
    @order = Order.find(params[:id])
  end
end

Contributing

Bug reports and merge requests are welcome on GitLab at https://github.com/[USERNAME]/interage-request.

FAQs

Package last updated on 03 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc