Repository URL to install this package:
| 
      
        
        
        Version: 
        
         
          
          0.9.17  ▾
        
         | 
module ActionSprout::Facebook
  class Response
    attr_reader :http_status, :parsed_response, :headers, :graph
    def initialize(http_status, parsed_response, headers, graph)
      @http_status = http_status
      @parsed_response = parsed_response
      @headers = headers
      # TODO: Do we really need `graph` here?, if we can remove it then
      # HTTPService would no longer need to depend on a graph.
      @graph = graph
    end
    def has_error?
      http_status >= 400
    end
    def app_rate_limited?
      app_usage.present?
    end
    def page_rate_limited?
      page_usage.present?
    end
    def app_call_count
      app_usage.dig('call_count')
    end
    def app_total_time
      app_usage.dig('total_time')
    end
    def app_total_cputime
      app_usage.dig('total_cputime')
    end
    def page_call_count
      page_usage.dig('call_count')
    end
    def page_total_time
      page_usage.dig('total_time')
    end
    def page_total_cputime
      page_usage.dig('total_cputime')
    end
    private
    def app_usage
      @_app_usage ||= parse_json_header 'x-app-usage'
    end
    def page_usage
      @_page_usage ||= parse_json_header 'x-page-usage'
    end
    def parse_json_header(key)
      headers[key] ? JSON.parse(headers[key]) : {}
    end
  end
end