Sha256: 6fb4e509bd7bb6f186ed72e6bd404657439fad139e6edb4566717b5ae83ee15f

Contents?: true

Size: 704 Bytes

Versions: 1

Compression:

Stored size: 704 Bytes

Contents

require 'ostruct'
require 'httparty'

module SenseiApi
  class Base
    class <<self
      def find_by(params)
        response = HTTParty.get(url, query: params.compact, format: :json)
        JSON.parse(response.body, object_class: OpenStruct)
      end

      def create(params)
        response = HTTParty.post(url, body: params.compact.reject { |key, _| key == :id }, format: :json)
        JSON.parse(response.body, object_class: OpenStruct)
      end

      def update(params)
        response = HTTParty.put(url, body: params.compact, format: :json)
        JSON.parse(response.body, object_class: OpenStruct)
      end

      def url
        raise NotImplementedError
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sensei_eod_utils-0.0.48 lib/sensei_api/base.rb