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



654
655
656
657
# File 'lib/bumeran.rb', line 654

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



659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
# File 'lib/bumeran.rb', line 659

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



679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
# File 'lib/bumeran.rb', line 679

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