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-0.12.1 lib/maestrano/api/list_object.rb
maestrano-0.12.0 lib/maestrano/api/list_object.rb
maestrano-0.11.0 lib/maestrano/api/list_object.rb
maestrano-0.10.0 lib/maestrano/api/list_object.rb
maestrano-0.9.2 lib/maestrano/api/list_object.rb
maestrano-0.9.1 lib/maestrano/api/list_object.rb
maestrano-0.9.0 lib/maestrano/api/list_object.rb
maestrano-ruby-test-0.8.3 lib/maestrano/api/list_object.rb
maestrano-0.8.2 lib/maestrano/api/list_object.rb
maestrano-0.8.1 lib/maestrano/api/list_object.rb
maestrano-0.8.0 lib/maestrano/api/list_object.rb
maestrano-0.7.0 lib/maestrano/api/list_object.rb
maestrano-0.6.0 lib/maestrano/api/list_object.rb
maestrano-0.5.0 lib/maestrano/api/list_object.rb
maestrano-0.4.0 lib/maestrano/api/list_object.rb