100% free for Open Source, forever. Get another set of eyes on your code.

Take a look. Our new design is currently in beta, but you can start using it today!

A
 

Echowrap::API

Updated more than 3 months ago.

No issues here.

Congrats! Give yourself time to reflect on your awesome coding skillz.


module Echowrap
  module API
    module Utils

      SUCCESS = 0
      MISSING_OR_INVALID_KEY = 1
      API_KEY_CANNOT_CALL_THIS_METHOD = 2
      RATE_LIMIT_EXCEEDED = 3
      MISSING_PARAMETER = 4
      INVALID_PARAMETER = 5

      private

      # @param klass [Class]
      # @param request_method [Symbol]
      # @param path [String]
      # @param options [Hash]
      # @return [Array]
      def objects_from_response(klass, request_method, path, object_key, options={})
        response = send(request_method.to_sym, path, options)[:body][:response][object_key] || []
        objects_from_array(klass, response)
      end

      # @param klass [Class]
      # @param array [Array]
      # @return [Array]
      def objects_from_array(klass, array)
        array.map do |element|
          klass.new(element)
        end
      end

      # @param klass [Class]
      # @param request_method [Symbol]
      # @param path [String]
      # @param object_key [Symbol]
      # @param options [Hash]
      # @return [Object]
      def object_from_response(klass, request_method, path, object_key, options={})
        response = send(request_method.to_sym, path, options)[:body][:response]
        response = response[object_key] if object_key
        klass.new(response)
      end

      # @param klass [Class]
      # @param request_method [Symbol]
      # @param path [String]
      # @param options [Hash]
      # @return [Object]
      def boolean_from_response(request_method, path, options={})
        response = send(request_method.to_sym, path, options)
        response[:body][:response][:status][:code] == SUCCESS
      end
    end
  end
end
0
Complexity
0
Duplication
57
Lines
0
Methods
N/A
Complexity / M
0
Churn
31
Lines of Code
N/A
LOC / Method