Sha256: 943ad1731a40a88dadf1f2cc8387d120c6089853b37c9550e000441b12cd825a

Contents?: true

Size: 906 Bytes

Versions: 1

Compression:

Stored size: 906 Bytes

Contents

# options.rb

module Carriots
  # Connecction options for {Client}
  #
  module ApiMethods
    # general options for Carriots API
    #
    class Options
      attr_accessor :options
      attr_accessor :build_options

      def initialize(options = {})
        @raw_options = options
        @options = []
        set_options
        @build_options = opts_montati
      end

      def raw
        @raw_options
      end

      def keys
        []
      end

      def set_options
        keys.each { |key| send("param_#{key}", raw[key]) }
      end

      def opts_montati
        return '' if @options.empty?

        '?' + @options.join('&')
      end

      private

      def set_param(key, value)
        @options << "#{key}=#{value}"
      end

      def set_time_param(key, value)
        v = (value.is_a?(Fixnum) ? value : value.to_time.to_i)
        set_param(key, v)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
carriots-0.0.2 lib/carriots/api_methods/options.rb