Sha256: be14e3bd06912dfe54841919d530d919ad8011c0e9763642c64fcb6e16214b4e

Contents?: true

Size: 1.21 KB

Versions: 30

Compression:

Stored size: 1.21 KB

Contents

module NetSuite
  module Support
    module Requests

      def self.included(base)
        base.send(:extend, ClassMethods)
      end

      module ClassMethods

        def call(options, credentials={})
          raise ArgumentError, "options should be an array" unless options.is_a?(Array)
          new(*options).call(credentials)
        end

      end

      def call(credentials={})
        @response = request(credentials)
        build_response
      end

      private

      def request
        raise NotImplementedError, 'Please implement a #request method'
      end

      def build_response
        Response.new(success: success?, header: response_header, body: response_body, errors: response_errors)
      end

      def success?
        raise NotImplementedError, 'Please implement a #success? method'
      end

      # Only care about headers in Search class for now
      def response_header
        nil
      end

      def response_errors
        nil
      end

      def response_body
        raise NotImplementedError, 'Please implement a #response_body method'
      end

      def array_wrap(object)
        if object.is_a?(Array)
          return object
        end

        [ object ]
      end

    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
netsuite-0.9.2 lib/netsuite/support/requests.rb
netsuite-0.9.1 lib/netsuite/support/requests.rb
netsuite-0.9.0 lib/netsuite/support/requests.rb
netsuite-0.8.12 lib/netsuite/support/requests.rb
netsuite-0.8.11 lib/netsuite/support/requests.rb
netsuite-0.8.10 lib/netsuite/support/requests.rb
netsuite-0.8.9 lib/netsuite/support/requests.rb
netsuite-0.8.8 lib/netsuite/support/requests.rb
netsuite-0.8.7 lib/netsuite/support/requests.rb
netsuite-0.8.6 lib/netsuite/support/requests.rb
netsuite-0.8.5 lib/netsuite/support/requests.rb
netsuite-0.8.4 lib/netsuite/support/requests.rb
netsuite-0.8.3 lib/netsuite/support/requests.rb
netsuite-0.8.2 lib/netsuite/support/requests.rb
netsuite-0.8.1 lib/netsuite/support/requests.rb
netsuite-0.8.0 lib/netsuite/support/requests.rb
netsuite-0.7.9 lib/netsuite/support/requests.rb
netsuite-0.7.8 lib/netsuite/support/requests.rb
netsuite-0.7.7 lib/netsuite/support/requests.rb
netsuite-0.7.6 lib/netsuite/support/requests.rb