Sha256: 3c9d0ef5c1d91478b80b4faf5c78051bc0e7b015575ecc81630c591cfb886b2c

Contents?: true

Size: 813 Bytes

Versions: 1

Compression:

Stored size: 813 Bytes

Contents

module UniqueResponse

  Response = Struct.new(:panelist_id, :respondent_id, :ip_address, :user_agent, :survey_token) do
    attr_reader :matches

    def valid?
      values.map { |value| value.is_a?(String) && !value.empty? }.reduce(:&)
    end

    def save
      raise ArgumentError unless valid?

      client = Client.new
      if client.save_response(self)
        @matches = client.data
        true
      else
        false
      end
    end

    def duplicate_ip_address?
      @matches.any? { |match| match["ip_address"] == ip_address }
    end

    def duplicate_user_agent?
      @matches.any? { |match| match["user_agent"] == user_agent }
    end

    def duplicate_ip_and_ua?
      @matches.any? { |match| match["ip_address"] == ip_address && match["user_agent"] == user_agent }
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unique_response_ruby-0.1.0 lib/unique_response_ruby/response.rb