Class: Bumeran::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/bumeran.rb

Class Method Summary collapse

Class Method Details

.parse_json_to_hash(json, hash) ⇒ Object



610
611
612
613
# File 'lib/bumeran.rb', line 610

def self.parse_json_to_hash(json, hash)
  json.each{|object| hash[object["id"]] ? hash[object["id"]].merge!(object) : hash[object["id"]] = object}
  return hash
end

.parse_response(response) ⇒ Object



615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
# File 'lib/bumeran.rb', line 615

def self.parse_response(response)
  Bumeran.last_response = response
  Bumeran.last_request = response.request
  case response.code
    when 200..201
      # "All good!"
      return response.body
    when 401
      Bumeran.invalidate_access_token!
      raise "Error 401: Unauthorized. Check login info.\n #{response.body}"
    when 403
      raise "Error 403: Forbidden"
    when 404
      raise "Error 404 not found"
    when 500...600
      raise "ZOMG ERROR #{response.code}: #{response.request.path}, #{response.body}"
    else
      raise "Error #{response.code}, unkown response: #{response.request.path}, #{response.body}"
  end
end

.parse_response_to_json(response) ⇒ Object



635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
# File 'lib/bumeran.rb', line 635

def self.parse_response_to_json(response)
  Bumeran.last_response = response
  Bumeran.last_request = response.request
  case response.code
    when 200..201
      # "All good!"
      return JSON.parse(response.body)
    when 401
      Bumeran.invalidate_access_token!
      raise "Error 401: Unauthorized. Check login info.\n #{response.body}"
    when 403
      raise "Error 403: Forbidden"
    when 404
      raise "Error 404 not found"
    when 500...600
      raise "ZOMG ERROR #{response.code}: #{response.request.path}, #{response.body}"
    else
      raise "Error #{response.code}, unkown response: #{response.request.path}, #{response.body}"
  end
end