Sha256: 81bc3b299aecd1d345b92dbc8fa11674f548d1584a1fff5bd45e5ab4e1c959cd

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

require 'crefo/service/request'
require 'crefo/service/response'

module Crefo
  class Service
    attr_reader :options, :log

    def initialize(options = {})
      @options = options
    end

    def process
      begin
        url = Crefo.config.endpoint
        request = self.class::Request.new(**options)
        response_data = request.send(url)
        response = self.class::Response.new(response_data)
      rescue Crefo::Service::Response::ResponseError => exception
        error = true
      rescue Exception => exception
        error = %(#{exception.class}: #{exception.message}\n#{exception.backtrace.join("\n")})
        raise exception
      end

      Crefo::Log.new(url, (request && request.envelope), (response && response.body), error)
      Result.new(
        result: (response && response.result),
        body: (response && response.body),
        attachments: (response && response.attachments),
        error: error
      )
    end

    class Result
      attr_reader :result, :body, :attachments, :error

      def initialize(result: raise(ArgumentError), body: raise(ArgumentError), attachments: raise(ArgumentError), error: raise(ArgumentError))
        @result = result
        @body = body
        @attachments = attachments
        @error = error
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
crefo-0.3.0 lib/crefo/service.rb