Sha256: f0b32abbfdc60111d32915e0e160fa42e38170aab01d58e4d878497d3d62e78d

Contents?: true

Size: 899 Bytes

Versions: 6

Compression:

Stored size: 899 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, command_options.fetch(:request_type, :public))
    end
  end

  def self.execute_request!(options = {}, request_type)
    request_class = request_type == :partner ? ShippingEasy::Http::PartnerRequest : ShippingEasy::Http::Request
    response = request_class.connect!(options)
    ShippingEasy::Http::ResponseHandler.run(response)
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
shipping_easy-0.7.1 lib/shipping_easy/resources/base.rb
shipping_easy-0.7.0 lib/shipping_easy/resources/base.rb
shipping_easy-0.6.1 lib/shipping_easy/resources/base.rb
shipping_easy-0.6.0 lib/shipping_easy/resources/base.rb
shipping_easy-0.5.1 lib/shipping_easy/resources/base.rb
shipping_easy-0.5.0 lib/shipping_easy/resources/base.rb