Sha256: 806efed69e48a528bbaddb21a4c0a7abc8476903023a79f61baa5e63f4bf64e6

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

module Falconz
  module APIs
    # A module consisting of the method associted with the 
    # Feed section of the API.
    #
    # @author Kent 'picat' Gruber
    module Feed
      # access a feed of last 250 reports over 24h
      #
      # == Example
      #   client = Falconz.client.new
      #
      #   client.latest_feed do |data|
      #     # do something with the data
      #     puts data.to_json
      #   end
      #
      # https://www.hybrid-analysis.com/docs/api/v2#/Feed/get_feed_latest
      def latest_feed
        # return response unless block was given ( like the in-line example )
        return get_request('/feed/latest') unless block_given?
        # capture response
        response = get_request('/feed/latest')
        # raise error (built out of the response) unless everything is ok
        raise "response not ok: #{response}" unless Falconz.response_is_ok?(response)
        # raise error unless there is any data
        raise "no data to iterate through in response #{response}" unless response['data'] or !response['data'].zero?
        response['data'].each do |data|
          yield data
        end
      end

      # A little wrapper method to #latest_feed that returns the count
      # of the ammount of data found in the feed.
      #
      # @return [void]
      # @see #latest_feed
      def latest_feed_count
        # capture response
        response = latest_feed   
        # raise error (built out of the response) unless everything is ok
        raise response unless Falconz.response_is_ok?(response)
        # raise error unless there is any count in the response
        raise "no count found in response #{response}" unless response['count']
        # return the count
        response["count"] 
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
falconz-1.0.1 lib/falconz/apis/feed.rb