Sha256: 7d2e8f744f1c1d3a90d1a512ab5a6d52caa40e512204f70b8be41e48ce8fa745

Contents?: true

Size: 1001 Bytes

Versions: 5

Compression:

Stored size: 1001 Bytes

Contents

module Masheri
  class RestClient
    class Base
      def initialize(attributes)
        attributes.each do |key, value|
          send("#{key}=", value)
        end
      end

      def self.count
        default_query.items(1).to_json["result"]["total_items"]
      end

      def self.all
        default_query.all
      end

      def self.items(argument)
        default_query.items(argument)
      end

      def self.where(argument)
        default_query.where(argument)
      end

      def self.page(argument)
        default_query.page(argument)
      end

      def self.find_each(&block)
        default_query.find_each(&block)
      end

      def self.standard_query
        Masheri.rpc.query_builder(self).from(object_type).items(100)
      end

      def self.default_query
        standard_query
      end

      def self.first
        new(standard_query.items(1).all.items[0])
      end

      def self.object_type
        self.name.underscore.pluralize
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
masheri-0.5.6 lib/masheri/rest_client/base.rb
masheri-0.5.5 lib/masheri/rest_client/base.rb
masheri-0.5.2 lib/masheri/rest_client/base.rb
masheri-0.5.1 lib/masheri/rest_client/base.rb
masheri-0.5.0 lib/masheri/rest_client/base.rb