Sha256: e498f1afd5e826186526bb1d5d9ba1ccca45f9b647fbca73744b8344b9da723b

Contents?: true

Size: 740 Bytes

Versions: 2

Compression:

Stored size: 740 Bytes

Contents

class ShippingEasy::Resources::Base

  def self.command(name, command_options = {}, &block)
    define_singleton_method name do |options = {}|
      request_options = {}
      request_options[:relative_path] = command_options.fetch(:relative_path, block.call(options))
      request_options[:http_method] = command_options.fetch(:http_method, :get)
      request_options[:payload] = options.delete(:payload) if options.has_key?(:payload)
      request_options[:params] = options unless options.nil? || options.empty?
      execute_request!(request_options)
    end
  end

  def self.execute_request!(options = {})
    response = ShippingEasy::Http::Request.connect!(options)
    ShippingEasy::Http::ResponseHandler.run(response)
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shipping_easy-0.3.2 lib/shipping_easy/resources/base.rb
shipping_easy-0.3.1 lib/shipping_easy/resources/base.rb