Sha256: bf00d479f02881cb1c1cc06e85f091225ef4e13af8eb3903d3945b1f259b06f1

Contents?: true

Size: 552 Bytes

Versions: 2

Compression:

Stored size: 552 Bytes

Contents

require 'hashie'

module Slack
  class Base < Hashie::Mash
    class << self
      def parse(response, key=nil)
        parsed = JSON.parse(response.body)
        parsed = parsed[key] if key && parsed[key]
        if parsed.is_a? Array
          models = []
          parsed.each { |attributes| models << new(attributes) }
          models
        else
          new parsed
        end
      end

      def parse_all(responses, key=nil)
        responses.map do |response|
          parse(response, key)
        end.flatten
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
laziness-0.2.6 lib/laziness/base.rb
laziness-0.2.5 lib/laziness/base.rb