lib/rescuetime/query_buildable.rb
def order_by(order, interval: nil)
      # set order and intervals as symbols
      order    = order.to_s
      interval = interval ? interval.to_s : nil

      # guards against invalid order or interval
      unless valid_order? order
        raise Errors::InvalidQueryError, "#{order} is not a valid order"
      end

      unless valid_interval? interval
        raise Errors::InvalidQueryError, "#{interval} is not a valid interval"
      end

      add_to_query perspective: (order == 'time' ? 'interval' : order),
                   resolution_time: interval
    end
def order_by(order, interval: nil)
      # set order and intervals as symbols
      order    = order.to_s
      interval = interval ? interval.to_s : nil

      # guards against invalid order or interval
      unless valid_order? order
        raise Errors::InvalidQueryError, "#{order} is not a valid order"
      end

      unless valid_interval? interval
        raise Errors::InvalidQueryError, "#{interval} is not a valid interval"
      end

      add_to_query perspective: (order == 'time' ? 'interval' : order),
                   resolution_time: interval
    end
Specifies the ordering and the interval of the returned Rescuetime report.
 For example, the results can be ordered by time, activity rank, or member;
 The results can be returned in intervals spanning a month, a week, a day,
 an hour, or 5-minutes.

 Efficiency reports default to :time order; everything else defaults to
 :rank order.

 @example Basic Use
   client = Rescuetime::Client.new
   client.order_by 'time' # interval is not required
   #=> #<Rescuetime::Collection:0x007f93841681a8>

   client.order_by 'rank', interval: 'hour'
   #=> #<Rescuetime::Collection:0x007f93841681a8>

   client.order_by :rank, interval: :hour # Symbols are also valid
   #=> #<Rescuetime::Collection:0x007f93841681a8>

 @example Invalid Values Raise Errors
   client = Rescuetime::Client.new
   client.order_by 'invalid'
   # => Rescuetime::Errors::InvalidQueryError: invalid is not a valid order

   client.order_by 'time', interval: 'invalid'
   # => Rescuetime::Errors::InvalidQueryError: invalid is not a valid interval

 @param  [#to_s]        order      an order for the results (ex. 'time')
 @param  [#intern, nil] interval   a chunking interval for results
                                   (ex. 'month'). defaults to nil

 @return [Rescuetime::Collection]  a Rescuetime Collection specifying order
                                   and interval (if set)

 @raise [Rescuetime::Errors::InvalidQueryError] if either order or interval are
                                        invalid

 @see https://www.rescuetime.com/apidoc#paramlist  Rescuetime API docs
                                                   (see: perspective,
                                                   resolution_time)
 @see Rescuetime::QueryBuildable::VALID            List of valid values