Class: Slack::Base

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/laziness/base.rb

Class Method Summary collapse

Class Method Details

.parse(response, key = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/laziness/base.rb', line 6

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

.parse_all(responses, key = nil) ⇒ Object



18
19
20
21
22
# File 'lib/laziness/base.rb', line 18

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