Sha256: 46a643d7276ec254f30a8beb5819c9182654db6e60a06e18374338ab2145664a

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

module Awis
  module API
    class Base
      include Utils::Extra
      attr_reader :arguments, :response_body

      def fetch(arguments = {})
        validation_arguments!(arguments)

        loading_response_body
        self
      end

      def parsed_body
        @parsed_body ||= MultiXml.parse(response_body)
      end

      def loading_response_body
        @response_body = Awis::Connection.new.get(params)
      end

      def root_node_name
        "#{action_name}Response"
      end

      def action_name
        self.class.name.split(/\:\:/)[-1]
      end

      def load_request_uri(params)
        collection = Awis::Connection.new
        collection.setup_params(params)
        collection.uri
      end

      def before_validation_arguments(arguments)
        raise ArgumentError, "Invalid arguments. should be like { url: 'site.com' }" unless arguments.is_a?(Hash)
        raise ArgumentError, "Invalid arguments. the url must be configured." unless arguments.has_key?(:url)
      end

      class << self
        def loading_data_from_xml(xml_file_path)
          MultiXml.parse(File.new(xml_file_path))
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
awis-sdk-ruby-0.0.7 lib/awis/api/base.rb