Sha256: 2b34d31c85959386e3e694e8aad80e26c77bc9cdd17e0f753245133f2536e956

Contents?: true

Size: 1.24 KB

Versions: 35

Compression:

Stored size: 1.24 KB

Contents

module Maestrano
  module API
    class ListObject < Maestrano::API::Object

      def [](k)
        case k
        when String, Symbol
          super
        else
          raise ArgumentError.new("You tried to access the #{k.inspect} index, but ListObject types only support String keys. (HINT: List calls return an object with a 'data' (which is the data array). You likely want to call #data[#{k.inspect}])")
        end
      end

      def each(&blk)
        self.data.each(&blk)
      end

      def retrieve(id, api_token=nil)
        api_token ||= @api_token
        response, api_token = Maestrano::API::Operation::Base.request(:get,"#{url}/#{CGI.escape(id)}", api_token)
        Util.convert_to_maestrano_object(response, api_token)
      end

      def create(params={}, api_token=nil)
        api_token ||= @api_token
        response, api_token = Maestrano::API::Operation::Base.request(:post, url, api_token, params)
        Util.convert_to_maestrano_object(response, api_token)
      end

      def all(params={}, api_token=nil)
        api_token ||= @api_token
        response, api_token = Maestrano::API::Operation::Base.request(:get, url, api_token, params)
        Util.convert_to_maestrano_object(response, api_token)
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 2 rubygems

Version Path
maestrano-1.0.6 lib/maestrano/api/list_object.rb
maestrano-1.0.5 lib/maestrano/api/list_object.rb
maestrano-1.0.4 lib/maestrano/api/list_object.rb
maestrano-1.0.3 lib/maestrano/api/list_object.rb
maestrano-1.0.2 lib/maestrano/api/list_object.rb
maestrano-1.0.1 lib/maestrano/api/list_object.rb
maestrano-1.0.0 lib/maestrano/api/list_object.rb
maestrano-1.0.0.pre.RC9 lib/maestrano/api/list_object.rb
maestrano-1.0.0.pre.RC8 lib/maestrano/api/list_object.rb
maestrano-1.0.0.pre.RC7 lib/maestrano/api/list_object.rb
maestrano-1.0.0.pre.RC6 lib/maestrano/api/list_object.rb
maestrano-1.0.0.pre.RC5 lib/maestrano/api/list_object.rb
maestrano-1.0.0.pre.RC4 lib/maestrano/api/list_object.rb
maestrano-1.0.0.pre.RC3 lib/maestrano/api/list_object.rb
maestrano-1.0.0.pre.RC2 lib/maestrano/api/list_object.rb
maestrano-1.0.0.pre.RC1 lib/maestrano/api/list_object.rb
maestrano-0.12.5 lib/maestrano/api/list_object.rb
maestrano-0.12.4 lib/maestrano/api/list_object.rb
maestrano-0.12.3 lib/maestrano/api/list_object.rb
maestrano-0.12.2 lib/maestrano/api/list_object.rb